- Author:
- cody
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- m0ose.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/642
- Shortlink:
- https://js1k.com/642
- Blog post:
- please update here!
- Bytes:
- 895
- Chars:
- 895
- Submission
init();canvas=document.getElementById("c");ca=canvas;W=ca.width=window.innerWidth-24;H=ca.height=window.innerHeight-24;X=ca.getContext("2d");sl;sh;
M=Math;Mf=M.floor;var s;var ants;function ant(x,y,d){this.x=x;this.y=y;this.d=d%4}function init(){sl=100;sh=100;s=new Array(sl);
ants=[new ant(50,50,1)];for(var x=0;x<s.length;x++){s[x]=new Array(sh)}setInterval("loop()",1)}function loop(){for(i=0;
i<ants.length;i++){a=ants[i];if(s[a.x][a.y]&&s[a.x][a.y]==1){s[a.x][a.y]=M.ceil(M.random()*254+1);a.d=(a.d+1)%4}else{s[a.x][a.y]=1;
a.d=((a.d-1)+4)%4 ;}if(a.d==0)a.x=(a.x+1)%sl;if(a.d==2)a.x=((a.x-1)+sl)%sl;if(a.d==1)a.y=(a.y+1)%sh;if(a.d==3)a.y=((a.y-1)+sh)%sh}X.fillStyle="rgb(0,0,0)";X.fillRect(0,0,W,H);l=Mf(W/sl);h=Mf(H/sh);for(x=0;x<sl;x++){for(y=0;y<sh;y++){if(s[x][y]){if(s[x][y]==1){X.fillStyle="rgb(255, 255, 200)"}else{X.fillStyle="rgb("+s[x][y]+",0,0)"}X.fillRect(x*l,y*h,l,h)}}}}
- Description
- Virtual Ants
- Base64 encoded
aW5pdCgpO2NhbnZhcz1kb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiYyIpO2NhPWNhbnZhcztXPWNhLndpZHRoPXdpbmRvdy5pbm5lcldpZHRoLTI0O0g9Y2EuaGVpZ2h0PXdpbmRvdy5pbm5lckhlaWdodC0yNDtYPWNhLmdldENvbnRleHQoIjJkIik7c2w7c2g7DQpNPU1hdGg7TWY9TS5mbG9vcjt2YXIgczt2YXIgYW50cztmdW5jdGlvbiBhbnQoeCx5LGQpe3RoaXMueD14O3RoaXMueT15O3RoaXMuZD1kJTR9ZnVuY3Rpb24gaW5pdCgpe3NsPTEwMDtzaD0xMDA7cz1uZXcgQXJyYXkoc2wpOw0KYW50cz1bbmV3IGFudCg1MCw1MCwxKV07Zm9yKHZhciB4PTA7eDxzLmxlbmd0aDt4Kyspe3NbeF09bmV3IEFycmF5KHNoKX1zZXRJbnRlcnZhbCgibG9vcCgpIiwxKX1mdW5jdGlvbiBsb29wKCl7Zm9yKGk9MDsNCmk8YW50cy5sZW5ndGg7aSsrKXthPWFudHNbaV07aWYoc1thLnhdW2EueV0mJnNbYS54XVthLnldPT0xKXtzW2EueF1bYS55XT1NLmNlaWwoTS5yYW5kb20oKSoyNTQrMSk7YS5kPShhLmQrMSklNH1lbHNle3NbYS54XVthLnldPTE7DQphLmQ9KChhLmQtMSkrNCklNCA7fWlmKGEuZD09MClhLng9KGEueCsxKSVzbDtpZihhLmQ9PTIpYS54PSgoYS54LTEpK3NsKSVzbDtpZihhLmQ9PTEpYS55PShhLnkrMSklc2g7aWYoYS5kPT0zKWEueT0oKGEueS0xKStzaCklc2h9WC5maWxsU3R5bGU9InJnYigwLDAsMCkiO1guZmlsbFJlY3QoMCwwLFcsSCk7bD1NZihXL3NsKTtoPU1mKEgvc2gpO2Zvcih4PTA7eDxzbDt4Kyspe2Zvcih5PTA7eTxzaDt5Kyspe2lmKHNbeF1beV0pe2lmKHNbeF1beV09PTEpe1guZmlsbFN0eWxlPSJyZ2IoMjU1LCAyNTUsIDIwMCkifWVsc2V7WC5maWxsU3R5bGU9InJnYigiK3NbeF1beV0rIiwwLDApIn1YLmZpbGxSZWN0KHgqbCx5KmgsbCxoKX19fX0NCg==
- Original source
<!doctype html>
<html>
<head>
<title>JS1k, bird shit </title>
<meta charset="utf-8" />
</head>
<body>
<canvas id="c"></canvas>
<script>
init();
canvas = document.getElementById("c");
ca = canvas;
W = ca.width = window.innerWidth - 24;
H = ca.height = window.innerHeight -24;
X = ca.getContext("2d");
sl;
sh;
M= Math;
Mf =M.floor;
var s;
var ants;
function ant( x,y,d)
{
this.x = x;
this.y = y;
this.d = d % 4;
}
function init()
{
//fill
sl = 100;
sh = 100;
s = new Array( sl );
ants = [ new ant( 50,50,1) ];
for( var x = 0 ; x < s.length; x++)
{
s[x] = new Array(sh);
}
setInterval( "loop()" , 1 );
}
function loop()
{
for( i = 0 ; i < ants.length; i++)
{
a = ants[i];
if( s[a.x][a.y] && s[a.x][a.y] == 1)
{
//stamp black
s[a.x][a.y] = M.ceil(M.random() * 254 + 1);
//r ight turn
a.d = ( a.d + 1 ) % 4 ;
}
else
{
//stamp white
s[a.x][a.y] = 1;
//left turn
a.d = (( a.d - 1) + 4) % 4;
}
if( a.d == 0) a.x = (a.x + 1) % sl;
if( a.d == 2) a.x = ((a.x - 1) + sl ) % sl;
if( a.d == 1) a.y = (a.y + 1) % sh;
if( a.d == 3) a.y = ((a.y - 1) + sh) % sh;
}
X.fillStyle = "rgb(0,0,0)";
X.fillRect(0,0, W,H);
l = Mf( W / sl);
h = Mf( H / sh);
for( x = 0 ; x < sl; x++)
{
for( y = 0 ; y < sh; y++)
{
if( s[x][y])
{
if( s[x][y] == 1){
X.fillStyle = "rgb(255, 255, 200)";
}
else
{
X.fillStyle = "rgb("+ s[x][y]+",0,0)";
}
X.fillRect( x * l,y * h, l ,h);
}
}
}
}
</script>
</body>
</html>