Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Square[] squares;
- int elem, unit;
- color f;
- void setup() {
- size(500, 500);
- background(255);
- int counter=0;
- int i=0;
- int div = 4;
- unit = width/div;
- elem = int(sq(div));
- squares = new Square[elem];
- for (int x = unit/2; x<width; x +=unit) {
- counter = 0;
- for (int y = unit/2; y<height; y +=unit) {
- squares[i] = new Square(float(x), float(y), counter);
- i++;
- counter++;
- }
- }
- }
- void draw() {
- background(255);
- for (int i=0; i<elem; i++) {
- squares[i].display();
- }
- if (frameCount % 2 == 0 & frameCount<121) saveFrame("image-####.gif");
- }
- class Square {
- float x, y, theta,f;
- float x1, x2, x3, x4, y1, y2, y3, y4;
- float nx1, nx2, nx3, nx4, ny1, ny2, ny3, ny4;
- float sz = unit*.3;
- PVector pv;
- int c;
- Square(float _x, float _y, int _counter) {
- x = _x;
- y = _y;
- c = _counter;
- x1 = x-sz;
- y1 = y-sz;
- x2 = x;
- y2 = y-sz;
- x3 = x-sz;
- y3 = y;
- x4 = x;
- y4 = y;
- pv = new PVector(unit/2-sz, unit/2-sz);
- }
- void display() {
- nx1 = map(sin(theta), -1, 1, x1-pv.x, x1);
- ny1 = map(sin(theta), -1, 1, y1-pv.y, y1);
- nx2 = map(sin(theta), -1, 1, x2+pv.x,x2);
- ny2 = map(sin(theta), -1, 1, y2-pv.y,y2);
- nx3 = map(sin(theta), -1, 1, x3-pv.x, x3);
- ny3 = map(sin(theta), -1, 1, y3+pv.y, y3);
- nx4 = map(sin(theta), -1, 1, x4+pv.x, x4);
- ny4 = map(sin(theta), -1, 1, y4+pv.y, y4);
- f = map(sin(theta),-1,1,100,180);
- fill(f);
- stroke(f);
- strokeWeight(5);
- rect(nx1, ny1, sz, sz);
- rect(nx2, ny2, sz, sz);
- rect(nx3, ny3, sz, sz);
- rect(nx4, ny4, sz, sz);
- theta += 0.0523;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement