17 years!
That hit home
That hit home
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu

restore edges
read edges
dim e1(edges)
dim e2(edges)
for a=1 to edges
read e1(a)
read e2(a)
next a
' 12 vertices of an icosahedron
phi=(1+sqrt(5))/2
scale=80
dim vx(12)
dim vy(12)
dim vz(12)
' two rings plus poles
vx(1)=0
vy(1)=scale
vz(1)=0
vx(12)=0
vy(12)=-scale
vz(12)=0
for a=0 to 4
ang=a*72*pi/180
vx(a+2)=cos(ang)*scale
vy(a+2)=scale*0.4
vz(a+2)=sin(ang)*scale
next a
for a=0 to 4
ang=(a*72+36)*pi/180
vx(a+7)=cos(ang)*scale
vy(a+7)=-scale*0.4
vz(a+7)=sin(ang)*scale
next a
dim sx(12)
dim sy(12)
ax=0
ay=0
az=0
open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
' rotate and project
for a=1 to 12
x=vx(a)
y=vy(a)
z=vz(a)
' rotate X
ty=y*cos(ax)-z*sin(ax)
tz=y*sin(ax)+z*cos(ax)
y=ty
z=tz
' rotate Y
tx=x*cos(ay)+z*sin(ay)
tz=-x*sin(ay)+z*cos(ay)
x=tx
z=tz
' rotate Z
tx=x*cos(az)-y*sin(az)
ty=x*sin(az)+y*cos(az)
x=tx
y=ty
' perspective projection
dist=300
sx(a)=320+x*dist/(z+dist)
sy(a)=256-y*dist/(z+dist)
next a
' draw edges
for a=1 to edges
line sx(e1(a)),sy(e1(a)) to sx(e2(a)),sy(e2(a))
next a
ax=ax+0.01
ay=ay+0.015
az=az+0.02
until (1=0)
label edges
data 30
data 1,2
data 1,3
data 1,4
data 1,5
data 1,6
data 12,7
data 12,8
data 12,9
data 12,10
data 12,11
data 2,3
data 3,4
data 4,5
data 5,6
data 6,2
data 7,8
data 8,9
data 9,10
data 10,11
data 11,7
data 2,7
data 2,11
data 3,7
data 3,8
data 4,8
data 4,9
data 5,9
data 5,10
data 6,10
data 6,11
joint=32
dim x(joint)
dim y(joint)
dim oldx(joint)
dim oldy(joint)
length=10
gravity=.15
drag=.995
' create rope hanging down
for a=1 to joint
x(a)=320
y(a)=80+(a-1)*length
oldx(a)=x(a)
oldy(a)=y(a)
next a
' give rope a big initial swing
for a=1 to joint
x(a)=320+(a*a*.35)
oldx(a)=x(a)-20
next a
open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
' physics update
for a=2 to joint
vx=x(a)-oldx(a)
vy=y(a)-oldy(a)
oldx(a)=x(a)
oldy(a)=y(a)
x(a)=x(a)+vx*drag
y(a)=y(a)+vy*drag+gravity
next a
' solve rope lengths
for b=1 to 8
x(1)=320
y(1)=80
for a=2 to joint
dx=x(a)-x(a-1)
dy=y(a)-y(a-1)
dist=sqrt(dx*dx+dy*dy)
if dist>0 then
diff=(dist-length)/dist
if a<>2 then
x(a-1)=x(a-1)+dx*diff*.5
y(a-1)=y(a-1)+dy*diff*.5
endif
x(a)=x(a)-dx*diff*.5
y(a)=y(a)-dy*diff*.5
endif
next a
next b
' redraw rope
setrgb 1,255,255,255
for a=1 to joint-1
line x(a),y(a) to x(a+1),y(a+1)
next a
until 1=0


Page created in 1.810 seconds with 15 queries.