Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------
- // Processing - processing.org
- // Rotating rectangles(blue stroke) - by iomikron
- //-----------------------------------------------
- int numOfRectangles = 250;
- Rectangle [] rectArray = new Rectangle[numOfRectangles];
- void setup()
- {
- size(300, 300);
- for(int i = 0; i <= numOfRectangles-1; i++)
- {
- rectArray[i] =
- new Rectangle(
- random(20, width - 20), //coordinate X
- random(20,height - 20), //coordinate Y
- 133, //color
- 20., //width
- 20., //height
- PI/(random(i,i*i)), //angle (initial)
- random(2.75,5.8), //angular Velocity (initial)
- random(0.1,0.25)//rotate speed (initial)
- );
- }
- }
- void draw()
- {
- background(0);
- for(int i = 0; i <= numOfRectangles-1; i++)
- {
- rectArray[i].move();
- }
- }
- //--------------------------
- //Rectangle CLASS DEFINITION
- //--------------------------
- class Rectangle
- {
- float coordX;//horizontal coordinate for the center
- float coordY;//vertical coordinate for the center
- float rectColor;//color filling
- // float rectAlpha; Uncomment for opacity
- float rectWidth;//parameter for the width
- float widthConst;
- float rectHeight;//parameter for the height
- float angle;
- float angularVelocity;
- float rotationSpeed;
- //Constructor
- Rectangle(float X, float Y,
- float C,
- float W, float H,
- float a, float angV, float rotS)
- {
- coordX = X;
- coordY = Y;
- rectColor = C;
- rectWidth = W;
- widthConst = W;
- rectHeight = H;
- angle = a;
- angularVelocity = angV;
- rotationSpeed = rotS;
- }
- //FUNCTIONS FOR THE CLASS
- void display()
- {
- rectMode(CENTER);
- //define color and opacity
- stroke(color(0,133,255));
- fill(changeColor());
- //create the rectangle
- rect(0, 0, widthConst*changeWidth(), rectHeight);
- }
- void move()
- {
- pushMatrix();
- translate(coordX, coordY);
- rotate(radians(angle));
- display();
- popMatrix();
- changeAngle();
- changeWidth();
- }
- float changeAngle()
- {
- angle = angle + angularVelocity;
- return(angle);
- }
- float changeWidth()
- {
- float w;
- rectWidth = rectWidth + rotationSpeed;
- w = cos(rectWidth);
- return(w);
- }
- float changeColor()
- {
- float c;
- c = rectColor*cos(rectWidth)*cos(rectWidth) + 120;
- return(c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement