Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Smaller text for SCREEN 13 - or any other valid screen!
#11
Or, better yet, here is a QuickBASIC program to calculate the decimal value:
Code:
'SPRITE-N, by Ralph A. Esquivel, 06-Mar-2006, calculates
'the value of spriteN that represents a sprite.

CLS
'for a wxh sprite
w = 3
h = 5


d = w * h
DIM s(d + 1)'sprite array
s(0) = w
s(1) = h
'example: sprite = "O" 'the letter "O"; see DATA statements below

'calling spriteN the decimal number that represents the sprite:
FOR i = 1 TO d
  READ s(i + 1)
  spriteN = spriteN + s(i + 1) * 2 ^ (d - i)
NEXT i
LOCATE 3, 3
PRINT "Representing the leter O as a 3*5 sprite, its decimal equivalent is"; spriteN
WHILE INKEY$ = "": WEND
END


DATA 0,1,0
DATA 1,0,1
DATA 1,0,1
DATA 1,0,1
DATA 0,1,0
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#12
Quote:Antoni:
Would you please explain how to use
Quote:each char fits in an integer and you can design chars from the top of your head : if you use octal each pixel line is a figure.
to obtain, say, a 0 and an O as 11114? When I drew a 0 as:
010
101
101
101
010
and translated the binary value 010101101101010 into decimal, I got 11114. Does the program then translate 11114 into octal?

Thanks. And, by the way, I found a neat way to translate any of the characters in the program you posted from the drawn character, or sprite, to the decimal number you show, or to an octal number, if that is required. The method can easily be extended to any other size of character or sprite. The only thing is, the numbers obtained in this manner are based on zeros and ones, so only one color per sprite can be assigned by the program.


While it is true tht this is a QuickBASIC forum, my mehtod for this involves an Excel spreadsheet.

I start by highlighting columns A, B and C for the present case, doing a Format, Column, Width, and choosing 5, to give a reasonabl-looking sprite.

In cell A2, I write SPRITE; in cell D2, BINARY; in cell E2, BIN2DEC; in cell F2, DEC2OCT.

In cell D3, I enter =A3&B3&C3, and copy down to D7.

In cell E7, I enter =MID(D7,1,1)*2^2+MID(D7,2,1)*2+MID(D7,3,1)
In cell E6, I enter =MID(D6,1,1)*2^5+MID(D6,2,1)*2^4+MID(D6,3,1)*2^3
In cell E5, I enter =MID(D5,1,1)*2^8+MID(D5,2,1)*2^7+MID(D5,3,1)*2^6
In cell E4, I enter =MID(D4,1,1)*2^11+MID(D4,2,1)*2^10+MID(D4,3,1)*2^9
In cell E3, I enter =MID(D3,1,1)*2^14+MID(D3,2,1)*2^13+MID(D3,3,1)*2^12

In cell F3, if I want octal numbers, I enter, =DEC2OCT(E3), and copy down to F7.

Now, any sprite I enter in the range A3:C7 as 0s and 1s appears in column D as binary numbers, and in column D and E as decimals and octals for the whole binary number represented in the sprite as the range A3:C7, or the range D3Big Grin7.

Using the above is how I saw that the 11114 Antoni shows, for a 0 and for an O, is not an octal, but a decimal. And, the method can easily be expanded for larger sprites!

I can see that this kind of representation for sprites of one color can be a real memory and code saver, for those programmers that do graphics. I wonder if the numeric representation IS used in this manner?

Comments?
Your Excel hack looks handy. I'll test it when I have time

About Biskbart's 5x4 font:
In your example
010 2
101 5
101 5
101 5
010 2

the char in octal is &o25552, you can put that value directly in the table. Curiously Biskbart translated everything to decimal when he wrote the code...
Antoni
Reply
#13
Antoni said:

Quote:Your Excel hack looks handy. I'll test it when I have time
, but, now that you have shown me how easily you obtain an octal number from a binary one, why, you can simply use Excel's oct2dec(x) to obtain the decimal value.

And, even though Bisbark didn't clutter up his progrm with the drawings necessary to envsion each character, he still had to draw each one to get the binary and octal numbers, and then do an octal-to-decimal transformation to get his final decimal numbers. I would think it would be easier to just do the drawings as DATA statements, and use code to obtain the binary, octal and/or decimal numbers.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)