Skip to content

Instantly share code, notes, and snippets.

@miura miura/code13_DotXY.ijm Secret
Last active Dec 17, 2015

What would you like to do?
//Code 13
macro "Generate Dot Animation XY move" {
// **** initial values ****
sizenum=10; //dot size in pixel
int=255; //dot intensity in 8bit grayscale
frames=200; //frames in stack
w=200; //width of frame
h=400; //height of frame
x_position = sizenum; //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 ****
xspeed = speed;
yspeed = speed;
newImage(stackname, "8-bit Black", w, h, frames);
//**** drawing oval in the stack ****
for(i=0; i<frames; i++) {
x_position += xspeed;
y_position += yspeed;
if ((x_position > (w-sizenum)) || (x_position < 0) ) {
x_position += xspeed*2; //avoids penetrating boundary
if ((y_position > (h-sizenum)) || (y_position < 0) ) {
y_position += yspeed*2; //avoids penetrating boundary
makeOval(x_position, y_position, sizenum, sizenum);
run("Fill", "slice");
run("Select None");

This comment has been minimized.

Copy link
Owner Author

miura commented May 16, 2013

upgrade from the simple x only movement. Changes are as follows:

  • line 8-9, changed the image size, for a larger field.
  • line 22-23, two speeds, one for x and the other for y direciton prepared. These values should be independent for independent bouncings.
  • line 29-30, increment in two directions individually. Initially they behave in a similar way, but after bouncing in one of the wall, they become independent.
  • line 32, switching of direction happens only in x direction.
  • line 35-38, switching in y direction added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.