hozer

Untitled

Nov 23rd, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. class square
  2. {
  3. float x, y, a;
  4.  
  5. square(float xp, float yp, float ap)
  6. {
  7. x = xp; y = yp; a = ap;
  8. }
  9. }
  10.  
  11. square[] sqrs = new square[4];
  12. int a = 0, del = 10;
  13. void setup()
  14. {
  15. size(800, 600);
  16. frame.setResizable(true);
  17. }
  18.  
  19. void draw() {
  20. float padding = 40;
  21. float minSide = height;
  22. float offsetTop, offsetLeft, rA;
  23. background(255);
  24. //calc center and sides
  25. if (minSide > width)
  26. {
  27. minSide = width;
  28. rA = minSide-padding;
  29. offsetTop = height - height / 2 - rA/2;
  30. offsetLeft = padding/2;
  31.  
  32. }
  33. else
  34. {
  35. rA = minSide-padding;
  36. offsetLeft = width - width / 2 - rA/2;
  37. offsetTop = padding/2;
  38. }
  39. //calc squares pos's and sizes
  40. sqrs[0] = new square(offsetLeft, offsetTop, rA/2);
  41. sqrs[1] = new square(offsetLeft+rA/2, offsetTop, rA/2);
  42. sqrs[2] = new square(offsetLeft, offsetTop+rA/2, rA/2);
  43. sqrs[3] = new square(offsetLeft+rA/2, offsetTop+rA/2, rA/2);
  44.  
  45. //draw squares
  46. /*for(int i = 0; i < 4; i++)
  47. {
  48. rect(sqrs[i].x, sqrs[i].y, sqrs[i].a, sqrs[i].a);
  49. }*/
  50.  
  51. //rotate
  52. rotate(sqrs[0], a);
  53. rotate(sqrs[1], -a);
  54. rotate(sqrs[2], -a);
  55. rotate(sqrs[3], a);
  56.  
  57. //increase angel
  58. if (a < 90) a++;
  59. else a = 0;
  60.  
  61. delay(del);
  62. }
  63.  
  64. void rotate(square sq, int ang)
  65. {
  66. float rad, x, a1;
  67. boolean neg = false;
  68. //stab ang
  69. if (ang < 0) {neg = true; ang = abs(ang);}
  70. if (ang > 90) ang -= int(ang/90)*90;
  71. if (neg) ang = 90-ang;
  72. rad = radians(ang);
  73. //calculate
  74. x = int(sq.a/(sin(rad) + cos(rad)));
  75. a1 = int(x*sin(rad));
  76. //draw
  77. line(sq.x, sq.y+a1, sq.x+sq.a-a1, sq.y);
  78. line(sq.x+sq.a-a1, sq.y, sq.x+sq.a, sq.y+sq.a-a1);
  79. line(sq.x+sq.a, sq.y+sq.a-a1, sq.x+a1, sq.y+sq.a);
  80. line(sq.x+a1, sq.y+sq.a, sq.x, sq.y+a1);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment