Basicprogramming(.org) > SmallBASIC

POINT() gives odd output

(1/3) > >>

lettersquash:
I've been testing colours with POINT(x,y) and got some curious results. If I draw with rgb(255,0,0) and get p = point(x,y), then ? hex(-p) gives FF. With the full blue byte, the same ? hex(-p) gives FF0000.

Is this a bug or am I misunderstanding something?

chrisws:
Both POINT and RGB return negative values to dis-disambiguate from the colour constants 0-15. So you just need to compare -rgb(n,n,n) with -point(x,y)

Here's a little test program:

dim x
x << rgb(0,     0,   0)
x << rgb(0,     0, 255)
x << rgb(0,   255,   0)
x << rgb(0,   255, 255)
x << rgb(255,   0,   0)
x << rgb(255,   0, 255)
x << rgb(255, 255,   0)
x << rgb(255, 255, 255)
for c in x
pset 10, 10, c
p = point(10, 10)
if (p != c) then throw
print space(6-len(hex(-p))) + hex(-p)
next c

ZXDunny:
Seems that the RGB function takes colours in the format RGB(red, green, blue), but the POINT function returns BBGGRR. So when you specify full red (255,0,0) you get 0000FF back, but full blue returns FF0000 as expected.

B+:
Looks OK to me:

--- Code: ---'whats the point B+ 2019-02-19

dim x
x << rgb(40,     20,   10)
x << rgb(0,     0, 155)
x << rgb(0,   185,   0)
x << rgb(0,   255, 155)
x << rgb(255,   0,   0)
x << rgb(255,   0, 255)
x << rgb(255, 255,   0)
x << rgb(255, 255, 255)
for c in x
rect 100, 100, 200, 200, c filled
p = point(105,105)
color p
circle 500, 500, 100 filled
color 15
? getRGB(p)
input "OK? press enter ";wate\$   'consistent
cls
next

func getRGB(pointValue)
sh = right(space(6)+str(hex(-p)), 6)
r = left(sh, 2)
g = mid(sh, 3, 2)
b = right(sh, 2)
getRGB = "rgb("+str(val("&H"+r)) +", "+str(val("&H"+g))+", "+str(val("&H"+b))+")"
end

--- End code ---

chrisws:
Here's another test program:

pset 0, 0, rgb(0,0,0xFF): if "FF" != hex(-point(0,0)) then throw
pset 0, 0, rgb(0,0xFF,0): if "FF00" != hex(-point(0,0)) then throw
pset 0, 0, rgb(0xFF,0,0): if "FF0000" != hex(-point(0,0)) then throw