Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // iomikron.tumblr.com
- //this is for gif creation//import gifAnimation.*;
- //this is for gif creation//GifMaker gifExport = new GifMaker(this, "rotatedSquare05.gif");
- int numOfRectangles = 400;
- Rectangle [] rectArray = new Rectangle[numOfRectangles];
- void setup()
- {
- size(600, 150);
- //this is for gif creation// gifExport.setRepeat(0); //make it an 'endless' animation
- for(int i = 0; i <= numOfRectangles-1; i++)
- {
- rectArray[i] =
- new Rectangle(
- random(10, width - 10), //coordinate X
- random(10,height - 10), //coordinate Y
- 133, //color
- 20., //width
- 20., //height
- (PI/(i+1)), //angle (initial)
- random(3.1,4.), //angular Velocity (initial)
- random(0.05,0.25),//rotate speed (initial)
- 0.5,//initial value for time
- 0.000225//constant timeStep
- );
- }
- }
- void draw()
- {
- background(0);
- for(int i = 0; i <= numOfRectangles-1; i++)
- {
- rectArray[i].move();
- }
- //this is for gif creation// if(keyPressed == true)
- //this is for gif creation// {
- //this is for gif creation// gifExport.finish();
- //this is for gif creation// }
- //this is for gif creation// else
- //this is for gif creation// {
- //this is for gif creation// gifExport.addFrame();
- //this is for gif creation// }
- }
- ///////////////////////////////////////////////////////
- // 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;
- float time;
- float timeStep;
- //-----------------------------------------------------
- // Constructor
- //-----------------------------------------------------
- Rectangle(float X, float Y,
- float C,
- float W, float H,
- float a, float angV, float rotS,
- float T, float TS)
- {
- coordX = X;
- coordY = Y;
- rectColor = C;
- rectWidth = W;
- widthConst = W;
- rectHeight = H;
- angle = a;
- angularVelocity = angV;
- rotationSpeed = rotS;
- time = T;
- timeStep = TS;
- }
- ///////////////////////////////////////////////////////
- // FUNCTIONS FOR THE CLASS
- ///////////////////////////////////////////////////////
- // color and transparency \\
- void display()
- {
- rectMode(CENTER);
- //define color and opacity
- noStroke();
- fill(changeColor(),
- 200*(cos(4*height*time))*(cos(4*height*time)));
- //create the rectangle
- rect(0, 0, widthConst*changeWidth(), rectHeight);
- }
- // movement \\
- void move()
- {
- pushMatrix();
- translate(coordX, coordY);
- rotate(radians(angle));
- scale((cos(4*height*time))*(cos(4*height*time)) + 0.5);
- display();
- popMatrix();
- changeAngle();
- changeWidth();
- time = time + timeStep;
- }
- 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