Author Topic: Pendulum Rope  (Read 1134 times)

0 Members and 1 Guest are viewing this topic.

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 312
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Pendulum Rope
« on: October 10, 2021 »
It's been a while. I couldn't remember my password. But I'm still coding - in Yabasic.

I've wanted to figure this out for a long time.

Code: [Select]
joint=10
dim x(joint)
dim y(joint)
dim dir(joint)
dim arm(joint)
dim s(joint)

for a=1 to joint
dir(1)=20
dir(a)=0
arm(a)=25
next a
ang=pi/180
x=320
y=260

dim go(16)
dim G(16)

open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
c=peek("port1")

if go(11)=1 then
for a=1 to joint
dir(a)=0
next a
sel=1
endif

for a=1 to 16
if and(c,2^(a-1))<>0 go(a)=1
if go(a)=1 G(a)=G(a)+1
if G(a)>2 G(a)=2
if G(a)=2 go(a)=0
if and(c,2^(a-1))=0 G(a)=0
next a

if go(8)=1 sel=sel-1
if go(6)=1 sel=sel+1
if sel<1 sel=1
if sel>joint sel=joint

for a=1 to joint
if sel=a then
if and(c,16)>0 dir(a)=dir(a)-.5
if and(c,64)>0 dir(a)=dir(a)+.5
endif
next a

dir(1)=dir(1)+m
if dir(1)<90 m=m+.05
if dir(1)>91 m=m-.05

if dir(1)<90 then
for a=2 to joint
dir(a)=dir(a)-.25
next a
endif

if dir(1)>91 then
for a=2 to joint
dir(a)=dir(a)+.25
next a
endif

for a=1 to joint
if sel=a then
setrgb 1,0,256,0
else
setrgb 1,256,256,256
endif
'text 20,a*20+100,str$(int(dir(a)))
next a

for a=1 to joint
s(a)=0
next a

d=0

for a=1 to joint
if dir(a)>359 dir(a)=0
if dir(a)<0 dir(a)=359
next a

setrgb 1,256,256,256

for a=1 to joint
d=d+dir(a)

x(a)=cos(d*ang)*arm(a)
y(a)=sin(d*ang)*arm(a)

s(1)=s(1)+x(a-1)
s(2)=s(2)+y(a-1)
s(3)=s(3)+x(a)
s(4)=s(4)+y(a)

if sel=a then
setrgb 1,0,256,0
else
setrgb 1,256,256,256
endif

line s(1)+x,s(2)+y to s(3)+x,s(4)+y
next a

until (1=0)

Most of the code can be used to manipulate each arm to create shapes.
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.