Author Topic: Bitmap Sin Scroller.  (Read 3415 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17374
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Bitmap Sin Scroller.
« on: February 28, 2007 »
This needs the font in the archive attached to this post, there is also an exe in the archive for those without PB :)

This is an example of how to make a bitmap sine scroll using Purebasic.

Code: [Select]
; Sine Scroll Coded By Nick Simpson 2005.
;
;
;============================================================================================


Global  xres.w , yres.w , loop.w ,xp.w , yp.w , t$.s , tptr.w , sco.b
xres  = 800
yres  = 600
sco=0
tptr=1
t$="                                    "
t$=t$+"HELLO.. THIS IS MY FIRST ATTEMPT AT A DEMO WRITTEN IN PUREBASIC, THE LANGUAGE SEEMS TO BE A LITTLE BIT TRICKY "
t$=t$+"BUT IN FAIRNESS IT'S LEARNABLE AT LEAST AND IT SEEMS TO BE QUITE FAST SO I'LL PUT UP WITH IT... "
t$=t$+"NOW TO ADD SOME STARS, A LOGO AND SOME MUSIC AND THEN IT WILL BE FINISHED... HAPPY 2006.. NICK."
t$=t$+"                                 "

Dim gfxfont(60)


InitSprite()
UsePNGImageDecoder()
window  = OpenScreen( xres , yres , 32 , "PBWINDOW")

font=LoadImage (#PB_Any,"font.PNG")

InitKeyboard()

  StartDrawing (ScreenOutput())
                              DrawImage (UseImage(font),0,0)
StopDrawing() 

xp=0
yp=0
For loop=1 To 60
 
  gfxfont(loop)=GrabImage(font,#PB_Any,xp,yp,31,31) 
 
    xp=xp+32

    If xp>=320
      yp=yp+33
      xp=0
    EndIf
 
Next




Repeat
StartDrawing (ScreenOutput())
  ;DrawImage (UseImage(font),0,0)
cco=0
For cc=0 To 25
letter=(Asc(Mid(t$,tptr+cc,1))-31)
DrawImage(UseImage(gfxfont(letter)),(sco+cco),300+50*Sin((cc+cco+sco+m)/120)) 
cco=cco+32
Next
m=m-5
  sco=sco-3
  If sco<-32
  tptr=tptr+1
  sco=sco+32
  EndIf
  If tptr>(Len(t$)-30 )
  tptr=1
  EndIf
  StopDrawing()
ExamineKeyboard()
FlipBuffers()
ClearScreen(0,0,0)

Until KeyboardPushed (#PB_Key_Escape)
End
Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4379
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Bitmap Sin Scroller.
« Reply #1 on: February 28, 2007 »
Wow. Shocky. Thanks for posting. Nice one. Didn't know that you have a
purebasic copy ? Cool ...
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17374
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Bitmap Sin Scroller.
« Reply #2 on: February 28, 2007 »
When I finished using Blitz and returned to coding, I hadn't decided which language I was going to take up next.. At the time I was tempted by PB and I wrote a few things in it over the space of about a week.

Then I decided to try Freebasic.. Now I have to be honest and say that I like Purebasic's syntax better, as a language to code in I enjoyed it more but since everyone else around me seemed to be using FB and I intended to base the forum around one core language at the time, I chose Freebasic and left my experiments in PB where they were.

But yes, I do have a PB licence and full copy and I might do a bit more in this language in the future. It would be good to attract users of all kinds of languages here and to do that we need to have support for them. :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Bitmap Sin Scroller.
« Reply #3 on: February 28, 2007 »
Nice demo shocky.

i like also the font , can i use it with my work?

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17374
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Bitmap Sin Scroller.
« Reply #4 on: February 28, 2007 »
Sure, but you should know that I didn't draw that font, I found it somewhere :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Bitmap Sin Scroller.
« Reply #5 on: February 28, 2007 »
thanks :)

Offline va!n

  • Pentium
  • *****
  • Posts: 1393
  • Karma: 108
    • View Profile
    • http://www.secretly.de
Re: Bitmap Sin Scroller.
« Reply #6 on: March 15, 2007 »
Nice work shockwave...  i have updated the source to work with PB v4.02... btw, dont use StringName$.s because String.s and String$ are not the same thing (its silly i know ^^) So here we go with the updated versio

Code: [Select]
; Sine Scroll Coded By Nick Simpson 2005.
; Updated a bit, commented and added error handling to work with PB v4.02
; by va!n (thorsten will) in 2007
;
;============================================================================================

Global  xres.w , yres.w , loop.w ,xp.w , yp.w , t.s , tptr.w , sco.b

xres  = 800           ; ScreenWidth
yres  = 600           ; ScreenHeight
sco   = 0
tptr  = 1

t.s = "                                    "
t.s = t.s+"HELLO.. THIS IS MY FIRST ATTEMPT AT A DEMO WRITTEN IN PUREBASIC, THE LANGUAGE SEEMS TO BE A LITTLE BIT TRICKY "
t.s = t.s+"BUT IN FAIRNESS IT'S LEARNABLE AT LEAST AND IT SEEMS TO BE QUITE FAST SO I'LL PUT UP WITH IT... "
t.s = t.s+"NOW TO ADD SOME STARS, A LOGO AND SOME MUSIC AND THEN IT WILL BE FINISHED... HAPPY 2006.. NICK."
t.s = t.s+"                                 "


; -------- Init needed Stuff --------

InitSprite()                     ; Needed to init DX Screen and DX Drawings
InitKeyboard()                   ; Needed for handling DX keyboard inputs
UsePNGImageDecoder()             ; Needed to work with PNG Image

Dim gfxfont(60)                 ; DIM for handling the handle of each char image

; -------- Load Font Gfx --------

font = LoadImage (#PB_Any, "font.PNG")                ; Load the font PNG image
 
If font = 0                                              ; If loading image failed,
  MessageRequester("Error", "Cant load font.PNG", 0)     ; we alert an error and
  End                                                    ; stop the application
EndIf

; -------- If Font successfully load, open Screen --------

window = OpenScreen( xres , yres , 32 , "PBWINDOW")      ; Open DirectX Screen

If window = 0                                            ; If creating DX screen failed,
  MessageRequester("Error", "Cant open Window", 0)       ; we alert an error and
  End                                                    ; stop the application
EndIf

; -------- Creating for each bitmap char an own Image --------

StartDrawing (ScreenOutput())                           ; Drawing loaded FONT Image
  DrawImage (ImageID(font),0,0)                         ; to the DX screen...
StopDrawing() 

xp = 0
yp = 0

For loop =1 To 60                                     ; Grabing from the screen
  gfxfont(loop) = GrabImage(font,#PB_Any,xp,yp,31,31)  ; each char as single image 
  xp = xp + 32                                         ; and save its handle to the
  ;                                                    ; DIM gfxfont()
  If xp > = 320
    yp = yp + 33
    xp = 0
  EndIf
Next

; -------- MainLoop --------

Repeat
  ClearScreen($0)                                       ; Clear Screen with color $0
  ExamineKeyboard()                                     ; Update for keyboard inputs

  StartDrawing (ScreenOutput())                         ; Start drawing on DX Screen
    cco = 0
   
    For cc = 0 To 25
      letter = (Asc(Mid(t.s, tptr+cc, 1))-31)
      DrawImage (ImageID(gfxfont(letter)), (sco+cco), 300+50*Sin((cc+cco+sco+m)/120)) 
      cco = cco + 32
    Next
   
    m   = m   -5
    sco = sco -3
   
    If sco < -32
      tptr = tptr + 1
      sco=sco + 32
    EndIf
   
    If tptr > (Len(t.s)-30 )
      tptr = 1
    EndIf
  StopDrawing()                                        ; Stop drawing on DX Screen

  FlipBuffers()                                        ; Bring backround buffer to forground

Until KeyboardPushed (#PB_Key_Escape)                 ; Repeats until key ESCAPE has pressed
End

- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1393
  • Karma: 108
    • View Profile
    • http://www.secretly.de
Re: Bitmap Sin Scroller.
« Reply #7 on: March 15, 2007 »
Here is another modified version, using DX Sprites instead Images and just only the Font PNG as Sprite... This version dont use an array for handling each FontChar...  This Version is using just one big sprite and clipping to get the needed char out of the big sprite...

I am very tired and i m a bit confused about my source, because i think there is somehting wired and wrong... i will take later a look ^^ so sorry, if the code suxx, my concentration is out of power now ^^

Code: [Select]
; Sine Scroll Coded By Nick Simpson 2005.
; Updated to work with PB v4.02 and changed the code to work with DX Sprites indeed Images
; by va!n (thorsten will) in 2007
;
;============================================================================================

Global  xres.w , yres.w , loop.w ,xp.w , yp.w , t.s , tptr.w , sco.b

xres  = 800           ; ScreenWidth
yres  = 600           ; ScreenHeight
sco   = 0
tptr  = 1

t.s = "                                    "
t.s = t.s + "HELLO.. THIS IS MY FIRST ATTEMPT AT A DEMO WRITTEN IN PUREBASIC, THE LANGUAGE SEEMS TO BE A LITTLE BIT TRICKY "
t.s = t.s + "BUT IN FAIRNESS IT'S LEARNABLE AT LEAST AND IT SEEMS TO BE QUITE FAST SO I'LL PUT UP WITH IT... "
t.s = t.s + "NOW TO ADD SOME STARS, A LOGO AND SOME MUSIC AND THEN IT WILL BE FINISHED... HAPPY 2006.. NICK."
t.s = t.s + "                                 "

; -------- Init needed Stuff --------

InitSprite()                     ; Needed to init DX Screen and DX Drawings
InitKeyboard()                   ; Needed for handling DX keyboard inputs
UsePNGImageDecoder()             ; Needed to work with PNG Image

; -------- If Font successfully load, open Screen --------

window = OpenScreen( xres , yres , 32 , "PBWINDOW")      ; Open DirectX Screen

If window = 0                                            ; If creating DX screen failed,
  MessageRequester("Error", "Cant open Window", 0)       ; we alert an error and
  End                                                    ; stop the application
EndIf

; -------- Load Font Gfx as Sprite--------

font = LoadSprite (#PB_Any, "font.PNG")                ; Load the font PNG as Sprite

If font = 0                                              ; If loading Spritefailed,
  MessageRequester("Error", "Cant load font.PNG", 0)     ; we alert an error and
  End                                                    ; stop the application
EndIf

; -------- MainLoop --------

Repeat
  ClearScreen($0)                                       ; Clear Screen with color $0
  ExamineKeyboard()                                     ; Update for keyboard inputs

  cco = 0

  For cc = 0 To 25
    letter   = Asc(Mid(t.s, tptr+cc, 1))-31
 
    yCharPos = letter / 10
    xCharPos = letter % 10
   
    If xCharPos = -1 : xCharPos = 9
    ElseIf xCharPos > 0 : xCharPos = xCharPos - 1
    EndIf
   
    ClipSprite(font, xCharPos*32, yCharPos*33, 31, 32)
    DisplaySprite(font, sco+cco, 300+50*Sin((cc+cco+sco+m)/120))
    cco = cco + 32
  Next
 
  m   = m   -5
  sco = sco -3
;     
  If sco < -32
    tptr = tptr + 1
    sco = sco + 32
  EndIf
;     
  If tptr > Len(t.s)-30
    tptr = 1
  EndIf
                                                       ; Stop drawing on DX Screen
  FlipBuffers()                                        ; Bring backround buffer to forground

Until KeyboardPushed (#PB_Key_Escape)                 ; Repeats until key ESCAPE has pressed
End


- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17374
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: Bitmap Sin Scroller.
« Reply #8 on: March 15, 2007 »
Thanks va!n :) Always nice to have some Pbscource :D Have some Karma.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline aNdy

  • ZX 81
  • *
  • Posts: 24
  • Karma: 2
    • View Profile
Re: Bitmap Sin Scroller.
« Reply #9 on: September 01, 2018 »
Apologies for resurrecting this old thread...

I completely forgot to mention in other threads I started for my recent releases that knowledge gained from the posts above enabled me to write my own scrolling message routines, leading to eventually heavily rewriting and adding various effects.

My modified and enhanced code can be found in the downloads (sources included in the downloads) in the following threads; I hope someone finds them useful:

http://www.dbfinteractive.com/forum/index.php?topic=6756.0
http://www.dbfinteractive.com/forum/index.php?topic=6766.0

A  - --H U G E-- -  thanks to 'Shockwave' and 'va!n' for their posts and idea and humble apologies for not mentioning them in my scrolling messages. I bow down before your greatness! ;)

Regards
aNdy/AL/Cosine