Sine Wave Scroller with X and Y distortions

Started by kevin, December 12, 2018, 10:10:55 AM

Previous topic - Next topic

kevin

PlayBASIC -   Code Snippet  - Sine Wave Scroller - 18th June  2006

This is classic source code example from way back in 2006.  The demo shows a simple right to left scrolling message with sine wave distortions applied.   First we start with the basic scroller, next we add sine distortion on the X axis, then the Y axis finishing off by combining them..


  VIDEO:




music by: https://bensound.com


  Code:


PlayBASIC Code: [Select]
; PROJECT : Sine_Scrollers
; AUTHOR : Kevin Picone
; CREATED : 18/06/2006
; EDITED : 18/06/2006
; ---------------------------------------------------------------------

; load the Courier New font
Loadfont "Courier New",1,32,0
MakeBitmapFont 1,$ff0000

; load the Courier New font
Loadfont "Courier New",2,64,0
MakeBitmapFont 2,$8f70a0
setfont 2

; Make a type to hold the various bits of info ab

SineWaveWidth=32
ScrollHeight=GetTextHeight("Y")


; CReate an array to hold the Scroll text in charater form
Dim ScrollText(0)
Read_Text_To_Scroller_Array(ScrollText())


; Original Scroll buffer
ScrollBuffer=NewImage(800+(SineWaveWidth*2)+GetFontWidth(2),ScrollHeight)

ScrollBuffer2=NewImage(800+(SineWaveWidth*2)+GetFontWidth(2),ScrollHeight)


setfps 60
RendertoScreen
Do
Cls 0

; Update the Scroll Buffer
setfont 2
UpdateScroller(ScrollText(),ScrollBuffer)


; select What effect render
Select Effect
case 0
; draw the scroll messagae
Drawimage ScrollBuffer,0,280,true
EffectName$="Standard Scroller"

case 1
Draw_XSine_Image(ScrollBuffer,0,280,32)
EffectName$="Scroller with sine X distortion"

case 2
Draw_YSine_Image(ScrollBuffer,0,280,270)
EffectName$="Scroller with sine Y distortion"

case 3
rendertoimage Scrollbuffer2
Draw_XSine_Image(ScrollBuffer,0,0,24)
rendertoscreen
Draw_YSine_Image(ScrollBuffer2,0,280,270)
EffectName$="Scroller with combined X&Y distortion"
endselect




if Spacekey()
Inc Effect
If effect>3 then effect=0
flushkeys
endif

Setfont 1
x=getscreenwidth()/2
y=GetScreenheight()/2+200
centertext x,y,EffectName$
centertext x,y+50,"Press Space"


Sync
loop


; ---------------------------------------------------------------------
; Copy an Image width a X sine wave applied
; ---------------------------------------------------------------------

Function Draw_XSine_Image(ThisImage,Xpos,Ypos,XwaveRAdius)
Static BaseAngle#

OutputBuffer=getsurface()

IW=GetImageWidth(ThisImage)
IH=GetImageheight(ThisImage)

For Angle#=BaseAngle# to Baseangle#+IH
X=SinRadius(Angle#,XwaveRadius)
CopyStripH ThisImage,y,0,iw,OutPutBuffer,Xpos-XwaveRAdius+X,ypos
inc Y
inc Ypos
next

BaseAngle#=wrapangle(BaseAngle#,0.5)
rendertoscreen
EndFUnction




; ---------------------------------------------------------------------
; Copy an Image with a Y sine wave applied
; ---------------------------------------------------------------------

Function Draw_YSine_Image(ThisImage,Xpos,Ypos,WaveRAdius)
Static BaseAngle#

OutputBuffer=getsurface()

IW=GetImageWidth(ThisImage)
IH=GetImageheight(ThisImage)

Angle#=baseangle#
if iw>GetImageWidth(Outputbuffer) then iw=GetImageWidth(Outputbuffer)
For x=0 to iw-1
Y=SinRadius(Angle#,waveRadius)
; to reduce the number of blits
CopyRect ThisImage,x,0,x+2,ih,OutPutBuffer,Xpos,ypos+Y
inc xpos
inc xpos
Angle#=wrapangle(Angle#,0.5)
next

BaseAngle#=wrapangle(BaseAngle#,2)
rendertoscreen
EndFUnction







; ---------------------------------------------------------------------
; Refresh Scroll Text/ Buffer
; ---------------------------------------------------------------------

Function UpdateScroller(ChrBuffer(),ScrollBuffer)
Login required to view complete source code