- Author:
- Daniel
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- rappdaniel.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/207
- Shortlink:
- https://js1k.com/207
- Blog post:
- please update here!
- Bytes:
- 988
- Chars:
- 988
- Submission
d=document.getElementById("c");k=350;d.width=k;d.height=k;c=d.getContext("2d");function ra(a,e){return Math.random()*(e-a)+a}function n(a,e,f,g){return Math.sqrt((a-f)*(a-f)+(e-g)*(e-g))}function p(a,e,f,g,h){u=Math.atan2(e,a);v=a+f*Math.cos(u);b=e+f*Math.sin(u);c.beginPath();c.moveTo(v,b);for(o=u;o<6+u;o+=6/g)c.lineTo(a+f*Math.cos(o),e+f*Math.sin(o));c.lineTo(v,b);c.fillStyle=h?"#a9ffa9":"#a9a9ff";c.closePath();c.fill();c.stroke()}
function ok(a,e,f,g){for(j=1;j<a;j++)if(n(e[a],f[a],e[j],f[j])<g[a]+g[j])return false;if(n(e[a],f[a],175,175)+g[a]>g[0])return false;return true}x=[];y=[];r=[];s=[];x[0]=175;y[0]=175;r[0]=175;s[0]=1;mR=43;mT=500;t=0;for(i=1;t<mT;i++){r[i]=2;s[i]=ra(5,10);for(t=0;t<mT;t++){x[i]=ra(2,k-r[i]);y[i]=ra(2,k-r[i]);if(ok(i,x,y,r))break}if(t>=mT)break;do if(ok(i,x,y,r,1))r[i]++;else break;while(r[i]<=mR);p(x[i],y[i],r[i],s[i])}
document.onmousemove=function(a){c.clearRect(0,0,k,k);for(j=1;j<i;j++)p(x[j],y[j],r[j],s[j],n(a.pageX,a.pageY,x[j],y[j])<70)};
- Description
- Polygon Packer
- Base64 encoded
ZD1kb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiYyIpO2s9MzUwO2Qud2lkdGg9aztkLmhlaWdodD1rO2M9ZC5nZXRDb250ZXh0KCIyZCIpO2Z1bmN0aW9uIHJhKGEsZSl7cmV0dXJuIE1hdGgucmFuZG9tKC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orKylwKHhbal0seVtqXSxyW2pdLHNbal0sbihhLnBhZ2VYLGEucGFnZVkseFtqXSx5W2pdKTw3MCl9Ow==
- Original source
d = document.getElementById("c");
k = 350;
d.width = k;
d.height = k;
c = d.getContext("2d");
function ra(g, h) {
return Math.random()*(h-g)+g;
}
function n(v, b, l, k) {
return Math.sqrt((v-l)*(v-l)+(b-k)*(b-k));
}
function p(x, y, r, s, f) {
u = Math.atan2(y, x);
v = x+r*Math.cos(u);
b = y+r*Math.sin(u);
c.beginPath();
c.moveTo(v, b);
for (o = u; o < 6+u; o+=6/s) c.lineTo(x+r*Math.cos(o), y+r*Math.sin(o));
c.lineTo(v, b);
c.fillStyle = f ? "#a9ffa9" : "#a9a9ff";
c.closePath();
c.fill();
c.stroke();
}
function ok(i, x, y, r) {
for (j = 1; j < i; j++) if (n(x[i], y[i], x[j], y[j]) < r[i]+r[j]) return false;
if (n(x[i], y[i], 175, 175)+r[i] > r[0]) return false;
return true;
}
x = [];
y = [];
r = [];
s = [];
x[0] = 175;
y[0] = 175;
r[0] = 175;
s[0] = 1;
mR = 43;
mT = 500;
t = 0;
for (i = 1; t < mT; i++) {
r[i] = 2;
s[i] = ra(5, 10);
for (t = 0; t < mT; t++) {
x[i] = ra(2, k-r[i]);
y[i] = ra(2, k-r[i]);
if (ok(i, x, y, r)) break;
}
if (t >= mT) break;
do {
if (ok(i, x, y, r, 1)) r[i]++;
else break;
} while (r[i] <= mR);
p(x[i], y[i], r[i], s[i]);
}
document.onmousemove = function(e) {
c.clearRect(0, 0, k, k);
for (j = 1; j < i; j++) p(x[j], y[j], r[j], s[j], n(e.pageX, e.pageY, x[j], y[j]) < 70);
}