Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LINE format

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
I asked a question about this a while ago, but nobody really answered it. Well, while I was trying to figure out a way to make a compact and fast font for my GUI I nailed it. There is to be no more guess work with line

What I am is talking about is 'dot' in:
LINE (100,100)-(200,100),,,dot

The last number is figured out in binary, and it goes in loops of 15 here is a chart that will help you (am me)

32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1


so say you want a line that goes 0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1

figure out it out by plugging it into the table and adding all the values together

32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1

Now add up all the numbers that had a 1 under them
8192+4096+1024+128+64+8+2+1=13515

LINE (100,100)-(200,100),,,13515
 
My bad! I counted out too many - it only goes up to 16384, don't ever add 32768. Move verything over 1 digit
 
Very nice.
 
You can actually include that 32768 digit by *subtracting* 32,768. As strange as this seems, it has to do with the way signed 16-bit numbers are represented. Using 2's complement (which is what QB uses, as well as Intel processors in general), you simply invert the sign of the most significant bit.

You should find that when you use the bit mask 32,767 (the maximum that your method can create), the line will have holes in it every 16 pixels. The mask -1 (which is what you get by subtracting 32,768 from 32,767) will give you a solid line.
 
very interesting, however, I just wouldn't put in any value if I wanted a solid line
 
I've been experementing with this line thing, and I only have one sugestion. Why not use...

2 ^ x

...insted of a table?
 
Good question, but there is a good reason to not use that. Exponentiation in QuickBASIC is done using the floating-point emulation layer. When you put "2 ^ x" in your code, what goes on behind the scenes is this:

- convert x to a [tt]DOUBLE[/tt]
- invoke the interrupt associated with the floating-point logarithm function, passing the double value of x
- convert 2 to a [tt]DOUBLE[/tt]
- invoke the interrupt associated with the floating-point multiplication function, passing the logarithm of x and 2 as parameters
- invoke the interrupt associated with the floating-point exponentiation function (which can only do base 'e', hence the logarithm stuff above), passing 2 * log(x) in as the parameter
- convert the result, which is a [tt]DOUBLE[/tt], back to an [tt]INTEGER[/tt]

Much, much slower than a lookup table :)
 
Cause where do you get x from?
What if you want a line like 010010010101011? How would you do that without a reference table?
 
Er, qbasicking, the index into the reference table *is* x.
 
2 ^ 0 = 1
2 ^ 1 = 2
2 ^ 3 = 4
2 ^ 4 = 8
2 ^ 5 = 16
2 ^ 6 = 32
2 ^ 7 = 64
2 ^ 8 = 128
ect...
 
But, I experemented and yes, a refrence table is much faster.
 
... But I still use 2 ^ X for setting up the table.
 
Of course, it makes virtually no difference, but this is the method I use:
[tt]
table(0) = 1
FOR i% = 0 TO 13
table(i% + 1) = table(i%) + table(i%)
NEXT i%
[/tt]
 
What am I missing here?

LINE (100,100)-(200,100),,,13515

is just

LINE (100,100)-(200,100),,,&H34CB

Just like in the QBasic documentation. Can somebody tell my when I need to use tables or exponentiation to create simple 16-bit values?
 
On a more helpful note, you can always use Microsoft Caclulator in "scientific view" and enter your bit-pattern in binary, then switch to hex to get the digits to enter in to your QBasic program.
 
These numbers have to be made on the fly, within the program, and with constantly changing dot patterns.
 
For that one pattern you happen to know the hex code. I have thousands of different patterns that I use, I'm not going to try and get the hex codes for all of them.

Good call on the calculator though.

there is no difference in the way that
LINE (100,100)-(200,100),,,13515 and
LINE (100,100)-(200,100),,,&H34CB behave, so it really doesn't matter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top