Sin Text Scroller

Blitz3D Forums/Blitz3D Beginners Area/Sin Text Scroller

CodeD(Posted 2004) [#1]
Neone can make a simple sin text scroller function using the text command that can be plugged into any program??

EDIT:

Here is the latest version of the DEMO code cleaned up for ya.
Global gfxBG, gfxflare
Graphics3D 640, 480,32, 1
SetBuffer BackBuffer() 
TFormFilter 1
Color 0,0,0
MilliSecs = 0
n = 0
grlx = 1
grly = 1
grly2 = 641
grlxdir = 1
grly = 1
timex = 0
speedtimex = 8
Type t_bullet
Field x,y
Field speedx,speedy
End Type
Global bullet.t_bullet
gfxBG=LoadImage("coolblue.png")
gfxface = LoadImage("interface2.png")
gfxgirl=LoadImage("amigagirl.png")
gfxflare=LoadImage("ice.png")
chnBackground=PlayMusic("z-tower.xm")
While Not KeyHit(1) 
If KeyDown(203) Then timex = timex - 1
If KeyDown(205) Then timex = timex + 1
Cls
DrawImage gfxBG, 1, 1
DrawImage gfxface, 1, 1
Text 50, 365, "NOW PLAYING"
Text 50, 365, "NOW PLAYING"
Text 30, 385, "TITLE: TOWER OF FLAMES": Text 30, 385, "TITLE: TOWER OF FLAMES"
Text 30, 405, "ARTIST: Frederic Hahn": Text 30, 405, "ARTIST: Frederic Hahn"
Text 30, 435, "UP/DOWN TO CHANGE SONG"
Text 30, 450, "LEFT/RIGHT TO CHANGE TEXT SPEED"
x=timex/10.0 
bulletchance = Rnd(0,10): If bulletchance = 5 Then bullet.t_bullet = New t_bullet: bullet\x = Rnd(0,200): bullet\y = Rnd(0,10): bullet\speedx = Rnd(1,3): bullet\speedy = Rnd(1,3)
bulletchance2 = Rnd(0,100): If bulletchance = 10 Then bullet.t_bullet = New t_bullet: bullet\x = Rnd(0,200): bullet\y = Rnd(0,10): bullet\speedx = Rnd(1,3): bullet\speedy = Rnd(1,3)
updategame()
rendergame()
If grlxdir = 1 Then grlx = grlx + 1
If grlxdir = 2 Then grlx = grlx - 1
If grlx = 100 Then grlxdir = 2
If grlx = 1 Then grlxdir = 1
SinScroll (" ................................... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", -x, 135, timex/10.0)
SinScroll (" ................................... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", -x-1, 135, timex/10.0)
DrawImage gfxgirl, grlx, grly
DrawImage gfxgirl, grlx, grly2
Flip
If timex < 0 Then timex = 0
timex = timex + speedtimex
If KeyDown(203) Then speedtimex = speedtimex - 1
If KeyDown(205) Then speedtimex = speedtimex + 1
Wend 
Function updategame()
For bullet.t_bullet = Each t_bullet
bullet\x = bullet\x + bullet\speedx
bullet\y = bullet\y + bullet\speedy
Next
End Function
Function rendergame()
For bullet.t_bullet = Each t_bullet
DrawImage gfxflare,bullet\x,bullet\y
Next
End Function
Function SinScroll(txt$,x,y,am,amp=50,per=20,d=10)
For n=1 To Len(txt$)
Text x+xx,y+Sin(am+n*per)*amp,Mid$(txt$,n,1)
xx=xx+d
Next
End Function



SoggyP(Posted 2004) [#2]
Hi Folks,

I'm in work so can't do it for you, but all you need to do is to define a lookup table holding the y-pos for each x-pos on the screen. Create a function that will take the character and the x-pos, and place the character at the x-pos and y-pos taken from the table.

Does that help?

Oh, yes, before anyone says you don't need to use a lookup table as it's just as quick to calculate it in real time and faster still to do it telepathically.

Later,

Jes


Jeppe Nielsen(Posted 2004) [#3]
Try this:
Graphics 800,600
SetBuffer BackBuffer()
Repeat
Cls
x=MilliSecs()/10.0 Mod 800
SinScroll("A nice sinus scroller, just a small example how this is done :)",800-x,300,MilliSecs()/10.0)
SinScroll("A nice sinus scroller, just a small example how this is done :)",800-x-800,300,MilliSecs()/10.0)
Flip
Until KeyDown(1)
End
Function SinScroll(txt$,x,y,am,amp=50,per=20,d=10)
For n=1 To Len(txt$)
Text x+xx,y+Sin(am+n*per)*amp,Mid$(txt$,n,1)
xx=xx+d
Next
End Function



CodeD(Posted 2004) [#4]
That's nifty!! Thanks!!


CodeD(Posted 2004) [#5]
Could you explain all those variables though in the function call? I know amp is like amplitude txt$, and x,y but not sure about the others.

Also, is there a way when it's done reading the line to loop back through it without clearing out the old line entirely??

Also, can you show how to set horizontal limits like if you want it to show the sinscroll from x:1 to x: 50 only???


wedoe(Posted 2004) [#6]
There are a sine-scroller on my website: www.blitzbasic.no
Check put the DYCP-scroller also.

They're made a long time ago but they work nice
and are very simple to understand.. (...and commented.)


CodeD(Posted 2004) [#7]
Thanks Wedoe those are pretty good.
Jeppe, still there??


CodeD(Posted 2004) [#8]
Function SinScroll(txt$,x,y,am,amp=20,per=20,d=10)
.wrap
For n=1 To Len(txt$)
If Len(txt$) = "^" Then Text x+xx,y+Sin(am+n*per)*amp, " ": Goto wrap
Text x+xx,y+Sin(am+n*per)*amp,Mid$(txt$,n,1)
xx=xx+d
Next
End Function

here is what i've done to the sin scroll function, it wraps the text but, the problem is when it gets to the end of the text, the x position moves back to the beginning i.e. the far left of the screen, so it jumps instead of actually continuing where it left off. and i probably shouldn't use a goto...


CodeD(Posted 2004) [#9]
anybody?


TomToad(Posted 2004) [#10]
So what would a holy text scroller look like?


CodeD(Posted 2004) [#11]
holy?


TomToad(Posted 2004) [#12]
Well, there is a sin text scroller, so there must be a holy text scroller. Right? Maybe something like this?

for x = 0 to 800
 y = holy(x)
  if y < 0 
   goto hell
  else
   goto heaven
  end if
next

Of course, this is only an example. Normally you would want to avoid the use of goto.


CodeD(Posted 2004) [#13]
Ooooooooh


CodeD(Posted 2004) [#14]
I figured out what my problem was. I need to recalculate the mod value according to the length of the text that's being scrolled. But, how do I calculate the mod value versus the text length??

(you can see I'm working on a slightly modified version of the bullet code posted by Semar in this forum for the ice flakes)

pic of demo in action here
demo in action

; LoadImage and DrawImage example 

; Declare a variable to hold the graphic file handle 
Global gfxBG, gfxflare
; Set a graphics mode 
Graphics3D 640, 480,32, 1
; Set drawing operations for double buffering 
SetBuffer BackBuffer() 
TFormFilter 1
Color 0,0,0
SeedRnd MilliSecs()
grlx = 1
grlxdir = 1
grly = 1
Type t_bullet
Field x,y
Field speedx,speedy
End Type
Global bullet.t_bullet
; Load the image and assign its file handle to the variable 
; - This assumes you have a graphic called player.bmp in the 
; same folder as this source code 
gfxBG=LoadImage("coolblue.png")
gfxgirl=LoadImage("amigagirl.png")
gfxflare=LoadImage("ice.png")
chnBackground=PlayMusic("z-tower.xm")
; Let's do a loop where the graphic is drawn wherever the 
; mouse is pointing. ESC will exit. 

While Not KeyHit(1) 
; clear the screen 
Cls
DrawImage gfxBG, 1, 1
x=MilliSecs()/10.0 Mod 2400
bulletchance = Rnd(0,10): If bulletchance = 5 Then bullet.t_bullet = New t_bullet: bullet\x = Rnd(0,200): bullet\y = Rnd(0,10): bullet\speedx = Rnd(1,3): bullet\speedy = Rnd(1,3)
bulletchance2 = Rnd(0,100): If bulletchance = 10 Then bullet.t_bullet = New t_bullet: bullet\x = Rnd(0,200): bullet\y = Rnd(0,10): bullet\speedx = Rnd(1,3): bullet\speedy = Rnd(1,3)
updategame()
rendergame()
;x=MilliSecs()/10.0 Mod 800
;If grlxdir = 1 Then grlx = grlx - 1
;If grlxdir = 2 Then grlx = grlx + 1
;If grlx = -639 Then grlxdir = 2
;If grlx = 1 Then grlxdir = 1
SinScroll (" ............... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", -x-2400, 300, MilliSecs()/10.0)
SinScroll (" ............... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", -x-1-2400, 300, MilliSecs()/10.0)
DrawImage gfxgirl, grlx, 1
;SinScroll (" ............... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", 800-x, 300, MilliSecs()/10.0)
;SinScroll (" ............... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", 800-x-800, 300, MilliSecs()/10.0)
Flip ; flip the image into view and clear the back buffer 
Wend 
;===================================
Function updategame()
;===================================
For bullet.t_bullet = Each t_bullet
bullet\x = bullet\x + bullet\speedx
bullet\y = bullet\y + bullet\speedy
Next
End Function
;===================================
Function rendergame()
;===================================
For bullet.t_bullet = Each t_bullet
;the bullet image is a global image called image_bullet

DrawImage gfxflare,bullet\x,bullet\y
Next
End Function
Function SinScroll(txt$,x,y,am,amp=50,per=20,d=10)
For n=1 To Len(txt$)
Text x+xx,y+Sin(am+n*per)*amp,Mid$(txt$,n,1)
xx=xx+d
Next
End Function



CodeD(Posted 2004) [#15]
Well, I know I'm doing something wrong and it has to do with the Millisecs()
So I came up with a shoddy replacement that lets you control speed and direction using the left and right arrow keys.
Not, what I wanted to do...
; LoadImage and DrawImage example 

; Declare a variable to hold the graphic file handle 
Global gfxBG, gfxflare
; Set a graphics mode 
Graphics3D 640, 480,32, 1
; Set drawing operations for double buffering 
SetBuffer BackBuffer() 
TFormFilter 1
Color 0,0,0
MilliSecs = 0
;SeedRnd MilliSecs()
n = 0
grlx = 1
grlxdir = 1
grly = 1
timex = 0
speedtimex = 8
Type t_bullet
Field x,y
Field speedx,speedy
End Type
Global bullet.t_bullet
; Load the image and assign its file handle to the variable 
; - This assumes you have a graphic called player.bmp in the 
; same folder as this source code 
gfxBG=LoadImage("coolblue.png")
gfxgirl=LoadImage("amigagirl.png")
gfxflare=LoadImage("ice.png")
chnBackground=PlayMusic("z-tower.xm")
; Let's do a loop where the graphic is drawn wherever the 
; mouse is pointing. ESC will exit. 

While Not KeyHit(1) 
If KeyDown(203) Then timex = timex - 1
If KeyDown(205) Then timex = timex + 1
; clear the screen 
Cls
DrawImage gfxBG, 1, 1
;mod value gives you amount of time to scroll before looping text
x=timex/10.0 ;Mod 800
bulletchance = Rnd(0,10): If bulletchance = 5 Then bullet.t_bullet = New t_bullet: bullet\x = Rnd(0,200): bullet\y = Rnd(0,10): bullet\speedx = Rnd(1,3): bullet\speedy = Rnd(1,3)
bulletchance2 = Rnd(0,100): If bulletchance = 10 Then bullet.t_bullet = New t_bullet: bullet\x = Rnd(0,200): bullet\y = Rnd(0,10): bullet\speedx = Rnd(1,3): bullet\speedy = Rnd(1,3)
updategame()
rendergame()
;x=MilliSecs()/10.0 Mod 800
;If grlxdir = 1 Then grlx = grlx - 1
;If grlxdir = 2 Then grlx = grlx + 1
;If grlx = -639 Then grlxdir = 2
;If grlx = 1 Then grlxdir = 1
SinScroll (" ................................... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", -x, 300, timex/10.0)
SinScroll (" ................................... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", -x-1, 300, timex/10.0)
DrawImage gfxgirl, grlx, 1
;SinScroll (" ............... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", 800-x, 300, MilliSecs()/10.0)
;SinScroll (" ............... CodeD aka (DJ) Krazy K Presents Amiga Tribute Vol. 1 ... Press up/down to change songs ... Code: CodeD, Jeppe Neilson (SinScroll) Gfx: FrogDot (thx for the babe!), CodeD ... Mods for Charity ... your donations help children!!! ... Visit http://sites.gwala.net/tormented/amiga for more info and to order the CD ... greetings to: Ckob, Lenn, Noel Cower, JFK, DJ SeeNSay, LizardKing, FutureCrew, Paradox, Mark Sibly & The Blitz Basic Crew, The Anonymous Modder ... Gotta have mod??  Amiga Tribute Vol. 2 coming soon!!  Cybernoid 3D coming soon!! Quality apps like this and more from CrapSoft and Evolved Dev Studios ............................ ", 800-x-800, 300, MilliSecs()/10.0)
Flip ; flip the image into view and clear the back buffer 
If timex < 0 Then timex = 0
timex = timex + speedtimex
If KeyDown(203) Then speedtimex = speedtimex - 1
If KeyDown(205) Then speedtimex = speedtimex + 1
Wend 
;===================================
Function updategame()
;===================================
For bullet.t_bullet = Each t_bullet
bullet\x = bullet\x + bullet\speedx
bullet\y = bullet\y + bullet\speedy
Next
End Function
;===================================
Function rendergame()
;===================================
For bullet.t_bullet = Each t_bullet
;the bullet image is a global image called image_bullet

DrawImage gfxflare,bullet\x,bullet\y
Next
End Function
Function SinScroll(txt$,x,y,am,amp=50,per=20,d=10)
For n=1 To Len(txt$)
Text x+xx,y+Sin(am+n*per)*amp,Mid$(txt$,n,1)
xx=xx+d
Next
End Function



Clyde(Posted 2004) [#16]
@Wedoe - Remember the C64 and DYCP-scrollers <Memories>
@CodeD - Looking way smart mate :)


wedoe(Posted 2004) [#17]
@Mikey F:
Take a look at this:
http://www.blitzbasic.no/div/nostalgia.zip


Clyde(Posted 2004) [#18]
@Wedoe - Remember it well buddy :)
-Top Nostalgic Work mate -
Hail to the C64 / 80's

@CodeD - Hows progress mate?


CodeD(Posted 2004) [#19]
Edit: See my first post in this thread for the latest version of the demo code (cleaned up)

Yeah, the Nostalgic demo is cool.
I'm almost done on the demo which will accompany the new album Amiga Tribute Vol. 1, here is a pic of the demo in action

Here is what it does so far:
Snowflakes fly around and continually respawn
the girl moves left and back to right about 100 pixels each way.
Mod music plays
Sin Text scroll with user controlled speed/direction

To Do:
-Let user cycle through mods to play (super easy)
-Do something with the background (like a pallete cycle or something)
-Make the snowflakes rotate, will have to prerender the rotations and store into memory and cycle through rotation frames with an x = x + 1 type algorithm/check (medium diff)

Basically, one of the things that makes a demo visually exciting is movement so, that's what I'm going for.



here is the album cover




Clyde(Posted 2004) [#20]
Feel free to visit my site matey, as we love all things retro, Amiga / C64 and Graphics Demos / Games.

That looks real tasty CodeD, Brilliant work :)
-Mikey F aka Clyde :)


CodeD(Posted 2004) [#21]
Thanks I'll give it a look!


Clyde(Posted 2004) [#22]
Cheers mate, all the best with the project!
Cool site btw :)


CodeD(Posted 2004) [#23]
Finished Final Code is here:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1172
Email me if you want the media, it's a 501kb zip file.