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