iomikron

Processing - rotating square

Sep 25th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. float angle;
  2. float widthVar;
  3. float rotationSpeed;
  4.  
  5. void setup()
  6. {
  7. //set the size of the panel
  8. size(600,200);
  9.  
  10. //initialization of parameters
  11. angle = 3;
  12. widthVar = 0;
  13. rotationSpeed = 0.1;
  14.  
  15. fill(100);
  16. noStroke();
  17. rectMode(CENTER);
  18. rect(width/2,height/2, 40,40);
  19. }
  20.  
  21. void draw()
  22. {
  23. background(0);
  24.  
  25. pushMatrix();
  26. //move the origin to the pivot point
  27. translate(width/2, height/2);
  28. //pivot the grid
  29. rotate(radians(angle));
  30. //
  31. rectMode(CENTER);
  32. fill(133*cos(widthVar)*cos(widthVar) + 130);
  33. rect(0, 0, 40*cos(widthVar),40);
  34. popMatrix();
  35. angle = angle + 2.5;
  36. widthVar = widthVar + rotationSpeed;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment