- Author:
- Daniel
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- rappdaniel.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/511
- Shortlink:
- https://js1k.com/511
- Blog post:
- please update here!
- Bytes:
- 703
- Chars:
- 703
- Submission
k=350;x=[];y=[];r=[];s=[];m=Math;d=document.getElementById("c");c=d.getContext("2d");d.width=k;d.height=k;function dist(a,b,e,f){return m.sqrt((a-e)*(a-e)+(b-f)*(b-f))}function ok(a){if(dist(x[a],y[a],k/2,k/2)>k/2-r[a])return 0;for(j=0;++j<a;)if(dist(x[a],y[a],x[j],y[j])<r[a]+r[j])return 0;return 1}for(i=0;++i<400;){r[i]=1;s[i]=m.random()*9+3;do{x[i]=m.random()*k;y[i]=m.random()*k}while(!ok(i));for(;ok(i);)r[i]++}
onmousemove=function(a){c.clearRect(0,0,k,k);for(j=0;++j<i;){c.beginPath();c.moveTo(x[j]+r[j],y[j]);for(o=0;o<6;o+=6/s[j])c.lineTo(x[j]+r[j]*m.cos(o),y[j]+r[j]*m.sin(o));c.lineTo(x[j]+r[j],y[j]);c.fillStyle=dist(a.pageX,a.pageY,x[j],y[j])<50?"#a9ffa9":"#a9a9ff";c.fill();c.stroke()}};
- Description
- Polygon packer
- Base64 encoded
az0zNTA7eD1bXTt5PVtdO3I9W107cz1bXTttPU1hdGg7ZD1kb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiYyIpO2M9ZC5nZXRDb250ZXh0KCIyZCIpO2Qud2lkdGg9aztkLmhlaWdodD1rO2Z1bmN0aW9uIGRpc3QoYSxiLGUsZil7cmV0dXJuIG0uc3FydCgoYS1lKSooYS1lKSsoYi1mKSooYi1mKSl9ZnVuY3Rpb24gb2soYSl7aWYoZGlzdCh4W2FdLHlbYV0say8yLGsvMik+ay8yLXJbYV0pcmV0dXJuIDA7Zm9yKGo9MDsrK2o8YTspaWYoZGlzdCh4W2FdLHlbYV0seFtqXSx5W2pdKTxyW2FdK3Jbal0pcmV0dXJuIDA7cmV0dXJuIDF9Zm9yKGk9MDsrK2k8NDAwOyl7cltpXT0xO3NbaV09bS5yYW5kb20oKSo5KzM7ZG97eFtpXT1tLnJhbmRvbSgpKms7eVtpXT1tLnJhbmRvbSgpKmt9d2hpbGUoIW9rKGkpKTtmb3IoO29rKGkpOylyW2ldKyt9DQpvbm1vdXNlbW92ZT1mdW5jdGlvbihhKXtjLmNsZWFyUmVjdCgwLDAsayxrKTtmb3Ioaj0wOysrajxpOyl7Yy5iZWdpblBhdGgoKTtjLm1vdmVUbyh4W2pdK3Jbal0seVtqXSk7Zm9yKG89MDtvPDY7bys9Ni9zW2pdKWMubGluZVRvKHhbal0rcltqXSptLmNvcyhvKSx5W2pdK3Jbal0qbS5zaW4obykpO2MubGluZVRvKHhbal0rcltqXSx5W2pdKTtjLmZpbGxTdHlsZT1kaXN0KGEucGFnZVgsYS5wYWdlWSx4W2pdLHlbal0pPDUwPyIjYTlmZmE5IjoiI2E5YTlmZiI7Yy5maWxsKCk7Yy5zdHJva2UoKX19Ow==
- Original source
k = 350;
x = [];
y = [];
r = [];
s = [];
m = Math;
d = document.getElementById("c");
c = d.getContext("2d");
d.width = k;
d.height = k;
function dist(x1, y1, x2, y2) {
return m.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
}
function ok(i) {
if (dist(x[i], y[i], k/2, k/2) > k/2-r[i]) return 0;
for (j = 0; ++j < i;) if (dist(x[i], y[i], x[j], y[j]) < r[i]+r[j]) return 0;
return 1
}
for (i = 0; ++i < 400;) {
r[i] = 1;
s[i] = m.random()*9+3;
do {
x[i] = m.random()*k;
y[i] = m.random()*k;
} while (!ok(i));
while (ok(i)) r[i]++;
}
onmousemove = function(e) {
c.clearRect(0,0,k,k);
for (j = 0; ++j < i;) {
c.beginPath();
c.moveTo(x[j]+r[j], y[j]);
for (o = 0; o < 6; o+=6/s[j]) c.lineTo(x[j]+r[j]*m.cos(o), y[j]+r[j]*m.sin(o));
c.lineTo(x[j]+r[j], y[j]);
c.fillStyle = dist(e.pageX, e.pageY, x[j], y[j]) < 50 ? "#a9ffa9" : "#a9a9ff";
c.fill();
c.stroke();
}
}