Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class square
- {
- float x, y, a;
- square(float xp, float yp, float ap)
- {
- x = xp; y = yp; a = ap;
- }
- }
- square[] sqrs = new square[16];
- int a = 0, del = 0;
- int colorch = 0, sqcol = 0;
- void setup()
- {
- size(800, 600);
- frame.setResizable(true);
- }
- void draw() {
- float padding = 40;
- float minSide = height;
- float offsetTop, offsetLeft, rA;
- //calc center and sides
- background(255);
- if (minSide > width)
- {
- minSide = width;
- rA = minSide-padding;
- offsetTop = height - height / 2 - rA/2;
- offsetLeft = padding/2;
- }
- else
- {
- rA = minSide-padding;
- offsetLeft = width - width / 2 - rA/2;
- offsetTop = padding/2;
- }
- //calc squares pos's and sizes
- sqrs[0] = new square(offsetLeft, offsetTop, rA/4);
- sqrs[1] = new square(offsetLeft+rA/4, offsetTop, rA/4);
- sqrs[2] = new square(offsetLeft, offsetTop+rA/4, rA/4);
- sqrs[3] = new square(offsetLeft+rA/4, offsetTop+rA/4, rA/4);
- sqrs[4] = new square(offsetLeft+rA/2, offsetTop, rA/4);
- sqrs[5] = new square(offsetLeft+rA/4+rA/2, offsetTop, rA/4);
- sqrs[6] = new square(offsetLeft+rA/2, offsetTop+rA/4, rA/4);
- sqrs[7] = new square(offsetLeft+rA/4+rA/2, offsetTop+rA/4, rA/4);
- sqrs[8] = new square(offsetLeft, offsetTop+rA/2, rA/4);
- sqrs[9] = new square(offsetLeft+rA/4, offsetTop+rA/2, rA/4);
- sqrs[10] = new square(offsetLeft, offsetTop+rA/4+rA/2, rA/4);
- sqrs[11] = new square(offsetLeft+rA/4, offsetTop+rA/4+rA/2, rA/4);
- sqrs[12] = new square(offsetLeft+rA/2, offsetTop+rA/2, rA/4);
- sqrs[13] = new square(offsetLeft+rA/4+rA/2, offsetTop+rA/2, rA/4);
- sqrs[14] = new square(offsetLeft+rA/2, offsetTop+rA/4+rA/2, rA/4);
- sqrs[15] = new square(offsetLeft+rA/4+rA/2, offsetTop+rA/4+rA/2, rA/4);
- //draw squares
- for(int i = 0; i < 16; i++) {
- rect(sqrs[i].x, sqrs[i].y, sqrs[i].a, sqrs[i].a);;
- }
- //rotate
- for(int i = 0, k = 1; i < 16; i++)
- {
- rotate(sqrs[i], a*k);
- if ((i) % 2==0) k *= -1;
- }
- //increase angel
- if (a < 360) a++;
- else a = 0;
- delay(del);
- }
- void rotate(square sq, int ang)
- {
- float rad, x, a1;
- boolean neg = false;
- //stab ang
- if (ang < 0) {neg = true; ang = abs(ang);}
- if (ang > 90) ang -= int(ang/90)*90;
- if (neg) ang = 90-ang;
- rad = radians(ang);
- //calculate
- x = int(sq.a/(sin(rad) + cos(rad)));
- a1 = int(x*sin(rad));
- //draw
- line(sq.x, sq.y+a1, sq.x+sq.a-a1, sq.y);
- line(sq.x+sq.a-a1, sq.y, sq.x+sq.a, sq.y+sq.a-a1);
- line(sq.x+sq.a, sq.y+sq.a-a1, sq.x+a1, sq.y+sq.a);
- line(sq.x+a1, sq.y+sq.a, sq.x, sq.y+a1);
- }
Advertisement
Add Comment
Please, Sign In to add comment