Author Topic: Scrolling LED Text[BB2D]  (Read 5079 times)

0 Members and 1 Guest are viewing this topic.

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Scrolling LED Text[BB2D]
« on: March 06, 2007 »
Heres a scrolling text function I just managed to finish before I go sleep. It should be fairly easy to put into in progs. The text is all pre-drawn to a bitmap image. I did this because I figured it would be faster than drawing each loop. The downside to that is that no animation or colour changing can be done to it :( I still plan on adding a couple more features and making the font look a little nicer but other than that I consider this pretty much done. Oh and i still got to work out why the mess is occurring, but at least it looks kinda nice :p

Code: [Select]
Graphics 640, 480, 32, 2

;--------------------------------------;
;********** NEEDED IN PROG ************;
;--------------------------------------;
Dim letter_data(236, 8)
INIT_LETTER_DATA()

Type led
Field x, y, w, h, dir, spd, image, spawn, x_start
End Type
;--------------------------------------;
;************ DEMO LOOP ***************;
;--------------------------------------;
CREATE_LED(0, 0, 1, 0, 150, 0, 6, 0, "Some stuff    ")
CREATE_LED(65, 0, 2, 100, 0, 150, 10, 0, "hello heres an example of a scrolling text function")
CREATE_LED(160, 1, 5, 120, 20, 0, 6, 1, "0010 1000 0110 1111 0101 1100 ")
CREATE_LED(200, 1, 2, 150, 20, 0, 10, 1, "daer ot gnisufnoc eb dluow sihT     Confusing   ")
CREATE_LED(300, 0, 8, 0, 150, 0, 4, 1, "read me      ")
CREATE_LED(380, 0, 3, 150, 150, 250, 6, 1, "Heres a mess   ")
CREATE_LED(360, 0, 3, 100, 0, 100, 10, 0, "hello heres an example of a scrolling text function    ")
While Not KeyHit(1)
Cls
DRAW_LEDS()
Flip
Wend


;--------------------------------------;
;************ FUNCTIONS ***************;
;--------------------------------------;
Function DRAW_LEDS()
For l.led = Each led
DrawImage l\image, l\x, l\y
If l\dir = 0
l\x=l\x-l\spd
;loop the text
If l\x+l\w < GraphicsWidth() And l\spawn = 0
l\spawn = 1

l2.led = New led
l2\x = l\x_start: l2\y = l\y
l2\w = l\w: l2\h = l\h
l2\dir = l\dir: l2\spd = l\spd
l2\image = l\image
l2\x_start = l\x_start
;clean up text thats scrolled off screen
Else If l\x+l\w < 0
Delete l.led
EndIf
Else
l\x=l\x+l\spd
;loop the text
If l\x > 0 And l\spawn = 0
l\spawn = 1

l2.led = New led
l2\x = l\x_start: l2\y = l\y
l2\w = l\w: l2\h = l\h
l2\dir = l\dir: l2\spd = l\spd
l2\image = l\image
l2\x_start = l\x_start
;clean up text thats scrolled off screen
Else If l\x > GraphicsWidth()
Delete l.led
EndIf
EndIf

Next

End Function

;-----------------CREATE LED PARAMETERS----------------------;
;x_pos = x position for image to start at
;y_pos = y position for image to start at
;dir = direction led moves: 0 = left, 1 = right
;spd = speed image moves
;r, g , b = colour elements
;dot_size = the size of the dots
;dot_type = dot shape: 0 = round, 1 = square
;led_string = The text you want to display
;------------------------------------------------------------;

Function CREATE_LED(y_pos, dir, spd, r, g, b, dot_size, dot_type, led_string$)
length = Len(led_string$)
l.led = New led
l\image = CreateImage(8*dot_size*length, 8*dot_size)
l\y = y_pos
l\w = ImageWidth(l\image)
l\h = ImageHeight(l\image)
l\dir = dir: l\spd = spd
If l\dir = 0 
l\x = GraphicsWidth()
l\x_start = l\x
Else
l\x = -l\w
l\x_start = l\x
EndIf 


SetBuffer ImageBuffer(l\image)
For c = 1 To length
char$ = Mid(led_string$, c, 1)

ascii = Asc(char$)
If ascii < 58 And ascii > 47 ;Is Numeric
loc = ((Asc(char$)-48)*6)+1
Else If ascii > 64 And ascii < 91 ;Alpha Upper Case
loc = ((Asc(char$)-55)*6)+1
Else If ascii > 96 And ascii < 123  ;Lower case gets converted to upper
loc = ((Asc(char$)-87)*6)+1
Else If ascii = 32 ;Is space
space = 1
Else ;Is metacharacter

EndIf

If space = 0
For x = 0 To 5
For y = 1 To 8
If letter_data(loc+x, y) = 1
Color r, g, b
If dot_type = 0
Oval ((c-1)* dot_size*8)+((x)*dot_size), ((y-1)*dot_size), dot_size-2,dot_size-2, 1
Else
Rect ((c-1)* dot_size*8)+((x)*dot_size), ((y-1)*dot_size), dot_size-2,dot_size-2, 1
EndIf
If r-40 > 0
r2=r-80
Else
r=0
EndIf
If g-40 > 0
g2=g-80
Else
g2=0
EndIf
If b-40 > 0
b2=b-80
Else
b=0
EndIf

Color r2, g2, b2
If dot_type = 0
Oval ((c-1)* dot_size*8)+((x)*dot_size), ((y-1)*dot_size), dot_size-2,dot_size-2, 0
Else
Rect ((c-1)* dot_size*8)+((x)*dot_size), ((y-1)*dot_size), dot_size-2,dot_size-2, 0
EndIf

EndIf
Next
Next
EndIf
space = 0
Next 

SetBuffer BackBuffer()
End Function

;--------------------------------------;
Function INIT_LETTER_DATA()
;0 to 9
For y = 1 To 8
For x = 1 To 60
Read letter_data(x, y)
Next
Next
;A to J
For y = 1 To 8
For x = 61 To 120
Read letter_data(x, y)
Next
Next
;K to T
For y = 1 To 8
For x = 121 To 180
Read letter_data(x, y)
Next
Next
;U to Z
For y = 1 To 8
For x = 181 To 216
Read letter_data(x, y)
Next
Next
End Function
;--------------------------------------;


;0 to 9
Data 0,1,1,1,1,0, 0,0,0,1,0,0, 0,1,1,1,1,0, 0,1,1,1,1,0, 1,0,0,1,0,0, 1,1,1,1,1,1, 0,1,1,1,1,0, 1,1,1,1,1,1, 0,1,1,1,1,0, 0,1,1,1,1,0
Data 1,0,0,0,1,1, 0,0,0,1,0,0, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,1,0,0, 1,0,0,0,0,0, 1,0,0,0,0,1, 0,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,1
Data 1,0,0,1,0,1, 0,0,1,1,0,0, 0,0,0,0,0,1, 0,0,0,0,0,1, 1,0,0,1,0,0, 1,0,0,0,0,0, 1,0,0,0,0,0, 0,0,0,0,1,0, 1,0,0,0,0,1, 1,0,0,0,0,1
Data 1,0,0,1,0,1, 0,0,0,1,0,0, 0,0,0,0,0,1, 0,0,0,0,0,1, 1,0,0,1,0,0, 0,1,1,1,1,0, 1,0,0,0,0,0, 0,0,0,0,1,0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,0,1,0,0,0
Data 1,0,0,0,0,1, 0,1,0,0,1,0, 1,0,1,1,0,1, 0,1,0,0,1,0, 0,0,0,0,0,1, 0,1,0,0,0,0
Data 1,0,0,0,0,1, 0,0,1,1,0,0, 0,1,1,1,1,0, 1,0,0,0,0,1, 1,0,0,0,0,1, 1,0,0,0,0,0
Data 0,1,1,1,1,0, 0,0,1,1,0,0, 0,1,0,0,1,0, 1,0,0,0,0,1, 0,1,1,1,1,0, 1,1,1,1,1,1
« Last Edit: July 21, 2007 by Shockwave »

Online Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Scrolling LED Text
« Reply #1 on: March 06, 2007 »
Nice one Mike :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Scrolling LED Text
« Reply #2 on: March 06, 2007 »
Thanks. It was going to be a part for my 20 sec demo, but since it was kind of like its own self contained little thing in a way I figured I might as well post the code.

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Scrolling LED Text
« Reply #3 on: March 06, 2007 »
I think something is wrong, heres a screenshot.
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Scrolling LED Text
« Reply #4 on: March 06, 2007 »
That looks really weird. I dont know if anyone else gets the same problem, or might know whats happening there, cos I dont ???

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Scrolling LED Text
« Reply #5 on: March 06, 2007 »
It works fine here and looks great.

That screen shoot is probably something to do with that particular PC. The thing with blitz is that it can have certain errors when you do certain things like draw stuff off screen. Its some sort of memory overflow or other. Somtimes you get it from updated gfx drivers. Chances are if you used an older driver, or even the latest driver if ur using an old version already, it would fix the problem.

It is possible to resolve some of these issues by the way you progam the application too.
I noticed this line of code

Code: [Select]
Else If l\x > GraphicsWidth()
possibly chaning that to

Code: [Select]
Else If l\x >= GraphicsWidth()

and then moving where you actually draw the image to somewhere after the range checking mite clear it up.

What thats saying to me is that at somepoint, DrawImage is drawing an image at position GraphicsWidth() wich technically memory wise doesnt exist.
Blitz should actually cope with this, and it does most of the time. However on the rare occasion you do get some wierd bugs like that.

I got no idea if my suggestion will have any impact on the result, but its worth a try. I cant unfortunately replicate the problem. But I stand by that advice in that you try to keep the poition you draw anything within the range of 0->GraphicsWidth()-1 and 0->GraphicsHeight()-1 and do the checking before you actually draw anything.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Scrolling LED Text
« Reply #6 on: March 06, 2007 »
Nice work Mike :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Scrolling LED Text
« Reply #7 on: March 06, 2007 »
I thought that it had something to do with to big images for blitz.
Maybe but i don't know.
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: Scrolling LED Text
« Reply #8 on: March 06, 2007 »
Tetra, thanks for the advice. From experience I have never had a problem using DrawImage() outside of the buffer. If thats causing a problem for some I should be able to fix it using a Viewport :)

Clyde, glad you like it ;)

Paul, yeah youre right the images are pretty big. I havent heard of there being any limit on the size of an image you can use in Blitz, but maybe there is one. If thats true it could cause problems, in which case I spose I'll just have to draw each character to a separate image. Maybe I'll give it a test with a very big string just to see what happens. 


Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Scrolling LED Text
« Reply #9 on: March 06, 2007 »
I thought that it had something to do with to big images for blitz.

Yep that is more likey the case. Try using the frames parameter for each letter.
I just had the above problem with an onborad intel gfx chip once ugh :whack:
Challenge Trophies Won: