- Author:
- Gísli Konráð
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-xmas/demo/876
- Shortlink:
- https://js1k.com/876
- Blog post:
- please update here!
- Bytes:
- 1022
- Chars:
- 1022
- Submission
W=c.width=800;H=c.height=600;S="fillStyle";T="fillText";L="length";M=Math;R=M.random;C=M.ceil;J=10;U=20;P="push";var d=9*H,e=1,j=[];a.strokeStyle="#fff";a.lineWidth=3;for(var k=0;k<d;k++)j[P](new l(H));onkeydown=function(b){b=b.keyCode;b==37&&e--;b==39&&e++;if(b==38)d+=J;if(b==40&&d>J)d-=J};function l(b){this.b=R()*b;this.a=R()*W+1;this.c=R()+1;this.e=R()*3;this.f=R()*(H/3);this.d=R()+1}setInterval(function(){var b=W,f=H;a[S]="#000";for(a.fillRect(0,0,b,f);j[L]!=d;)if(j[L]>d)j.pop();else j[L]<d&&j[P](new l(H));b=W/2;f=H/2;var g=250,h=W/2-H/U,i=H-H/J,m=H/J,n=H/J;a[S]="#630";a.fillRect(h,i,m,n);a[S]="#080";for(h=0;h<5;h++){with(a){beginPath();moveTo(b-g*0.8,f+g);lineTo(b,f);lineTo(b+g*0.8,f+g);fill();stroke()}g/=2;f-=g*0.6}for(b=0;b<j[L];b++){i=j[b].d;f=j[b].a+j[b].e*M.sin(j[b].f+j[b].b/U);g=j[b].b;i=h=i;a[S]="#fff";a.fillRect(f,g,h,i);j[b].b+=j[b].c;j[b].a+=e;if(j[b].a>W)j[b].a-=W;if(j[b].a<0)j[b].a+=W;if(j[b].b>H)j[b]=new l(-9)}a[S]="#080";a.font="18pt Arial";a[T]("Flakes:"+d,U,U);a[T]("Wind:"+e,U,50)},33);
- Description
- Simple particle system of snow flakes with a tree in the center of the scene.
Up/Down: Adds/Removes snow flakes
Left/Right: Manipulates wind
- Base64 encoded
Vz1jLndpZHRoPTgwMDtIPWMuaGVpZ2h0PTYwMDtTPSJmaWx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ZixnLGgsaSk7altiXS5iKz1qW2JdLmM7altiXS5hKz1lO2lmKGpbYl0uYT5XKWpbYl0uYS09VztpZihqW2JdLmE8MClqW2JdLmErPVc7aWYoaltiXS5iPkgpaltiXT1uZXcgbCgtOSl9YVtTXT0iIzA4MCI7YS5mb250PSIxOHB0IEFyaWFsIjthW1RdKCJGbGFrZXM6IitkLFUsVSk7YVtUXSgiV2luZDoiK2UsVSw1MCl9LDMzKTs=
- Original source
W=c.width=800;
H=c.height=600;
S='fillStyle';
T='fillText';
L='length';
M = Math;
R = M.random;
C = M.ceil;
J=10;
U=20;
P='push';
var count = 9*H;
var wind = 1;
var particles = [];
a.strokeStyle = '#fff';
a.lineWidth = 3;
for(var i=0;i < count;i++){
particles[P](new Flake(H));
}
function DrawRect(x,y,w,h,c){
if(c)a[S]=c;
else a[S]='#000';
a.fillRect(x,y,w,h);
}
onkeydown=function(e){
var k = e.keyCode;
if(k==37) wind--;
if(k==39) wind++;
if(k==38) count+=J;
if(k==40&&count>J) count-=J;
}
function DrawTree(){
var x = W/2;
var y = H/2;
var offset = 250;
DrawRect(W/2-H/U,H-H/J,H/J,H/J,'#630');
a[S]='#080';
for(var i = 0;i<5;i++)
{
with(a)
{
beginPath();
moveTo(x-offset*.8,y+offset);
lineTo(x,y);
lineTo(x+offset*.8,y+offset);
fill();
stroke();
}
offset = offset / 2;
y = y-(offset*.6);
}
}
function HandleAndDrawParticles(){
for(var i=0;i<particles[L];i++) {
var size = particles[i].Size;
var x = particles[i].X+particles[i].Swirve*M.sin((particles[i].SwirveOffset + particles[i].Y/U));
var y = particles[i].Y;
DrawRect(x,y,size,size,'#fff');
particles[i].Y += particles[i].FallSpeed;
particles[i].X += wind;
if(particles[i].X > W)
particles[i].X -= W;
if(particles[i].X < 0)
particles[i].X +=W;
if(particles[i].Y > H)
particles[i] = new Flake(-9);
}
}
function Loop(){
DrawRect(0,0,W,H);
while(particles[L] != count) {
if(particles[L] > count)
particles.pop();
else if(particles[L] < count)
particles[P](new Flake(H));
}
DrawTree();
HandleAndDrawParticles();
a[S]='#080';
a.font='18pt Arial';
a[T]('Flakes:' + count, U,U);
a[T]('Wind:' + wind, U,50);
}
function Flake(MaxY){
this.Y = R()*MaxY;
this.X = R()*W+1;
this.FallSpeed = R()+1;
this.Swirve = R()*3;
this.SwirveOffset = R()*(H/3);
this.Size = R()+1;
}
setInterval(Loop, 33);