Rotating object around a point
in
Programming Questions
•
1 year ago
Hi,
I want to design a moving object in 2d. Basically, I chose a triangle and i can only move it up and down. All I need is, when I press left button, it must rotate counter-clockwise and when i press right, it must rotate clockwise and then continue in that direction when up/down is pressed.
Here is my code:
- int x0=200,y0=200,x1=205,y1=230,x2=195,y2=230;
- void setup()
- {
- size(400,400);
- }
- void draw()
- {
- background(0,255,0);
- stroke(0);
- smooth();
- triangle(x0,y0,x1,y1,x2,y2);
- }
- void keyPressed()
- {
- if(key==CODED)
- {
- if(keyCode==UP)
- {
- y0--;y1--;y2--;
- }
- if(keyCode==DOWN)
- {
- y0++;y1++;y2++;
- }
- }
- }
1