Out of boredom I made a few rope-functions, bankbased, but no user should be bothered with that.. (I think) it's also based on those circles btw..
The example app says it all .. The rope-swing could be a bit better.. the upper-part of the ropes ain't swinging at all. Ahwell, someone who wants to improve it, within the current structure? :)
app=CreateWindow("rope - CS_TBL",0,0,640,480)
canvas=CreateCanvas(0,0,640,480,app)
timer=CreateTimer(25)
; make a bunch o' ropes ... schoolgym-trauma :( *sigh*
Dim MyRope(15)
For t=0 To 15
MyRope(t)=CreateRope(48,3,128-Rnd(80),4+Rnd(8)) ; CreateRope(segments, segmentlength, swingamplitude, swingspeed)
Next
Repeat
WaitEvent()
If EventID()=$4001
SetBuffer CanvasBuffer(canvas)
Cls
For ropes=0 To 15 ; all ropes
UpdateRope(MyRope(ropes)) ; update the phases
; readout the x/y coords for each segment, for each rope
For t=0 To RopeMaxsegments(MyRope(ropes))-1
x=RopeX(t,MyRope(ropes))
y=RopeY(t,MyRope(ropes))
Plot 64+(ropes*32)+x,128+y
Next
Next
FlipCanvas canvas
EndIf
If EventID()=$803 quit=True
Until quit
End
Function CreateRope(segments,segmentlength,swing,speed)
bank=CreateBank(1+1+1+1 + 2) ; functionarguments + 1 (swingphase)
If speed>360 speed=360
PokeByte bank,0,segments
PokeByte bank,1,segmentlength
PokeByte bank,2,swing
PokeByte bank,3,speed
PokeShort bank,4,0
Return bank
End Function
Function UpdateRope(bank)
If Not bank End
speed=PeekByte(bank,3)
phase=PeekShort(bank,4)
phase=(phase+speed) Mod 360
PokeShort bank,4,phase
End Function
Function RopeX(segment,bank)
If Not bank End
maxsegments=PeekByte(bank,0)
If segment>=maxsegments End
phase=PeekShort(bank,4)
swing=PeekByte(bank,2)
segmentlength=PeekByte(bank,1)
angle=Sin(phase)*swing*segment/128
angle=angle*segment/maxsegments
x=Sin(angle)*segment*segmentlength
Return x
End Function
Function RopeY(segment,bank)
If Not bank End
maxsegments=PeekByte(bank,0)
If segment>=maxsegments End
phase=PeekShort(bank,4)
swing=PeekByte(bank,2)
segmentlength=PeekByte(bank,1)
angle=Sin(phase)*swing*segment/128
angle=angle*segment/maxsegments
y=Cos(angle)*segment*segmentlength
Return y
End Function
Function RopeMaxsegments(bank)
If Not bank End
Return PeekByte(bank,0)
End Function