WaterParticle.js 878 B

1234567891011121314151617181920212223242526272829303132
  1. var WaterParticle = function() {
  2. var wp = this;
  3. wp.x = 0;
  4. wp.y = 0;
  5. wp.z = Math.random() * 1 + 0.3;
  6. wp.size = 1.2;
  7. wp.opacity = Math.random() * 0.8 + 0.1;
  8. wp.update = function(bounds) {
  9. if(wp.x == 0 || wp.y == 0) {
  10. wp.x = Math.random() * (bounds[1].x - bounds[0].x) + bounds[0].x;
  11. wp.y = Math.random() * (bounds[1].y - bounds[0].y) + bounds[0].y;
  12. }
  13. // Wrap around screen
  14. wp.x = wp.x < bounds[0].x ? bounds[1].x : wp.x;
  15. wp.y = wp.y < bounds[0].y ? bounds[1].y : wp.y;
  16. wp.x = wp.x > bounds[1].x ? bounds[0].x : wp.x;
  17. wp.y = wp.y > bounds[1].y ? bounds[0].y : wp.y;
  18. };
  19. wp.draw = function(context) {
  20. // Draw circle
  21. context.fillStyle = 'rgba(226,219,226,'+wp.opacity+')';
  22. //context.fillStyle = '#fff';
  23. context.beginPath();
  24. context.arc(wp.x, wp.y, this.z * this.size, 0, Math.PI*2, true);
  25. context.closePath();
  26. context.fill();
  27. };
  28. }