Rotating rectangles animation
in
Programming Questions
•
2 years ago
Hi,
I'm starting using Processing these days.
I'd like to create animation with some rectangles on the screen continuosly rotating in some sort of random way.
I created a Rectangle class with a display function,
but I'm actually drawing the rectangles again and again and not actually moving.
Then, in the draw() function:
"a" is an array with all the rectangles. I'm not sure if this is the right way to do it. I mean, I'd like all the rectangles rotating at the same time in different ways.
Any suggestion?
I'm starting using Processing these days.
I'd like to create animation with some rectangles on the screen continuosly rotating in some sort of random way.
I created a Rectangle class with a display function,
- class Rectangle
- {
- float x, y;
- float w, h;
- Rectangle(float tempX, float tempY, float tempW, float tempH)
- {
- x = tempX;
- y = tempY;
- w = tempW;
- h = tempH;
- }
- void display()
- {
- pushMatrix();
- translate(x, y);
- rotate(radians(random(0, 360)));
- rect(x, y, w, h);
- popMatrix();
- }
but I'm actually drawing the rectangles again and again and not actually moving.
Then, in the draw() function:
- void draw()
- {
- for (int i = 0; i < rectNum; i++)
- {
- a[i].display();
- }
- }
"a" is an array with all the rectangles. I'm not sure if this is the right way to do it. I mean, I'd like all the rectangles rotating at the same time in different ways.
Any suggestion?
1
