- Author:
- Alex Epifano
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/434
- Shortlink:
- https://js1k.com/434
- Blog post:
- please update here!
- Bytes:
- 1005
- Chars:
- 1005
- Submission
a="d#ocumt;c#.getElemtById('c'Ub=c.getContext('2d'Uf=10;c.wid=g=c.height=j=500;k=[Ml=[Mq=hH;r=o=1;D_5V<fV++,y_8Qz=[MDiH,_5J<fJ++,x_8Qz]={x:x,y:y:1,k:x,j:y}h>0Qpush([h,h])}(i>0?push([h,h]):0)@k[0][0]S=k[0][9]SH;nAclearRect(0,0,g,jUKffp=z]pwi(pQnx*1~-k*~;ny*1~-j*~+(_0125*rUk=x;j=y;nx;ny@@K2lga=lMs01t23dtW-sW`tZ-sZ`e#x+dy`i=(de-_064)/((de+_064)*(sS+tS))ssW+#i;sZ+#i}i&ttWNi;tZNi@}Olga=lMbeginPa(Us01t23!To(sW*g,sZ*jUlineTo(tW*g,tZ*jUstro()@;setInterval(n,35UFdownAw=f;Kffp=zMdxLX/g-pW`yLY/j-pZ;nw#x+dynw<wQw=nw=p@}F!AqW=q.kLX/gZ=q.jLY/jSH};FupAF!=nullS=o};}`.onydownAi&e.yCode==71Qr=(r=H)?1:0}oH}`.onyupAo=1}";for(b in c="VGO;qkeyNxN]MJG-1l.J&x=+=y=en!moveS!HQb.,i[ithKDhHV<]]K=kK~.99`;d@}}&f(#=d_.0zk[h]Z.yW.xV;hU);S.iQ){ODiHJ<N*dM];L=e.pageK[a[J;iH=0G++){Fd.onmouseDfor(A=function(e){".split(""))a=a.replace(RegExp(c[b][0],"g"),c[b].slice(1));eval(a)
- Description
- A 3d cloth simulation. Interact with it! Drag it! Fun!
Controls:
Drag: mouse
Gravity (toggle): g
Pin (hold point in place): press and hold any character (other than g), select a point with the mouse, manipulate point, release point, release key;
See http://www.andrew-hoyer.com/experiments/cloth
- Base64 encoded
YT0iZC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dXUsfAT1rSx9+Ljk5H2A7ZB9AfX0fJmYoHyM9ZB9fLjAfemtbaF0fWi55H1cueB9WO2gfVSk7H1MuaR9RKXsfT0RpSEo8H04qZB9NXTsfTD1lLnBhZ2UfS1thWx9KO2kfSD0wH0crKyl7H0ZkLm9ubW91c2UfRGZvcigfQT1mdW5jdGlvbihlKXsiLnNwbGl0KCIfIikpYT1hLnJlcGxhY2UoUmVnRXhwKGNbYl1bMF0sImciKSxjW2JdLnNsaWNlKDEpKTtldmFsKGEp
- Original source
http://www.andrew-hoyer.com/experiments/cloth
d = document;
c = d.getElementById('c');
b = c.getContext('2d');
f = 10; //number of k (sq_rt)
c.width = g = window.innerWidth - 25;
c.height = j = window.innerHeight - 25;
k=[]; //double array [y][x]
l=[];
q=0;
r=.00125;
o=1;
for(h=0, y=.05;h<f;h++,y+=.08) {
k[h]=[];
for(i=0,x=.05;i<f;i++, x+=.08) {
k[h][i]={x:x,y:y,i:1,k:x,j:y};
if(h>0){
l.push([h-1,i,h,i]);
}
//add a new horizontal l
if(i>0){
l.push([h,i-1,h,i]);
}
}
}
k[0][0].i=0;
k[0][9].i=0;
function n() {
b.clearRect(0, 0, g, j);
for(h=0;h<f;h++) {
for(i=0;i<f;i++) {
p=k[h][i];
if(p.i!=0){
nx=p.x*2-p.k;
ny=p.y*2-p.j+r;
p.k=p.x;
p.j=p.y;
p.x=nx;
p.y=ny;
}
//k[h][i]=p;
}
}
for(h=0;h<2;h++) { //17
for(i=0;i<l.length;i++) {
a=l[i];
s=k[a[0]][a[1]];
t=k[a[2]][a[3]];
dx=t.x-s.x;
dy=t.y-s.y;
de=dx*dx+dy*dy;
di=(de-.0064)/((.0064+de)*(s.i+t.i));
if(s.i!=0) {
s.x+=dx*di;
s.y+=dy*di;
}
if(t.i!=0) {
t.x-=dx*di;
t.y-=dy*di;
}
}
}
for(i=0;i<l.length;i++) {
a=l[i];
b.beginPath();
// b.strokeStyle = "#000";
s=k[a[0]][a[1]];
t=k[a[2]][a[3]];
b.moveTo(s.x*g,s.y*j);
b.lineTo(t.x*g,t.y*j);
b.stroke();
}
}
//r();
setInterval(n, 35)
z="onmouse";
v=z+"move";
d[z+"down"] = function(e) {
w=f;
for(h=0;h<f;h++) {
for(i=0;i<f;i++) {
p=k[h][i];
dx=e.pageX/g-p.x;
dy=e.pageY/j-p.y;
nw=dx*dx+dy*dy;
if(nw<w) {
w=nw;
q=p;
}
}
}
d[v]=function(e) {
q.x=q.k=e.pageX/g;
q.y=q.j=e.pageY/j;
q.i=0;
}
d[z+"up"]=function(){
d[v]=null;
q.i=o;
}
}
d.onkeydown=function(e) {
if(e.keyCode==71) {
r=(r==0)?.00125:0;
}
o=0;
};
d.onkeyup=function() {
o=1;
}