• Welcome to Dark Bit Factory & Gravity.
 

Pendulum Rope

Started by bikemadness, June 20, 2026

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

bikemadness

This shows a preset segmented line controlled by repeating math.


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.

Shockwave

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;


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:

bikemadness

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.

Shockwave

One of the things I have always loved about programming is the journey it takes you on sometimes.
Shockwave ^ Codigos
Challenge Trophies Won:

bikemadness

Shockwave. I've played with your program to understand it.
Create initial start and mid swings using page-up or page-down.


joint=32

dim x(joint)
dim y(joint)
dim oldx(joint)
dim oldy(joint)

length=10

gravity=.1
drag=.9

' 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

dim go(16)
dim g(16)

open window 640,512

repeat

setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
c=peek("port1")

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

g=ran(1)

if go(4)=1 x(32)=600
if go(4)=1 y(32)=80

if go(1)=1 then
for a=1 to joint
x(a)=320+(a*a*g)
oldx(a)=x(a)-20
next a
endif

' 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)

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