Skip to content

Instantly share code, notes, and snippets.

@jonesfish
Last active March 21, 2019 02:57
Show Gist options
  • Select an option

  • Save jonesfish/d5968fd03c976e82d88c to your computer and use it in GitHub Desktop.

Select an option

Save jonesfish/d5968fd03c976e82d88c to your computer and use it in GitHub Desktop.
float x, y;
float w, h;
float speed = 5;
int state = 0;
void setup() {
size(500, 500);
w = 50;
h = 30;
x = w/2;
y = h/2;
}
void draw() {
// If the state is 0, move to the right.
switch (state){
case 0:
x += speed;
// If, while the state is 0, it reaches the right side of the window, change the state to 1
if (x > width-w/2) {
x = width-w/2;
state = 1;
}
break;
case 1:
y += speed;
if (y > height-h/2) {
y = height-h/2;
state = 2;
}
break;
case 2:
x -= speed;
if (x < w/2) {
x = w/2;
state = 3;
}
break;
case 3:
y -= speed;
if (y < h/2) {
y = h/2;
state=0;
}
break;
}
background(0);
// UFO
fill(151,37,210);
ellipse(x, y, 50, 15);
fill(186,0,255);
stroke(255);
arc(x, y, 25, 25, PI, TWO_PI);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment