github.com/nicgrayson/terraform@v0.4.3-0.20150415203910-c4de50829380/website/source/assets/javascripts/app/Engine.Particle.Fixed.js (about) 1 (function( 2 Particle, 3 Engine, 4 Vector 5 ){ 6 7 Particle.Fixed = function(width, height){ 8 var targetX, targetY; 9 10 this.radius = Engine.getRandomFloat(0.1, 1); 11 // this.fillA = 'rgba(136,67,237,' + Engine.getRandomFloat(0.4, 0.5) + ')'; 12 // this.fillB = 'rgba(136,67,237,' + Engine.getRandomFloat(0.51, 0.6) + ')'; 13 this.fillA = '#3a1066'; 14 this.fillB = '#561799'; 15 this.frameMax = Engine.getRandomInt(4, 10); 16 17 this.max = { 18 x: width + this.maxRadius, 19 y: height + this.maxRadius 20 }; 21 22 this.min = { 23 x: 0 - this.maxRadius, 24 y: 0 - this.maxRadius 25 }; 26 27 targetX = Engine.getRandomInt(0 + this.radius, width + this.radius); 28 targetY = Engine.getRandomInt(0 + this.radius, height + this.radius); 29 30 this.pos = new Vector(targetX, targetY); 31 }; 32 33 Engine.Particle.Fixed.prototype = { 34 35 radius: 1, 36 37 pos: { 38 x: 0, 39 y: 0 40 }, 41 42 frame: 0, 43 showA: false, 44 45 update: function(engine){ 46 this.frame++; 47 if (this.frame > this.frameMax) { 48 this.frame = 0; 49 this.showA = !this.showA; 50 } 51 return this; 52 }, 53 54 draw: function(ctx, scale){ 55 // Draw a circle - far less performant 56 ctx.beginPath(); 57 ctx.arc( 58 this.pos.x * scale >> 0, 59 this.pos.y * scale >> 0, 60 this.radius * scale, 61 0, 62 Math.PI * 2, 63 false 64 ); 65 if (this.showA) { 66 ctx.fillStyle = this.fillA; 67 } else { 68 ctx.fillStyle = this.fillB; 69 } 70 ctx.fill(); 71 72 return this; 73 } 74 75 }; 76 77 })(window.Engine.Particle, window.Engine, window.Vector);