processing.org -processing question -10pnts for help?

Publié le

Write a dynamic processing application for a screen size of 400 X 400 that moves a square at a 45degree angle continually from (200,0) to (0,200) to (200,400) to (400,200) and then backto (200,0). The square should change to a random color every time it hits an edge. ---- add-on : Any key press should change the direction of rotation of the square, anti clockwise to clockwise and vice-versa . //my code for the top part is int x = 200; int y = 0; int speed = 5; int state = 0; float r = random (10); float g = random (10); float b = random (70); void setup() { size(400,400); } void draw() { frameRate (30); background(255); stroke(0); rect (x,y,30,30); //Move to left center if(state == 0) { x -= speed ; y = speed; if(x <= 0 || y >= 200) { x = 0; y = 200; fill(r,g,b); state ; } } //Move to bottom center else if(state == 1) { x = speed ; y = speed; if(x >= 200 || y >= 370) { x = 200; y = 370; fill(r,g,b); state ; } } //Move to right side center else if(state == 2) { x = speed ; y -= speed; if(x >=380 || y <= 200) { x = 380; y = 200; fill(r,g,b); state ; } } //move back to top center else if(state == 3) { x -= speed ; y -= speed; if(x <= 200 || y <= 0) { x = 200; y = 0; fill(r,g,b); state = 0; } } } // anyone have any ideas on the add on part ?? - the bit where if key is pressed it changes direction??
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article