How to create a blinking image marker?

I have a 2-D image graph, and want to put a blinking marker on the display. This marker should be relatively small, and blink as rapidly as possible (up to 4 Hz) for ease of perception. My approach has been to use a drawing object, and get it to update as rapidly as possible. I have tried to adapt one method described in the IP manual, but have not succeeded in my goals. I am hoping someone can show me where I am going wrong, or suggest an alternate approach. The code shown clears the old marker, shows a new marker, but does not blink further, even though the loop has five iterations. The only marker attribute that needs to change is from fillfgc=(....) with specified colors, to fillpat=0 (transparent). An alternative would be to remove and redraw the marker, but I had no better luck with that.

function drawdot(x,y, contrast)
	variable x, y, contrast
	variable ticks0,  j
	variable color = 65535/2 + contrast*65535/2    //	sets the blinker contrast in the autoscaled image
	SetDrawLayer /W=Graph2/K  UserFront           //	clear old draw objects
	SetDrawLayer /W=Graph2 UserFront
	
	for(j=0;j<5;j+=1)	//	blink loop
	     SetDrawEnv gstart, gname = greydot
	     SetDrawEnv xcoord= bottom,ycoord= left,fillfgc= (color,color,color),linethick= 0.00
	     DrawOval /W=Graph2  x, y, x-0.02, y-0.02	//  a variable greyscale fill pattern
	     SetDrawEnv gstop
	     DoUpdate/W=Graph2
	
	     ticks0 = ticks
	     do
	     while( (ticks-ticks0)<60 )	//	delay one second, for example
		
	     DrawAction getgroup=greydot, delete, begininsert
	     SetDrawEnv gstart, gname = greydot
	     SetDrawEnv xcoord= bottom,ycoord= left,fillpat=0 ,linethick= 0.00 // no fill
	     DrawOval /W=Graph2  x, y, x-0.02, y-0.02	  // effectively invisible
	     SetDrawEnv gstop
	     DrawAction endinsert
	     DoUpdate/W=Graph2
	
	     ticks0 = ticks
	     do
	     while( (ticks-ticks0)<60 )
	endfor
end
I see some overall problems with your function but let's start with the main problem. You were simply putting too much good intention into the redrawing part. :)
Just delete the second drawing part in your for-loop and it works. Drawing and deleting is enough to let the dot blink.

Next, some suggestions:
1) You'd rather use the nifty function 'sleep' for the delay. No need for empty do-while-loops.
2) In the current state the function is extremely hard-coded to a specific case (graph named 'graph2' with bottom and left axes, also the dot size is very dependent on the axis range), but I guess you don't mind. It wouldn't be too difficult to fetch all this data for a more general approach, though (e.g. bringing the desired window to the front at start to omit all these /W flags)
3) You want the dot to blink only five times? How about forever or until something happens? You may want to read more about background functions then.

Here's my reworked function, by the way:

function drawdot(x,y, contrast)
	variable x, y, contrast
	variable j, color = 65535/2 + contrast*65535/2	// sets the blinker contrast in the autoscaled image
	SetDrawLayer/K  UserFront			// clear old draw objects
	SetDrawLayer UserFront
 
	for(j=0;j<5;j+=1)				// blink loop
		SetDrawEnv gstart, gname = greydot
		SetDrawEnv xcoord= bottom,ycoord= left,fillfgc= (color,color,color),linethick= 0.00
		DrawOval   x, y, x-0.02, y-0.02		// a variable greyscale fill pattern
		SetDrawEnv gstop

		DoUpdate
		Sleep/S 1
		DrawAction getgroup=greydot, delete, begininsert
		DoUpdate
		Sleep/S 1
	endfor
end
Chozo,
Thanks for your timely and helpful response and suggestions. Your code works well. I have elected to stay with the 'ticks' timing option because the 'sleep' documentation suggests it is best suited for longer intervals rather than fractions of a second (maybe I am wrong there). I have gotten the marker display to blink at about 10Hz.
s.r.chinn wrote: I ... want to put a blinking marker on the display. ...


Had you been from across the pond, we might have responded to this differently. :-)

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville