Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using DATA like arrays
#1
I'm making a font and I'm using DATA statements to make up the font, is there a way to do something like this:

Code:
dim _data(1 to 3)

_data(1):
data 1
_data(2):
data 2
_data(3):
data 4

for i = 1 to 3
    restore _data(i)
    read value
    print value
    sleep
next
sleep

So that way each piece of DATA can be indexed by a variable like an array?
Reply
#2
EDIT:
http://www.freebasic.net/forum/viewtopic.php?t=3175

Joshy
sorry about my english
Reply
#3
DJ, that link seems to be broken.

Axipher, why would you want to store your data like that? It's only going to slow your program down, if you have to read the data every time you print a character.
Reply
#4
Do you have to use DATA? Why not just use a font file?
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#5
I saw no slowing my my program so far, I've implemented this method into a 800-line program and called it about 30 times in loop and it worked fine. Anyways how would I make a font file?
Reply
#6
0,0,0,1,0,0,0
0,0,1,0,1,0,0
0,1,1,1,1,1,0
0,1,0,0,0,1,0
1,0,0,0,0,0,1
1,0,0,0,0,0,1
1,0,0,0,0,0,1
1,1,1,1,1,1,0
1,0,0,0,0,0,1
1,0,0,0,0,0,1
1,1,1,1,1,1,0
1,0,0,0,0,0,1
1,0,0,0,0,0,1
1,1,1,1,1,1,0

That would be A and B and you could figure ot the rest

Code:
'make the arrays
DIM font(25) as integer ptr  '26 letters
FOR i = 0 TO 25
   font(25) = imagecreate(7,7)
NEXT

'load the file
OPEN "font.fnt" FOR INPUT AS #1
FOR i = 0 TO 25
   For x = 0 TO 6
      For y = 0 To 6
         INPUT #1, a
         PSET font(i), (x, y), a
      Next
   Next
Next

'place an A on the screen
Screenres 640, 480, 32
PUT (10, 10), font(1), TRANS

'important! don't let the program leak memory
FOR i = 0 TO 25
   imagedestroy font(i)
NEXT

This will give you a fast font routine. I have an even faster routine somewhere, I'll look for it for you.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#7
Thanks alot, I'll try to implement this somehow.

All i get is an error saying FBIDE.tmop needs to close and nothing happens in the window.

P.S.: What exactly is "ptr" mean?
Reply
#8
ooh, well... a pointer is just a type of data, like an integer(3 for instance), or a single (3.27838743 for intstance) or a string ("hello" for instance)

the difference is, all of these data types, the integer, the single, and the string, have different places in memory where theyre sitting. everything FB does has a place in memory where it sits untiil you need it.


now heres a little theory:

Here we have a program that has three variables; x, y, and px. x and y are integer variables. px is a pointer to the location of x.


Code:
dim as integer x, y
dim as integer ptr px

x = 100
y = 64

px = @x



now, when fb makes your program, its got to give all of those data places in memory. x needs a place, and y and also px need a place in memory. so:

x = Address 4 (length of an integer is 4 bytes)
y = Address 8 (length of an integer is 4 bytes)
px = Address 12 (length of a ptr is 4 bytes)



so, since x = 100, that means "100" is at memory location 4. y = 64 so "64" is at memory location 8.

now the new part. px is holding the address of x (@x) which is Address 4. px = 4, so if we remember from before...

"x = 100, 100 at address 4"
"y = 64, 64 at address 8"
"px = 4, 4 at address 12"


okay!

any more questions just ask. heres one before you do, to read whats at the address of a pointer, use "*"


Code:
dim as integer x, y
dim as integer ptr px

x = 100
y = 64
px = @x

? *px
*px = 300 '' changed what was really in x!

? x
sleep


p.s. all the code here is untested
Reply
#9
I know why nothing is displayed on the screen, its these lines:

Code:
INPUT #1, a
         PSET font(i), (x, y), a

This will give you a black font, and you are probably writing on black right? Try this instead:

Code:
INPUT #1, a
       IF a THEN PSET font(i), (x, y), rgb(255,255,255)

That will make the font white. I'd explain the pointers, but the last posts seems to have done that fairly well.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)