- Author:
- Gavin Suntop
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- promofunk.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-xmas/demo/866
- Shortlink:
- https://js1k.com/866
- Blog post:
- please update here!
- Bytes:
- 1021
- Chars:
- 1021
- Submission
for($ in a)a[$[0]+($[6]||$[2])]=a[$];c.width=960;c.height=600;B=[];P=0;function H(b,d){cl=["rgba(255,99,240,.8)","rgba(182,255,27,.8)","rgba(255,195,9,.8)","rgba(66,255,255,.8)"];B.push({x:b,y:d,c:cl[P]});P<3?P++:(P=0)}function DB(b){a.ba();a.ac(b.x,b.y,10,0,360,0);a.ac(b.x,b.y-12,6,0,360,0);a.ac(b.x,b.y-17,5,0,360,0);a.fillStyle=b.c;a.shadowColor="#fff";a.shadowBlur=25;a.fl();a.shadowBlur=0;a.ca()}function DC(b){r=b.length;if(r>1)for(i=1;i<r;i++){a.ba();a.strokeStyle="#555";a.ca();a.mv(B[i-1].x,B[i-1].y-22);B[i].x>B[i-1].x?(q=(B[i].x-B[i-1].x)/2+B[i-1].x):(q=(B[i-1].x-B[i].x)/2+B[i].x);a.qt(q,600,B[i].x,B[i].y-22);a.mv(B[i].x,B[i].y-22);a.ca();a.sr()}}function R(){a.fillStyle="#000";a.fc(0,0,960,600);DC(B);for(k=0;k<B.length;k++)DB(B[k])}function X(b){return b.layerX||b.offsetX}function Y(b){return b.layerY||b.offsetY}c.a=c.addEventListener;c.a("mousemove",function(b){if(L=B.length){B[L-1].x=X(b);B[L-1].y=Y(b)}else H(X(b),Y(b));R()},1);c.a("click",function(b){H(X(b),Y(b));B.length<2&&H(X(b),Y(b))},1);R();
- Description
- XMASS Light Hanger
Click to string up the lights!
(v1.1: Added glow, more CPU friendly.)
- Base64 encoded
Zm9yKCQgaW4gYSlhWyRbMF0rKCRbNl18fCRbMl0pXT1hWyRdO2Mud2lkdGg9OTYwO2MuaGVpZ2h0PTYwMDtCPVtdO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VuY3Rpb24oYil7aWYoTD1CLmxlbmd0aCl7QltMLTFdLng9WChiKTtCW0wtMV0ueT1ZKGIpfWVsc2UgSChYKGIpLFkoYikpO1IoKX0sMSk7Yy5hKCJjbGljayIsZnVuY3Rpb24oYil7SChYKGIpLFkoYikpO0IubGVuZ3RoPDImJkgoWChiKSxZKGIpKX0sMSk7UigpOw==
- Original source
//
// X-MASS by Gavin Suntop [ promofunk.com ]
// for Xmas1k [ http://js1k.com/2010-xmas/ ]
//
//assign shortcodes to context properties
for($ in a){
a[$[0]+($[6]||$[2])]=a[$]
}
//console.log(a)
c.width = 960
c.height = 600
B = [] // bulB
P = 0 // colorPosition
function H(x,y) { // addBulb
cl = [ // colors
'rgba(255,99,240,.8)', // pink
'rgba(182,255,27,.8)', // green
'rgba(255,195,9,.8)', // orange
'rgba(66,255,255,.8)' // blue
]
B.push({x:x,y:y,c:cl[P]})
P < 3 ? P++ : P = 0 // 1 is cl length - 1
}
function DB(p) { // drawBulb
a.ba()
a.ac(p.x,p.y,10,0,360,0)
a.ac(p.x,p.y-12,6,0,360,0)
a.ac(p.x,p.y-17,5,0,360,0)
a.fillStyle = p.c
a.shadowColor = '#fff'
a.shadowBlur = 25
a.fl()
a.shadowBlur = 0
a.ca()
}
function DC(p) { // drawCords
r = p.length
if(r > 1) {
for(i=1;i<r;i++) {
a.ba()
a.strokeStyle = '#555'
a.ca()
a.mv(B[i-1].x, B[i-1].y-22)
B[i].x > B[i-1].x ? q = (B[i].x - B[i-1].x)/2 + B[i-1].x : q = (B[i-1].x - B[i].x)/2 + B[i].x
a.qt(q,600,B[i].x,B[i].y-22)
a.mv(B[i].x, B[i].y-22)
a.ca()
a.sr()
}
}
}
function R() { // draw
//console.log('Redrawing');
a.fillStyle = "#000"
a.fc(0,0,960,600) // clear canvas
DC(B)
for (k=0;k < B.length; k++) {
DB(B[k])
}
}
function X(e) { return e.layerX || e.offsetX }
function Y(e) { return e.layerY || e.offsetY }
c.a = c.addEventListener
c.a('mousemove',function(e) {
L = B.length
if(L) {
B[L-1].x = X(e)
B[L-1].y = Y(e)
} else
H(X(e),Y(e))
R() // Redraw as the mouse moves
},1)
c.a('click',function(e) {
H(X(e), Y(e))
B.length < 2 ? H(X(e), Y(e)) : 0
},1)
R()