var ARA = window.ARA || {}; ARA.canvas = ARA.canvas || {}; ARA.canvas.Starfield = function(el, params){ this.canvas = ARA.dom.getElement(el); if(this.canvas && this.canvas.getContext){ this.ctx = this.canvas.getContext('2d'); }else{ return null; } params = params || {}; this.fullScreen = !!params.fullScreen; this.xLimit = this.canvas.offsetWidth/2; this.yLimit = this.canvas.offsetHeight/2; this.zLimit = params.depth || 255; this.wave = {degree:0, dir:.1, ampl:25, freq:100}; this.animSpeed = params.animSpeed || 50; this.starCount = params.starCount || 100; this.zoomLimit = params.zoomLimit || 2; this.zoomFactor = params.zoomFactor || .035; this.starShape = params.starShape || "star"; this.waveX = params.waveX || false; this.waveY = params.waveY || false; this.stars = []; this.started = false; this.init(); }; ARA.canvas.Starfield.prototype.toString = function(){ return "Starfield#" + this.canvas.id; }; ARA.canvas.Starfield.prototype.init = function(){ this.ctx.translate(this.xLimit, this.yLimit); this.stars = []; for(var i=0; i this.xLimit){ this.recycleStar(star); }else{ star.x += (star.x * star.acc) / 200; if(this.waveX) star.x += this.wave.ampl * Math.sin(this.wave.degree); } if(Math.abs(star.y) > this.yLimit){ this.recycleStar(star); }else{ star.y += (star.y * star.acc) / 200; if(this.waveY) star.y += this.wave.ampl * Math.sin(this.wave.degree); } star.z = (star.z < this.zoomLimit) ? star.z + this.zoomFactor : star.z; star.color += (star.color < 255) ? star.acc : 0; this.drawStar(star); } if(this.waveX || this.waveY){ if(this.wave.degree > 90 || this.wave.degree < 0) this.wave.dir *= -.1; this.wave.degree += this.wave.dir; } } ARA.canvas.Starfield.prototype.drawStar = function(star){ this.ctx.fillStyle = "rgb(" + star.color + "," + star.color + "," + star.color + ")"; switch(this.starShape){ case "square": this.ctx.fillRect(star.x, star.y, star.z, star.z); break; case "circle": this.ctx.beginPath(); this.ctx.arc(star.x, star.y, star.z, 0, Math.PI*2, true); this.ctx.fill(); break; case "star": var starCoords = ARA.canvas.Starfield.shapes.star; this.ctx.beginPath(); this.ctx.moveTo(star.x, star.y); for(var i=0; i