News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Spinning Rope Effect

Started by kevin, May 18, 2005, 10:18:26 AM

Previous topic - Next topic

kevin

 Here's another cool old demo effect recreated in PlayBASIC 1.07b thanks to PlayBASIC's new gouraud strip command..  


PlayBASIC Code: [Select]
   Constant RopeEdges=5
Dim WaveRippleAngle#(3)

Type RopeVerts
X1#,X2#, rgb1,rgb2
endtype

Dim RopeSegs(Ropeedges) as Ropeverts

Do
Cls rgb(100,100,40)
Lockbuffer
DrawRope()
unlockbuffer
Sync
loop




Function DrawRope()
radius=100
ScReenHeight=GetScreenHeight()
basex=GetScreenwidth()/2

WaveAngle#= WaveRippleAngle#(1)
WaveAngle2#= WaveRippleAngle#(2)
WaveAngle3#= WaveRippleAngle#(3)

WaveRippleAngle#(1)=wrapangle(WaveAngle#,1)
WaveRippleAngle#(2)=wrapangle(WaveAngle2#,2.5)
WaveRippleAngle#(3)=wrapangle(WaveAngle3#,2.1)

r=155
g=40
b=90

EdgeAngleStep#=360.0/RopeEdges

BaseZ=500


Segments=0
static BaseAngle#
For lp=0 To RopeEdges-1
Angle#=BaseAngle#+(EdgeAngleStep#*lp)
Angle2#=Angle#+EdgeAngleStep#

X1#=Cosradius(angle#,Radius)
X2#=CosRadius(angle2#,Radius)
Z1#=basez+(Sin(angle#)*Radius)
Z2#=basez+(Sin(angle2#)*Radius)

Px1#=((X1#*500)/z1#)
Px2#=((X2#*500)/z2#)

If pX1#<pX2#
R1=(R*400)/z1#
G1=(G*400)/z1#
B1=(B*400)/z1#

R2=(R*400)/z2#
G2=(G*400)/z2#
B2=(B*400)/z2#

RopeSegs(Segments).x1=px1#
RopeSegs(Segments).x2=px2#
RopeSegs(Segments).rgb1=rgb(r1,g1,b1)
RopeSegs(Segments).rgb2=rgb(r2,g2,b2)
inc segments
EndIf
Next

dec segments

For ThisScanLine=0 To ScreenHeight-1
Xoffset=basex+(Sin(wAVEangle#)*50)
Xoffset=Xoffset+(Sin(wAVEangle2#+wAVEangle#)*80)
Xoffset=Xoffset+(Sin(wAVEangle3#)*90)

For lp=0 to Segments
GouraudStripH Xoffset+RopeSegs(lp).x1,RopeSegs(lp).rgb1,Xoffset+RopeSegs(lp).x2,RopeSegs(lp).rgb2,ThisScanline
next
waveangle#= waveangle#+0.5
waveangle2#= waveangle2#+0.25
waveangle3#= waveangle3#+0.3
Next

inc BaseAngle#
EndFunction