star.js 808 B

123456789101112131415161718192021222324252627282930
  1. function Star() {
  2. var x = 10, y = 10, diameter = 3, mindiameter = 0.1, maxdiameter = 3, height = 10;
  3. var pulse = 0.1;
  4. this.init = function(canvas) {
  5. x = Math.floor(canvas.width * Math.random());
  6. y = Math.floor(canvas.height * Math.random());
  7. diameter = 2 * Math.random() + 1;
  8. pulse = (10 * Math.random() + 1) / 1000;
  9. mindiameter = Math.random();
  10. maxdiameter = 2 * Math.random() + 1;
  11. };
  12. this.update = function(canvas) {
  13. diameter *= 1 + pulse;
  14. if(diameter > maxdiameter) {
  15. diameter = maxdiameter;
  16. pulse *= -1;
  17. }
  18. if(diameter < mindiameter) {
  19. diameter = mindiameter;
  20. pulse *= -1;
  21. }
  22. },
  23. this.draw = function(context, offset) {
  24. context.beginPath();
  25. context.arc(x + offset.x, y + offset.y, diameter, 0, 2 * Math.PI);
  26. context.fill();
  27. }
  28. }