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:00] ffpaladin |
hong_kong_students_click_here [2015/07/23 14:50] (current) ffpaladin |
||
---|---|---|---|
Line 230: | Line 230: | ||
http://processing.org/reference/ | http://processing.org/reference/ | ||
+ | |||
+ | Traffic Light | ||
+ | |||
+ | <code> | ||
+ | |||
+ | int counter; | ||
+ | |||
+ | void setup() { //setup function called initially, only once | ||
+ | size(500, 500); | ||
+ | } | ||
+ | |||
+ | void draw() { //draw function loops | ||
+ | |||
+ | fill(255,255,255); | ||
+ | rect(0,0,40,80); | ||
+ | | ||
+ | fill(255,0,0); | ||
+ | ellipse(20,20,20,20); | ||
+ | |||
+ | fill(0,255,0); | ||
+ | ellipse(20,40,20,20); | ||
+ | |||
+ | fill(0,0,255); | ||
+ | ellipse(20,60,20,20); | ||
+ | |||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | Stick Man | ||
+ | |||
+ | <code> | ||
+ | |||
+ | int counter; | ||
+ | |||
+ | void setup() { //setup function called initially, only once | ||
+ | size(300,300); | ||
+ | } | ||
+ | |||
+ | void draw() { //draw function loops | ||
+ | ellipse(20,20,20,20); | ||
+ | line(20,30,20,80); | ||
+ | line(10,40,30,40); | ||
+ | line(20,80,10,90); | ||
+ | line(20,80,30,90); | ||
+ | } | ||
+ | |||
+ | </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> |