- Author:
- Jeremy Clarke
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- geckojsc.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-xmas/demo/895
- Shortlink:
- https://js1k.com/895
- Blog post:
- please update here!
- Bytes:
- 1023
- Chars:
- 1023
- Submission
c.height*=2;g=[];h=[];for(x=-4;x<80;x++)for(y=0,g[x]=[],h[x]=[];y<76;y++)g[x][y]=h[x][y]=1;p=3;onkeydown=function(e){k=e.keyCode;48<k&&k<55?p=k-48:0};c.onmousemove=function(e){g[e.pageX/4|0][e.pageY/4|0]=p};setInterval(function(){for(x=0;x<75;x++){r=Math.random()*75|0;R=r%3-1;j=g[x];J=h[x];X=g[x+1];Z=g[x-1];l=g[x+R];L=g[x-R];q=h[x+R];Q=h[x-R];for(y=0;y<76;y++){t=j[y];d=j[Y=y+1];u=j[z=y-1];s=0;t==5&&R&&u^4?J[z]=5:t==4&&J[y]==1?d^1?l[Y]==1&&l[y]^4?q[Y]=4:L[Y]==1&&L[y]^4?Q[Y]=4:l[y]^1||q[y]^1?s=1:q[y]=4:J[Y]=4:t^3?t^2?0:s=1:d^1&&d^4?l[Y]==1&&l[y]^3?q[Y]=3:L[Y]==1&&L[y]^3?Q[Y]=3:J[y]=l[y+R]^5?t:4:(J[Y]=3,J[y]=d);if(t==6)if(d^3||j[y+2]^3)J[Y]=6;else{if(u&&!r%9)for(i=-4;i<5;i++)h[x+i][z]=g[x+i][z]^1?g[x+i][z]:0;s=1;};if(!t)R?Z[y]==1&&!X[y]&&g[x-2][y]^1?h[x+1][z]=0:X[y]==1&&!Z[y]&&g[x+2][y]^1?h[x-1][z]=0:Z[y]||X[y]?0:h[x][z]=0:0,s=1;s?J[y]=t?t:X[y]^5||u^5?t:5:0;a.fillStyle='#'+['2d3','000','877','eff','24f','f90','860'][t];a.fillRect(x*4,y*4,4,4);}}for(x in g)for(y in g[x])g[x][y]=1;G=g;H=h;g=H;h=G;g[r][0]=3;},75);
- Description
- It's a 'falling sand' game, with snow and Christmas trees!
Move the mouse to draw and hit the number keys to change the pen.
1 - empty space
2 - walls
3 - snow
4 - water
5 - fire
6 - trees
- Base64 encoded
Yy5oZWlnaHQqPTI7Zz1bXTtoPVtdO2Zvcih4PS00O3g8ODA7eCsrKWZvcih5PTAsZ1t4XT1bXSxoW3hdPVtdO3k8NzY7eSsrKWdbeF1beV09aFt4XVt5XT0xO3A9MztvbmtleWRvd249ZnVuY3Rpb24oZSl7az1lLmtleUNvZGU7NDg8ayYmazw1NT9wPWstNDg6MH07Yy5vbm1vdXNlbW92ZT1mdW5jdGlvbihlKXtnW2UucGFnZVgvNHwwXVtlLnBhZ2VZLzR8MF09cH07c2V0SW50ZXJ2YWwoZnVuY3Rpb24oKXtmb3IoeD0wO3g8NzU7eCsrKXtyPU1hdGgucmFuZG9tKCkqNzV8MDtSPXIlMy0xO2o9Z1t4XTtKPWhbeF07WD1nW3grMV07Wj1nW3gtMV07bD1nW3grUl07TD1nW3gtUl07cT1oW3grUl07UT1oW3gtUl07Zm9yKHk9MDt5PDc2O3krKyl7dD1qW3ldO2Q9altZPXkrMV07dT1qW3o9eS0xXTtzPTA7dD09NSYmUiYmdV40P0pbel09NTp0PT00JiZKW3ldPT0xP2ReMT9sW1ldPT0xJiZsW3ldXjQ/cVtZXT00OkxbWV09PTEmJkxbeV1eND9RW1ldPTQ6bFt5XV4xfHxxW3ldXjE/cz0xOnFbeV09NDpKW1ldPTQ6dF4zP3ReMj8wOnM9MTpkXjEmJmReND9sW1ldPT0xJiZsW3ldXjM/cVtZXT0zOkxbWV09PTEmJkxbeV1eMz9RW1ldPTM6Slt5XT1sW3krUl1eNT90OjQ6KEpbWV09MyxKW3ldPWQpO2lmKHQ9PTYpaWYoZF4zfHxqW3krMl1eMylKW1ldPTY7ZWxzZXtpZih1JiYhciU5KWZvcihpPS00O2k8NTtpKyspaFt4K2ldW3pdPWdbeCtpXVt6XV4xP2dbeCtpXVt6XTowO3M9MTt9O2lmKCF0KVI/Wlt5XT09MSYmIVhbeV0mJmdbeC0yXVt5XV4xP2hbeCsxXVt6XT0wOlhbeV09PTEmJiFaW3ldJiZnW3grMl1beV1eMT9oW3gtMV1bel09MDpaW3ldfHxYW3ldPzA6aFt4XVt6XT0wOjAscz0xO3M/Slt5XT10P3Q6WFt5XV41fHx1XjU/dDo1OjA7YS5maWxsU3R5bGU9JyMnK1snMmQzJywnMDAwJywnODc3JywnZWZmJywnMjRmJywnZjkwJywnODYwJ11bdF07YS5maWxsUmVjdCh4KjQseSo0LDQsNCk7fX1mb3IoeCBpbiBnKWZvcih5IGluIGdbeF0pZ1t4XVt5XT0xO0c9ZztIPWg7Zz1IO2g9RztnW3JdWzBdPTM7fSw3NSk7
- Original source
/*
The uncompressed source looked something like this before I started shrinking it.
This isn't exactly the same though, I had to change a bit of functionality to make it fit into 1024 bytes.
I added a few comments too.
*/
// initialize the grids and canvas and pen:
c.height=300;
g=[], h=[];
for (x=-4; x<80; x++) {
g[x]=[], h[x]=[];
for (y=-1; y<76; y++) g[x][y]=h[x][y]=1;
}
p = 3;
onkeydown = function (e) {
k = e.keyCode;
if (48<k&&k<55) p = k-48;
};
// I later discovered that |0 is better than ~~ because it has lower precedence.
c.onmousemove = function (e) { g[~~(e.pageX/4)][~~(e.pageY/4)] = p; };
setInterval(function () {
for (x=0; x<75; x++) {
r = ~~(Math.random()*75);
R = ~~(r%3-1);
for (y=0; y<76; y++) {
j=g[x]; J=h[x];
t = j[y];
d = j[y+1];
u = j[y-1];
s=0;
// all the cell logic happens down here:
if (t==5) {
if (R&&u^4) h[x][y-1] = 5; // for integers, ^ is the same as !=
}
if (t==4&&h[x][y]==1) {
if (d==1) h[x][y+1]=4;
else if (g[x+R][y+1]==1&&g[x+R][y]^4) h[x+R][y+1]=4;
else if (g[x-R][y+1]==1&&g[x-R][y]^4) h[x-R][y+1]=4;
else if (g[x+R][y]==1&&h[x+R][y]==1) h[x+R][y] = 4;
else s=1;
}
if (t==3) {
// in the compressed source I used ternary operator in place of ifs as much as possible
d==1||d==4 ? (h[x][y+1]=3, h[x][y]=d)
: (g[x+R][y+1]==1&&g[x+R][y]^3 ? h[x+R][y+1]=3
: (g[x-R][y+1]==1&&g[x-R][y]^3 ? h[x-R][y+1]=3
: h[x][y] = g[x+R][y+R]==5 ? 4 : t));
}
if (t==2) s=1;
if (t==6) {
if (d==3&&g[x][y+2]==3) {
if (u^0&&u^5&&!r%9) for (i=-4;i<5;i++) h[x+i][y-1] = g[x+i][y-1]==1 ? 0:g[x+i][y-1];
s=1;
}
else h[x][y+1] = 6;
}
// 0 is the cell code for tree leaves.
if (t==0)
g[x-1][y]==1&&g[x+1][y]==0&&g[x-2][y]^1&&R&&R ? h[x+1][y-1]=0 :0,
g[x+1][y]==1&&g[x-1][y]==0&&g[x+2][y]^1&&R ? h[x-1][y-1]=0 :0,
g[x-1][y]==0&&g[x+1][y]==0&&R ? h[x][y-1]=0 :0,
s=1;
if (s) h[x][y] = t==0||t==6? (g[x+1][y+R]==5||g[x-1][y-R]==5?5:t) : t;
// picking colours from an array literal:
a.fillStyle = '#'+['2d3','000','877','eff','24f','f90','860'][t];
a.fillRect(x*4, y*4, 4, 4);
}
}
for (x=0; x<75; x++) for (y=0; y<76; y++) g[x][y] = 1; // clear before swapping...
G=g;H=h;g=H;h=G; // swap grids
g[r][0] = 3; // add random snow to the top of the screen.
}, 75);