- Author:
- Evan Hahn
- Twitter:
- @
- GitHub:
- EvanHahn
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- evanhahn.com
- Compo:
- canvas
- Demo link:
- https://js1k.com/2016-elemental/demo/2584
- Shortlink:
- https://js1k.com/2584
- Blog post:
- please update here!
- Bytes:
- 870
- Chars:
- 870
- Submission
for(_='0,J),@in?",>Math.`*`random()_0_+5|^2*`PItionfunc)for(clickeightf.,00=[]ent(f){.map(}@E&&(,c.fill.push({.style.?ner:cli;padd?g:;font- >"(*P/I)opacityffStyle=cssText=",J)()c.beg?Path(@c.arc(bmarg?:00;background:#262747;overflow:hidden family:sans-serif size:26pt w:1>k=b.appendChild(docum.createElem("div")@kposi:fixed;top:0;left:0;width:1%26px;color:#f;text-align:cer;:1;transi: 3s>k.HTML=" for fireworks!>w=Width,h=H,r,p,b.on=k=JraX,bY,y:h})}, f(){E=1"#>rif(!d)if(E=J(y-=20)<bd=1,A=1^0;A;A--C="#"+["99>""][6_|0],F=7_+5,I=2^1JP=I;P;P--)pc:C,x:a,y:y,v:F,s:1Jf:`cos,g:`s?});else ay,2r@E=1,p(v-=.2)<0||(E=0g+=.03x+=f*vy+=g*vs=`max(s-=.5,1)c,xys)p@requestAnimaFrame(f)}();';G=/[-^-`>-@J]/.exec(_);)with(_.split(G))_=join(shift());eval(_)
- Description
- Click for colorful fireworks!
- Base64 encoded
Zm9yKF89JzAsSiksQGluPyIsPk1hdGguYCpgcmFuZG9tKClfMF8rNXxeMipgUEkfdGlvbh5mdW5jHh0pZm9yKBxjbGljaxtlaWdodBpmLhksGRgwMBc9W10WZW50FR0oZil7FC5tYXAoFBN9QEUmJigSLGMuZmlsbBEucHVzaCh7EC5zdHlsZS4PP25lcg46GWNsaRUMO3BhZGQ/ZzoLO2ZvbnQtCRc+IggoHypQL0kpB29wYWNpdHkGZmYFEVN0eWxlPQQPY3NzVGV4dD0iAyxKHykRKCkCYy5iZWc/UGF0aChAYy5hcmMoGQFiA21hcmc/OjALMDtiYWNrZ3JvdW5kOiMyNjI3NDc7b3ZlcmZsb3c6aGlkZGVuCWZhbWlseTpzYW5zLXNlcmlmCXNpemU6MjZwdAl3GjoxFz5rPWIuYXBwZW5kQ2hpbGQoZG9jdW0VLmNyZWF0ZUVsZW0VKCJkaXYiKUBrA3Bvc2keOmZpeGVkO3RvcDowO2xlZnQ6MDt3aWR0aDoxFyULMjZweDtjb2xvcjojBWY7dGV4dC1hbGlnbjpjFWVyOwY6MTt0cmFuc2keOgYgM3M+ay4OSFRNTD0iGyBmb3IgZmlyZXdvcmtzIT53PQ5XaWR0aCxoPQ5IGixyFixwFixiLm9uGz0Uaw8GPUpyEGEMWCxiDFkseTpofSl9LB0gZigpe0U9MQQiIwUFBT5yE2lmKCEZZClpZihFPUooGXktPTIwKTwZYhwZZD0xLEE9MV4wO0E7QS0tHEM9IiMiK1siBRcIBTk5CAUFCBcFCBcFBT4iBRcFIl1bNl98MF0sRj03Xys1LEk9Ml4xSlA9STtQO1AtLSlwEGM6Qyx4OhlhLHk6GXksdjpGLHM6MUpmOmBjb3MHLGc6YHM/B30pO2Vsc2UgAWEYeSwyAhJyFkBFPTEscBMoGXYtPS4yKTwwfHwoRT0wGGcrPS4wMxh4Kz0ZZioZdhh5Kz0ZZyoZdhhzPWBtYXgoGXMtPS41LDEpBBljLAF4GHkYcwIpEnAWQHJlcXVlc3RBbmltYR5GcmFtZShmKX0oKTsnO0c9L1sBLR9eLWA+LUBKXS8uZXhlYyhfKTspd2l0aChfLnNwbGl0KEcpKV89am9pbihzaGlmdCgpKTtldmFsKF8p
- Original source
/* eslint-disable no-undef */
// style the <body>
b.style.cssText = 'margin:0;padding:0;background:#262747;overflow:hidden;font-family:sans-serif;font-size:26pt;font-weight:100'
// add a div that tells you to click
k = b.appendChild(document.createElement('div'))
k.style.cssText = 'position:fixed;top:0;left:0;width:100%;padding:26px;color:#fff;text-align:center;opacity:1;transition:opacity 3s'
k.innerHTML = 'click for fireworks!'
// keep track of canvas size
w = innerWidth
h = innerHeight
// an array of all of the rockets and the particles
r = []
p = []
// shoots a rocket on click
b.onclick = function (clickEvent) {
k.style.opacity = 0
r.push({
a: clickEvent.clientX,
b: clickEvent.clientY,
y: h
})
};
// tick
(function T () {
// iterate through all the rockets, clearing the list if there aren't any active
U = 1
c.fillStyle = '#ffffff'
r.map(function (rocket) {
// skip if this rocket is already destroyed
if (rocket.d) { return }
// we've updated at least 1 rocket
U = 0
// shoot the rocket upward, destroying it if needed
if ((rocket.y -= 20) < rocket.b) {
// destroy the rocket
rocket.d = 1
// generate particles
for (R = (((Math.random() * 10) + 5) | 0); R; R--) {
// choose this ring's color, velocity
C = '#' + [
'ff0000',
'ff9900',
'ffff00',
'00ff00',
'00ffff',
'ff00ff'
][(Math.random() * 6) | 0]
V = (Math.random() * 7) + 5
// how many particles?
I = ((Math.random() * 20) + 5) | 10
// generate each particle
for (P = I; P; P--) {
p.push({
c: C,
x: rocket.a,
y: rocket.y,
v: V,
s: 10,
f: Math.cos(2 * Math.PI * P / I),
g: Math.sin(2 * Math.PI * P / I)
})
}
}
} else {
// draw the rocket
c.beginPath()
c.arc(rocket.a, rocket.y, 2, 0, 2 * Math.PI)
c.fill()
}
})
if (U) {
r = []
}
// iterate through all the particles, clearing them if you updated none
U = 1
p.map(function (particle) {
// stop if it's too slow
if ((particle.v -= 0.2) < 0) { return }
// we've updated at least one particle
U = 0
// slowly accelerate downward
particle.g += 0.03
// move the particle
particle.x += particle.f * particle.v
particle.y += particle.g * particle.v
// shrink
particle.s = Math.max(particle.s -= 0.5, 1)
// draw the particle
c.fillStyle = particle.c
c.beginPath()
c.arc(particle.x, particle.y, particle.s, 0, 2 * Math.PI)
c.fill()
})
if (U) {
p = []
}
// go again
requestAnimationFrame(T)
})()