Author Topic: Pendulum Rope  (Read 372 times)

0 Members and 2 Guests are viewing this topic.

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 323
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Pendulum Rope
« on: June 20, 2026 »
This shows a preset segmented line controlled by repeating math.

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

for a=1 to joint
dir(a)=0
arm(a)=15
next a

dir(1)=20
ang=pi/180
x=320
y=100

open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window

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

for a=2 to joint
if dir(1)<90 dir(a)=dir(a)-.12
if dir(1)>90 dir(a)=dir(a)+.12
next a

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

d=0

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)

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

until (1=0)

Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17423
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: Pendulum Rope
« Reply #1 on: July 30, 2026 »
I love this, it reminds me of Manic Miner, some of the rooms have swinging ropes you can grab onto.

I've always meant to see if I could make something like this so I hope you don't mind but I faffed around in the emulator and made each joint an actual point in space and takes gravity and velocity so that a wave can travel through the rope rather than have it follow a defined path;

Code: [Select]
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
Shockwave ^ Codigos
Challenge Trophies Won:

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 323
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Re: Pendulum Rope
« Reply #2 on: Today at 06:21 PM »
I don't mind in the least.
All I could do was put individual controls of line length and angle for each segment.
And what i showcased here.
Not in my wildest dreams before this.
And thankyou.
Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.