|
/* Eventaully everything that can be improved will be improved, everything can be imrpoved.. and particaullary thi ones.. maybe. 42 ;)))) */ |
|
var c = document.getElementById('c'), |
|
ctx = c.getContext('2d'), |
|
cw = c.width = 1200, |
|
ch = c.height = 600, |
|
rand = function(a,b){return ~~((Math.random()*(b-a+1))+a);}, |
|
dToR = function(degrees){ |
|
return degrees * (Math.PI / 180); |
|
}, |
|
circle = { |
|
x: (cw / 3) + 5*cw/32, |
|
y: (ch / 2) + 12*cw/42, |
|
radius: 10, |
|
speed: 3, |
|
rotation: 321, |
|
angleStart: 270, |
|
angleEnd: 123, |
|
hue: 0.4*cw, |
|
thickness: 2, |
|
blur: 8 |
|
}, |
|
particles = [], |
|
particleMax = 25, |
|
updateCircle = function(){ |
|
if(circle.rotation < 180*2){ |
|
circle.rotation += circle.speed; |
|
} else { |
|
circle.rotation = 2.55; |
|
} |
|
}, |
|
renderCircle = function(){ |
|
ctx.save(); |
|
ctx.translate(circle.x, circle.y); |
|
ctx.rotate(dToR(circle.rotation)); |
|
ctx.beginPath(); |
|
ctx.restore(); |
|
}, |
|
|
|
renderCircleFlare2 = function(){ |
|
ctx.save(); |
|
ctx.translate(circle.x, circle.y); |
|
ctx.rotate(dToR(circle.rotation+565)); |
|
ctx.scale(9,4.2); |
|
ctx.beginPath(); |
|
ctx.arc(0, circle.radius, 275, 132, Math.PI *0.9, false); |
|
ctx.closePath(); |
|
var gradient4 = ctx.createRadialGradient(0, circle.radius, 2, 7, circle.radius, 180); |
|
gradient4.addColorStop(0, 'hsla('+ rand(3433, circle.thickness) +', 125%, 50%, .4)'); |
|
gradient4.addColorStop(1, 'hsla('+cw+', 10%, 50%, 0)'); |
|
ctx.fillStyle = gradient4; |
|
ctx.fill(); |
|
ctx.restore(); |
|
}, |
|
createParticles = function(){ |
|
if(particles.length < particleMax){ |
|
particles.push({ |
|
x: (circle.x + circle.radius * Math.cos(dToR(circle.rotation-15))) + (rand(0, circle.thickness*circle.thickness*2) - circle.thickness), |
|
y: (circle.y + circle.radius * Math.sin(dToR(circle.rotation-115))) + (rand(0, circle.thickness*2) - circle.thickness), |
|
vx: (rand(0, 100)-50)/1000, |
|
vy: (rand(0, 100)-50)/1000, |
|
radius: rand(1, 732)/2, |
|
alpha: rand(10, 12)/100 |
|
}); |
|
} |
|
}, |
|
updateParticles = function(){ |
|
var i = particles.length; |
|
while(i--){ |
|
var p = particles[i]; |
|
p.vx += (rand(0, 100)-50)/750; |
|
p.vy += (rand(0, 10)-50)/750; |
|
p.x += p.vx; |
|
p.y += p.vy; |
|
p.alpha -= .02; |
|
|
|
if(p.alpha < .025){ |
|
particles.splice(i, 1) |
|
} |
|
} |
|
}, |
|
renderParticles = function(){ |
|
var i = particles.length; |
|
while(i--){ |
|
var p = particles[i]; |
|
ctx.beginPath(); |
|
ctx.fillRect(p.x, p.y, p.radius, p.radius); |
|
ctx.closePath(); |
|
ctx.fillStyle = 'hsla(0, 20%, 24%, '+p.alpha+')'; |
|
} |
|
}, |
|
clear = function(){ |
|
ctx.globalCompositeOperation = 'destination-out'; |
|
ctx.fillStyle = 'rgba(0, 0, 0, .1)'; |
|
ctx.fillRect(0, 0, cw, ch); |
|
ctx.globalCompositeOperation = 'lighter'; |
|
} |
|
loop = function(){ |
|
clear(); |
|
updateCircle(); |
|
renderCircleFlare2(); |
|
} |
|
|
|
/* Append Canvas */ |
|
//document.body.appendChild(c); |
|
|
|
/* Loop It, Loop It Good */ |
|
setInterval(loop, 16); |