WordPress Header Animation with Processing.js

After I knew about Processing.js, “WordPress header animation with Processing.js” is in my to do list. I finally get it up today. I studied and modified the current header animation from Processing.js. I hope I can create more advance and impressive animation in future. Below is the modified code as reference.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  1. <script type="application/processing">
  2. // Build float array to store circle properties
  3. float[] e = new float[5];
  4.  
  5. // Set up canvas
  6. void setup(){
  7. // Frame rate
  8. frameRate(15);
  9.  
  10. // Stroke/line/border thickness
  11. strokeWeight(1);
  12.  
  13. // Initiate random values for circles
  14. e[0] = random(width); // X
  15. e[1] = random(height); // Y
  16. e[2] = random(20, 90); // Radius
  17. e[3] = random(-.5, .5); // X Speed
  18. e[4] = random(-.5, .5); // Y Speed
  19. }
  20.  
  21. // Begin main draw loop (refresh 15 times per second)
  22. void draw(){
  23. // Fill background black
  24. background(0);
  25.  
  26. // Cache diameter and radius of current circle
  27. float radius = e[2];
  28. float diameter = radius / 2;
  29.  
  30. // Disable shape stroke/border
  31. noStroke();
  32.  
  33. // Fill with green colour
  34. fill(#98c92a, 100);
  35.  
  36. // Draw circle
  37. ellipse(e[0], e[1], radius, radius);
  38.  
  39. // Move circle
  40. e[0] += e[3];
  41. e[1] += e[4];
  42.  
  43. /* Wrap edges of canvas so circles leave the top
  44. and re-enter the bottom, etc. */
  45. if ( e[0] < -diameter ) { e[0] = width + diameter; }
  46. if ( e[0] > width + diameter ) { e[0] = -diameter; }
  47. if ( e[1] < 0 - diameter ) { e[1] = height + diameter; }
  48. if ( e[1] > height + diameter ) { e[1] = -diameter; }
  49.  
  50. // Set fill color of center dot to white.
  51. fill( 255, 255, 255, 255 );
  52.  
  53. // Turn off stroke/border
  54. noStroke();
  55.  
  56. // Draw dot in center of circle
  57. rect(e[0]-1, e[1]-1, 2, 2);
  58. }
  59. </script>
  60. <canvas id="navCanvas" ></canvas>

References

No Comments

No comments yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">