123456789101112131415161718192021222324252627282930 |
- function Star() {
- var x = 10, y = 10, diameter = 3, mindiameter = 0.1, maxdiameter = 3, height = 10;
- var pulse = 0.1;
- this.init = function(canvas) {
- x = Math.floor(canvas.width * Math.random());
- y = Math.floor(canvas.height * Math.random());
- diameter = 2 * Math.random() + 1;
- pulse = (10 * Math.random() + 1) / 1000;
- mindiameter = Math.random();
- maxdiameter = 2 * Math.random() + 1;
- };
- this.update = function(canvas) {
- diameter *= 1 + pulse;
- if(diameter > maxdiameter) {
- diameter = maxdiameter;
- pulse *= -1;
- }
- if(diameter < mindiameter) {
- diameter = mindiameter;
- pulse *= -1;
- }
- },
- this.draw = function(context, offset) {
- context.beginPath();
- context.arc(x + offset.x, y + offset.y, diameter, 0, 2 * Math.PI);
- context.fill();
- }
- }
|