PDA

View Full Version : printing variables in graphics/tv mode



mosquito56
01-26-2008, 07:39 AM
I can't find any way to print a variable using the graphics.spin and the tv.spin. Searching and trying things for hours. Just need one line of code or point in the right direction.

Car:=124

gr.text(128,17,string(car))
gr.text(128,17,car))
gr.text(128,17,str(string(car))

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Mike Green
01-26-2008, 07:45 AM
Most of the other video drivers have a routine for displaying numbers in decimal and hexadecimal (dec and hex).· These call·the single character output routine of the driver (out).· You could just copy and paste the routine(s) from something like tv_text.spin to graphics.spin and change the out routine calls to whatever graphics needs.· I don't think they refer to anything else.

deSilva
01-26-2008, 07:57 AM
Most people use "Numbers". It looks a little bit terrifying in the beginning, but it it is quite versatile, and not really much code - just many constants http://forums.parallax.com/images/smilies/smile.gif

However, lookout for the delayed action of GRAPHICS! Don't re-use the internal string buffer of Numbers as long as the string is still being output!!

This even fooled Martin once http://forums.parallax.com/images/smilies/smile.gif

Post Edited (deSilva) : 1/26/2008 2:04:34 PM GMT

VIRAND
01-26-2008, 08:02 AM
Well I think it could be done something like this:

PUB foo | car
car:=124

byte[@carstring+0]:=(car/100)//10+$30 '30 is ascii for 0 and we display 3 digits here
byte[@carstring+1]:=(car/10)//10+$30
byte[@carstring+2]:=(car/1)//10+$30
gr.text(128,17,@carstring)

DAT
carstring byte "000",0

'I think this would display 124. But if car was 99 it would say 099, so add some if's to change leading 0's to $20, spaces.

mosquito56
01-26-2008, 08:05 AM
Mike, i have been using out, dec, hex, bin for about a month with vbasic. I tried cut and paste but it didn't work. The out sends it directly to the graphics method but I can't figure out the dx in the printstatement. When i tried dec(123) it print 1,2,3, on top of each other.

·I will try it again.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Mike Green
01-26-2008, 09:15 AM
I don't have my Propeller code handy, but you can use "decStr[ p++ ] := digit" instead of "out( digit )" where "p" is initialized to zero at the beginning of "dec" and "decStr" is declared as a 10 byte array. At the end of "dec", you add a zero termination byte with "decStr[ p ] := 0". Now you have a string you can display with gr.text which accounts for the spacing between the characters.

mosquito56
01-26-2008, 08:38 PM
Virand: I saw something like this in the pallete demo using Hexstring
·hexstring[0] := hex(co >> 4)
·hexstring[1] := hex(co & $F)
·gr.text(8, 19, @colorstring) "Why is this line @colorstring and not @hexstring?
·gr.colorwidth(2, 6)
·gr.text(1, 19, @colorstring)·· With colorstring defined as "Color" this code ouputs· "Color A3" or whatever the hexcode of the color is under the mouse.
··

··· I think you've hit on the right idea. I had a bad day yesterday and my brain couldn't figure out how to break a number into individual bytes. LOL. Just divide // and pack the datstring the way I want it to look and off to the races. I feel like going Disco dancing, this is soooo retro. When you get used to OOP kinda hard to go back to the old days.


·Mike, I think you came up with the same idea but in a strange language, "English"

Thanx much guys. I worked on this for hours yesterday.

P.S. Got it working, now I just need to figure out how to blank the screen to print the updates.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Post Edited (mosquito56) : 1/26/2008 2:47:51 PM GMT

VIRAND
01-27-2008, 03:55 AM
My guess is that in the DAT section there is something like this:

colorstring byte "Color "
hexstring byte "00",0

In that case displaying colorstring will also display hexstring.

mosquito56
01-27-2008, 10:21 AM
yeah, I got it working fine up to 5 digits now with decimal point. Now to make it generic· with flexable decimal and flexable number of digits.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.