This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
hong_kong_students_click_here [2015/07/23 10:27] ffpaladin |
hong_kong_students_click_here [2015/07/23 14:50] (current) ffpaladin |
||
---|---|---|---|
Line 277: | Line 277: | ||
} | } | ||
+ | </code> | ||
+ | |||
+ | Moving Ball | ||
+ | |||
+ | <code> | ||
+ | |||
+ | int counter; | ||
+ | int x = 0; | ||
+ | int y = 0; | ||
+ | |||
+ | int dx = 5; | ||
+ | int dy = 2; | ||
+ | |||
+ | void setup() { //setup function called initially, only once | ||
+ | size(500, 500); | ||
+ | } | ||
+ | |||
+ | void draw() { //draw function loops | ||
+ | | ||
+ | background(0); | ||
+ | | ||
+ | ellipse(x,y,20,20); | ||
+ | |||
+ | if (x > 500) { | ||
+ | dx = dx * -1; | ||
+ | } | ||
+ | |||
+ | if (x < 0) { | ||
+ | dx = dx * -1; | ||
+ | } | ||
+ | |||
+ | if (y > 500) { | ||
+ | dy = dy * -1; | ||
+ | } | ||
+ | |||
+ | if (y < 0) { | ||
+ | dy = dy * -1; | ||
+ | } | ||
+ | | ||
+ | x = x + dx; | ||
+ | y = y + dy | ||
+ | | ||
+ | if (mousePressed) { | ||
+ | x = mouseX; | ||
+ | y = mouseY; | ||
+ | } | ||
+ | } | ||
</code> | </code> |