-
-
Save miura/3e1b8bcd73ea864b46ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Code 13_assignment | |
macro "Generate Dot Animation Random Walk (4)" { | |
// **** initial values **** | |
sizenum=10; //dot size in pixel | |
int=255; //dot intensity in 8bit grayscale | |
frames=200; //frames in stack | |
w=100; //width of frame | |
h=100; //height of frame | |
x_position = (w/2) - (sizenum/2); //starting x position: | |
y_position= (h/2)-(sizenum/2); //y positon of the oval top-left corner: constant | |
//**** set colors ***** | |
setForegroundColor(int, int, int); | |
setBackgroundColor(0, 0, 0); | |
//**** ask speed ***** | |
speed=getNumber("Speed [pix/frame]?",10) | |
//**** prepare stack **** | |
stackname="dotanimation"+speed; | |
xspeed = speed; | |
yspeed = speed; | |
newImage(stackname, "8-bit Black", w, h, frames); | |
//**** drawing oval in the stack **** | |
for(i=0; i<frames; i++) { | |
setSlice(i+1); | |
direction = randsteps(); // user-defined function. See below. | |
if (direction == "right") | |
x_position += xspeed; | |
else if (direction == "left") | |
x_position -= xspeed; | |
else if (direction == "down") | |
y_position += yspeed; | |
else // direction == up | |
y_position -= yspeed; | |
if (x_position > (w-sizenum)) | |
x_position = w-sizenum; //if dot goes out to right, then step back. | |
else if (x_position < 0) | |
x_position = sizenum; // if dot goes out to left side | |
if (y_position > (h-sizenum) ) | |
y_position = h - sizenum; //if dot goes out downwards | |
else if(y_position < 0) | |
y_position = sizenum; //if dot goes out upwards | |
makeOval(x_position, y_position, sizenum, sizenum); | |
run("Fill", "slice"); | |
} | |
run("Select None"); | |
} | |
function randsteps(){ | |
direction = ""; | |
r = random(); | |
if (r < 0.25) | |
direction = "right"; | |
else if (r < 0.5) | |
direction = "up"; | |
else if (r < 0.75) | |
direction = "left"; | |
else | |
direction= "down"; | |
return direction; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
XY movement macro is now modified to plot random walk dot. Changes are the following: