Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. /*
  2. Marzhan Kengessova
  3. Physical Computing
  4. Tutorial #3
  5. Part B
  6. February 9, 2016
  7.  
  8. Animation is made of multiple lines forms circled animation with different
  9. bright colors. If you press mouse, background will change, if you press
  10. mouse again, background will change. I took animation code from previous my project
  11. from another course, so, right know I don't remember from where I took my baseic code,
  12. but it was modified.
  13. */
  14.  
  15. float num, pathR, pathG, pathB;
  16. int backgroundColor = 0;
  17. boolean doOnce = true;
  18.  
  19. void setup() {
  20. size(640, 640); //size of the canvas
  21. }
  22.  
  23. void draw() {
  24. background(backgroundColor);
  25. translate(width/2, height/2); //mapping where to translate
  26. for (int i = 0; i < 360; i+=30) {
  27. float x = sin(radians(i+frameCount)) * 70; //radius of that circle x axis
  28. float y = cos(radians(i+frameCount)) * 90; //radius of that in y axis
  29. pushMatrix();
  30. translate(x, y);
  31. rotate(radians(-i)); //movement and rotation
  32. branch(75, i);
  33. popMatrix();
  34. }
  35. num+=0.05; //fastness of the animation
  36. }
  37.  
  38. void branch(int l, int i) {
  39. float theta = sin(num)*110;
  40.  
  41. ellipse(0, 0, 0, l); //line
  42. translate(0, l); //its mapping
  43.  
  44. l *= 0.66;
  45.  
  46. pathR = (((float)165/width)*mouseX+theta)+325*sin(i+num*2);
  47. pathG = (20+theta)+85*sin(i+num*6);
  48. pathB = (((float)35/height)*mouseY+theta)+8425*sin(i+num*7); //colors
  49.  
  50. if (l > 3) { //fastness
  51. stroke(pathR, pathG, pathB); //stroke color
  52. pushMatrix();
  53. rotate(radians(theta)); //what to rotate
  54. branch(l, i);
  55. popMatrix();
  56.  
  57. stroke(pathR, pathG, pathB); //stroke colors
  58. pushMatrix();
  59. rotate(-radians(theta)); //rotate in opposite way
  60. branch(l, i);
  61. popMatrix();
  62. } else {
  63. noStroke();
  64. fill(pathR, pathG, pathB); //else color and
  65. line(0, 0, 5, 5);
  66. }
  67. }
  68.  
  69. void mousePressed() { //if mouse pressed, background will change
  70. if (doOnce && backgroundColor == 255) {
  71. backgroundColor = 0;
  72. doOnce = false;
  73. }
  74. if (doOnce && backgroundColor == 0) { //if mouse is pressed again, background change
  75. backgroundColor = 255;
  76. doOnce = false;
  77. }
  78. }
  79.  
  80. void mouseReleased() {
  81. doOnce = true; //mouse released
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement