Rope... Kinda interesting effect...

Miscellaneous Forums/Blitz Showcase/Rope... Kinda interesting effect...

I was having a play inspired by Speed Thrasher, trying to make a realistic rope effect...

However... It wasn't very realistic... but it looks really cool!

There's no timing code so you might want to slow it down a bit, it runs fine on my pc at work, but my pc at work it rubbish!

Run this and move the mouse about!

Graphics 640,480,0,2

ropeelements=50
ropelength#=100

Dim rope#(ropeelements,4)
; 1 = x
; 2 = y
; 3 = xspeed
; 4 = yspeed

ropesection# = ropelength / ropeelements

For n=1 To ropeelements
	rope(n,1)=MouseX()
	rope(n,2)=MouseY()
Next

SetBuffer BackBuffer()

Repeat

Cls

x=MouseX()
y=MouseY()

For n=1 To ropeelements

	; get location of previous point (mouse pointer if first point)
	If n=1
		x1#=x-rope(n,1)
		y1#=y-rope(n,2)
	Else

		x1#=rope(n-1,1)-rope(n,1)
		y1#=rope(n-1,2)-rope(n,2)
	EndIf	

	; accelerate based on distance and direction of previous section
	dis# = Sqr((x1*x1)+(y1*y1))
	rope(n,3) = rope(n,3) + (x1/2)
	rope(n,4) = rope(n,4) + (y1/2)

	; Dampen	
	rope(n,3) = rope(n,3) *.5
	rope(n,4) = rope(n,4) *.5

	; Move the point	
	rope(n,1)=rope(n,1) + rope(n,3)
	rope(n,2)=rope(n,2) + rope(n,4)

	If n>1 Then Line rope(n-1,1),rope(n-1,2),rope(n,1),rope(n,2)
Next


Flip

Until KeyHit(1)


thats...pretty neat!!!

It's in someway ipnotic...

Nice one.

Updated...

Graphics 640,480,0,2

ropeelements=10
ropelength#=100

Dim rope#(ropeelements,4)
; 1 = x
; 2 = y
; 3 = xspeed
; 4 = yspeed

ropesection# = ropelength / ropeelements

For n#=1 To ropeelements
	rope(n,1)=MouseX()
	rope(n,2)=MouseY()
Next

SetBuffer BackBuffer()

Repeat

Cls

x=MouseX()
y=MouseY()

For n#=1 To ropeelements

	; get location of previous point (mouse pointer if first point)
	If n=1
		x1#=x-rope(n,1)
		y1#=y-rope(n,2)
	Else

		x1#=rope(n-1,1)-rope(n,1)
		y1#=rope(n-1,2)-rope(n,2)
	EndIf	

	; accelerate based on distance and direction of previous section
	dis# = Sqr((x1*x1)+(y1*y1))
	If dis>ropesection
		dd#=dis-ropesection
		x1=(x1/dis) * dd
		y1=(y1/dis) * dd
		rope(n,3) = rope(n,3) + (x1)
		rope(n,4) = rope(n,4) + (y1)
	EndIf

	; Dampen	
	rope(n,3) = rope(n,3) * .4
	rope(n,4) = rope(n,4) * .4

	; Move the point	
	rope(n,1)=rope(n,1) + rope(n,3)
	rope(n,2)=rope(n,2) + rope(n,4)

	If n>1 Then Line rope(n-1,1),rope(n-1,2),rope(n,1),rope(n,2)
Next


Flip

Until KeyHit(1)


why does it change length like elastic?

Because I made a made a mistake, but it was an interesting misake so I posted it... hence me saying "It wasn't very realistic... but it looks really cool!".

oh... well... keep up the good work,
have you managed to get collision working with it?

I find the old version nicer...

Slenker, I have no idea what you're talking about... what collision? Collision with what? Are you on drugs?

This is a cool bit of code. Nice one. I prefer the first one. Its weirdly addictive.

Cool :)

First one far best !

if you got it to collide with an image (imagesoverlap) you could create an S&M game with the 'rope' as a whip

The first routine is tremendous ! Try making very small fast circles in the centre of the screen - you'll get very sick very fast !

awesome

you can make a screensaver with this:

choice = Rnd(100)
If choice > 90 Then
x=Rnd(640)
y=Rnd(480)
End If


pretty nifty effect there.

Cool stuff.

Here it is all screensaverfied-ish like. (English is great aint it?)

Getcommand$=CommandLine$()

If Instr(Upper$(Getcommand$),"/P")>0 Then
	End
End If


If Instr(Upper$(Getcommand$),"/C")>0 Then
	Print "Options Screen"
	Print "No Options To set - Hit a Key to exit."
	WaitKey()
	End 
End If

FlushKeys()
FlushMouse()
Const scrw = 1024
Const scrh = 768

Graphics scrw,scrh,0,0

ropeelements=50
ropelength#=100
x# = scrw/2
y# = scrh/2
xdir# = 0.1
ydir# = 0.1
xac# = 0.001
yac# = 0.001
tic = 0
maxtic = 100
r# = 0
g# = 0
b# = 0

Dim rope#(ropeelements,4)
; 1 = x
; 2 = y
; 3 = xspeed
; 4 = yspeed

ropesection# = ropelength / ropeelements

For n=1 To ropeelements
	rope(n,1)=scrw/2;MouseX()
	rope(n,2)=scrh/2;MouseY()
Next

SeedRnd(MilliSecs())

SetBuffer BackBuffer()

Repeat

Cls

;x=MouseX()
;y=MouseY()
tic  = tic + 1
If tic > maxtic
	xac = Rnd(-0.1,0.1)
	yac = Rnd(-0.1,0.1)
	tic = 0
	maxtic = Rand(6,60)
	If maxtic > 45
		Select kol
			Case 0
				r = 255*8
			Case 1
				g = 255*8
			Case 2
				b = 255*8
			Case 3
				g = 255*8
				r = 255*8
			Case 4
				r = 255*8
				b = 255*8
			Case 5
				g = 255*8
				b = 255*8
			Case 6
				r = 255*8
				g = 255*8
				b = 255*8
		End Select
		kol = Rand(0,6)		
	EndIf
EndIf
xdir = xdir + xac
ydir = ydir + yac
If Abs(xdir) > 10 Then xdir = Sgn(xdir)*10
If Abs(ydir) > 10 Then ydir = Sgn(ydir)*10

x = x + xdir
y = y + ydir
If x > scrw-1 Then x = scrw-1:xdir = -xdir
If x < 0 Then x  = 0:xdir = -xdir
If y > scrh-1 Then y = scrh-1:ydir = -ydir
If y < 0 Then y = 0:ydir = -ydir


For n=1 To ropeelements

	; get location of previous point (mouse pointer if first point)
	If n=1
		x1#=x-rope(n,1)
		y1#=y-rope(n,2)
	Else

		x1#=rope(n-1,1)-rope(n,1)
		y1#=rope(n-1,2)-rope(n,2)
	EndIf	

	; accelerate based on distance and direction of previous section
	dis# = Sqr((x1*x1)+(y1*y1))
	rope(n,3) = rope(n,3) + (x1/2)
	rope(n,4) = rope(n,4) + (y1/2)

	; Dampen	
	rope(n,3) = rope(n,3) *.5
	rope(n,4) = rope(n,4) *.5

	; Move the point	
	rope(n,1)=rope(n,1) + rope(n,3)
	rope(n,2)=rope(n,2) + rope(n,4)

	Select kol
		Case 0
			If g > 0 Then g = g - 1
			If b > 0 Then b = b - 1			
			Color 255-3*n,g Shr 3,b Shr 3 
		Case 1
			If r > 0 Then r = r - 1
			If b > 0 Then b = b - 1			
			Color r Shr 3,255-3*n,b Shr 3 
		Case 2
			If g > 0 Then g = g - 1
			If r > 0 Then r = r - 1					
			Color r Shr 3,g Shr 3,255-3*n
		Case 3
			If b > 0 Then b = b - 1					
			Color 255-3*n,255-3*n,b Shr 3
		Case 4
			If g > 0 Then g = g - 1
			Color 255-3*n,g Shr 3,255-3*n
		Case 5
			If r > 0 Then r = r - 1
			Color r Shr 3,255-3*n,255-3*n
		Case 6
			Color 255-3*n,255-3*n,255-3*n
	End Select
	
	If n>1 Then Line rope(n-1,1),rope(n-1,2),rope(n,1),rope(n,2)
Next


Flip False
VWait 
Delay 16

	If GetKey()<>0 Then End

	If MouseXSpeed()<>0 Then End

	If MouseYSpeed()<>0 Then End

Until KeyHit(1)

End


that's officially my new screensaver here at work. :)

Updated screensaver version.

More wavey goodness!

Getcommand$=CommandLine$()

If Instr(Upper$(Getcommand$),"/P")>0 Then
	End
End If

If Instr(Upper$(Getcommand$),"/C")>0 Then
	Print "Options Screen"
	Print "No Options To set - Hit a Key to exit."
	WaitKey()
	End 
End If

FlushKeys()
FlushMouse()


Const scrw = 1024
Const scrh = 768

SeedRnd(MilliSecs())
ropeelements=40 ;50
MAXROPES=16

Dim x#(32)
Dim y#(32)
Dim xdir#(32)
Dim ydir#(32)
Dim xac#(32)
Dim yac#(32)
Dim tic(32)
Dim maxtic(32)
Dim r#(32)
Dim g#(32)
Dim b#(32)
Dim kol(32)
Dim act(32)
Dim rope#(32,ropeelements,4)  ; 1 = x, 2 = y, 3 = xspeed, 4 = yspeed

For m = 0 To 31
	x#(m) = scrw/2
	y#(m) = scrh/2
	act(m) = -1
	xdir#(m) = Rnd(-2,2)
	ydir#(m) = Rnd(-2,2)
	xac(m) = Rnd(-0.15,0.15)
	yac(m) = Rnd(-0.15,0.15)
	tic(m) = 0
	maxtic(m) = Rand(30,100)
	r#(m) = 255
	g#(m) = 255
	b#(m) = 255
	kol(m) = Rnd(7)
	For n=1 To ropeelements
		rope(m,n,1)=scrw/2
		rope(m,n,2)=scrh/2
	Next
Next 



Graphics scrw,scrh,0,0
SetBuffer BackBuffer()

Repeat
	
	Cls
	ticm = ticm + 1
	If ticm > 80
		rp = Rand(1,MAXROPES)
		act(rp) = -act(rp)
		ticm = Rand(0,60)
	EndIf
	
	For m = 0 To MAXROPES
		
		tic(m)  = tic(m) + 1
		If tic(m) > maxtic(m)
			xac(m) = Rnd(-0.15,0.15)
			yac(m) = Rnd(-0.15,0.15)
			tic(m) = 0
			maxtic(m) = Rand(6,40)   ;6,60
			If maxtic(m) > 30  ; 45
				Select kol(m)
					Case 0
						r(m) = 255*8
					Case 1
						g(m) = 255*8
					Case 2
						b(m) = 255*8
					Case 3
						g(m) = 255*8
						r(m) = 255*8
					Case 4
						r(m) = 255*8
						b(m) = 255*8
					Case 5
						g(m) = 255*8
						b(m) = 255*8
					Case 6
						r(m) = 255*8
						g(m) = 255*8
						b(m) = 255*8
				End Select
				kol(m) = Rand(0,5)		
			EndIf
		EndIf
		If act(m) > 0
			xdir(m) = xdir(m) + xac(m)
			ydir(m) = ydir(m) + yac(m)
		Else
			xdir(m) = xdir(m)*.99
			ydir(m) = ydir(m)*.99
		EndIf 
		If Abs(xdir(m)) > 10 Then xdir(m) = Sgn(xdir(m))*10
		If Abs(ydir(m)) > 10 Then ydir(m) = Sgn(ydir(m))*10
		
		x(m) = x(m) + xdir(m)
		y(m) = y(m) + ydir(m)
		If x(m) > scrw-1 Then x(m) = scrw-1:xdir(m) = -xdir(m)
		If x(m) < 0 Then x(m)  = 0:xdir(m) = -xdir(m)
		If y(m) > scrh-1 Then y(m) = scrh-1:ydir(m) = -ydir(m)
		If y(m) < 0 Then y(m) = 0:ydir(m) = -ydir(m)
		
		
		For n=1 To ropeelements
		
			; get location of previous point (mouse pointer if first point)
			If n=1
				x1#=x(m)-rope(m,n,1)
				y1#=y(m)-rope(m,n,2)
			Else
				x1#=rope(m,n-1,1)-rope(m,n,1)
				y1#=rope(m,n-1,2)-rope(m,n,2)
			EndIf	
		
			; accelerate based on distance and direction of previous section
			dis# = Sqr((x1*x1)+(y1*y1))
			rope(m,n,3) = rope(m,n,3) + (x1/2)
			rope(m,n,4) = rope(m,n,4) + (y1/2)
		
			; Dampen	
			rope(m,n,3) = rope(m,n,3) *.5
			rope(m,n,4) = rope(m,n,4) *.5
		
			; Move the point	
			rope(m,n,1)=rope(m,n,1) + rope(m,n,3)
			rope(m,n,2)=rope(m,n,2) + rope(m,n,4)
		
			Select kol(m)
				Case 0
					If g(m) > 0 Then g(m) = g(m) - 1
					If b(m) > 0 Then b(m) = b(m) - 1			
					Color 255-3*n,g(m) Shr 3,b(m) Shr 3 
				Case 1
					If r(m) > 0 Then r(m) = r(m) - 1
					If b(m) > 0 Then b(m) = b(m) - 1			
					Color r(m) Shr 3,255-3*n,b(m) Shr 3 
				Case 2
					If g(m) > 0 Then g(m) = g(m) - 1
					If r(m) > 0 Then r(m) = r(m) - 1					
					Color r(m) Shr 3,g(m) Shr 3,255-3*n
				Case 3
					If b(m) > 0 Then b(m) = b(m) - 1					
					Color 255-3*n,255-3*n,b(m) Shr 3
				Case 4
					If g(m) > 0 Then g(m) = g(m) - 1
					Color 255-3*n,g(m) Shr 3,255-3*n
				Case 5
					If r(m) > 0 Then r(m) = r(m) - 1
					Color r(m) Shr 3,255-3*n,255-3*n
				Case 6
					Color 255-3*n,255-3*n,255-3*n
			End Select
			
			If n>1 Then Line rope(m,n-1,1),rope(m,n-1,2),rope(m,n,1),rope(m,n,2)
		Next
	Next
	
	Flip False
	VWait 
	Delay 10
	
	If GetKey()<>0 Then End
	If MouseXSpeed()<>0 Then End
	If MouseYSpeed()<>0 Then End

Forever

End



*** Red Warrior is about to die! ***

ok fine.. THAT'S officially my new screensaver here at work. :)

*** You can't catch me! ***

*** Blue wizard needs food Bad! ***

Those are great Rob, the second one could be the basis for a wet-towel whipping simulator.

*** Green elf shot the food ***

really cool. turn this into a game

***Is there a green wizard yet?***

*** Red Warrior is it! ***

*** Yellow Enay needs cheese bad ***

***Green wizard kills everyone and this stupid game ends***

really cool demo and strangely addictive.
would make a good game whee you have to 'whip' litle alien monsters