Applying a Classic Sine wave effect to an image

Started by kevin, July 02, 2004, 08:18:23 AM

Previous topic - Next topic

kevin


PlayBASIC Code: [Select]
;---------------------------------------------------------------------; Sine Wave Image..;---------------------------------------------------------------------

OpenScreen 640,480,16,2

W=GetScreenWidth()
H=GetScreenHeight()

Global TempStripImage=2
CreateImage 1,w,h
CreateImage TempStripImage,w,1

CreateConvexShape 1,100,5

Do
RenderToImage 1 ; Cls 0

bw=32
bh=32
Ypos=ScrollY
Ypos2=Ypos+bh
For ylp=0 To h Step bh
Xpos=ScrollX
Xpos2=Xpos+bw
Toggle=Ylp And 1
For xlp=0 To w Step bw
If Toggle
BoxC Xpos,Ypos,Xpos2,Ypos2,RGB(255,0,0)
Else
BoxC Xpos,Ypos,Xpos2,Ypos2,RGB(155,0,255)
EndIf
toggle=1-toggle
Xpos=Xpos2
Xpos2=Xpos2+bw
Next
Ypos=Ypos2
Ypos2=Ypos2+bh
next


Angle#=WrapAngle(angle#,1)
RotateShape 1,angle#,1
Ink RGBFade($223344,70+Cos(angle)*30)
DrawShape 1,w/2,h/2,3

Ink RGBFade($223344,70+Sin(angle)*30)
DrawShape 1,w/2,h/2,1


Ink $ffffff
CenterText w/2,h/2-50,"Sine Wave Screen "+Str$(w)+"*"+Str$(h)

SineCopyImageToScreen(1,15)

Sync
Loop




Function SineCopyImageToScreen(SrcImage,wavesize#)
Static WaveAngle#
w=GetImageWidth(SrcImage)
Angle#=WaveAngle#
For Ylp=0 To GetImageHeight(srcImage)
RenderToImage SrcImage
GetImage TempStripImage,0,ylp,w,ylp+1
RenderToScreen
DrawImage TempStripIMage,SinRadius(Angle#,WaveSize#),ylp,0
INC Angle#
Next
WaveAngle#=WrapAngle(WaveAngle#,2)
EndFunction






Draco9898

VERY COOL  :blink:

I just shoved it into my game and made it move with the mouse!
:rolleyes:
Looks even cooler when you move it around and distort stuff
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

Draco9898

Looks even stranger if you make the
For Ylp=0 To GetImageHeight(srcImage)

go in Steps of 2......... :ph34r:
But I suppose thats because every other pixel is getting missed

I think I get how this works.....you capturing the screen as an image THEN your using  Static WaveAngle# and I'm not sure what the static commands does, but then you rip the image into Xwidth by 1 pixel height strips, then you paste enough of these on top of each other to get the original image back, but you've moved all the 'strips' with SinRange? and this causes the caustic effect?

ALSO: Changing the code by taking out the Static takes away all the movement and just leaves you with a  trick mirror like image and changing INC angle to DEC angle causes the effect to 'run' in the other direction...

I don't think I can think of a faster way to do this effect... :huh:


I have now also altered the code to so whatever is under or near the image 'waves' get affected as well

The only idea I have for making it faster is direct pixel access? Not sure.


Also one question: ARRAYS arn't globial by defult?  :unsure:
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

#3
The Static commands allows a variable within a function to keep it's value between calls.  Normally these variables are local and thus the values/data are destroyed each time the function call has ended.

Dim's are global by default...

However, if you Dim an Array inside a function, then it's LOCAL (only visible) to the function within which it appears..