// balls and springs dag:{[n;m]_dv'[_draw[n;m]_draw'-n;!n]} / graph: n balls, m connections ngon:{[n]pi:2*_asin 1;i:!n;k:i*(2*pi)%n;(_cos k;_sin k)} / polygon connect:{[g;d]stretch lines[g;d],balls g} / draw balls and lines stretch:{[g]g,(2#,,:)'3 -1} / stretch balls:{[g]-1!,/(7 2#,!0){x,,y}/:(+g)+\:ball[]} / red balls ball:{1+Size+Size*{(1+#x)#x}'ngon Sides} / ball lines:{[g;d],/(7 2#,!0){x,,y}/:+:',/1+Size+d{x[z]{(x;y)}/:x y}[+g]'!#d} / black lines matrix:{[d]c*~n=\:/:n:!#c:{x|+x}(!#d)_lin/:(),/:d} / connection matrix / spring model spring:{[c;h;x;y] a:1-%l:c*ln[x;y] X:x+h*gr[c;a;x] Y:y+h*gr[c;a;y] :[eq[c*ln[X;Y]]S 1;Balls::]} / next state .t..t:"if[.k.Auto;.k.next[]]" / timer / GUI Sides:10 Size:.01 Balls:20 Springs:5 Force:1 Force..u:Springs..u:Balls..u:Size..u:Sides..u:{:[y>0;y;x]} Zero:1.e-9 Zero..f:$: D..d:"dag[Balls;Springs]" N..d:"ngon Balls" S..d:"spring[matrix D;Force]. N" Next:"next[]" Next..c:`button Auto:0 Auto..c:`check M..d:"connect[N;D]" M..c:`plot M..l:` .k..a:(`Sides`Size`Balls`Springs`Force;`M;`Zero`Auto`Next) .k..l:"Balls and Springs" `show$`.k; \t .001