This is the code I wrote, which is pretty similar to the books with just a for loop added to allow me to check 30 pixels foreground color properties instead of one.
randomize timer()
screen_width = screen width()
screen_height = screen height()
cls
for i = 1 to 100
color = rgb(rnd(255), rnd(255), rnd(255))
ink color, 0
x = rnd(screen_width)
y = rnd(screen_height)
dot x, y
NEXT i
for i = 1 to 30
ink rgb(255, 255, 0), 0
x = rnd(screen_width)
y = rnd(screen_height)
if point(x, y) = rgb(0,0,0)
print "The pixel at ", x, ", ", y, " is black."
else
print "The pixel at ", x, ", ", y, " is not black."
ENDIF
next i
wait key
end
The program only prints out "The pixel at x, y is not black." I know it is something to do with the book though because I commented my code out and ran the books and got the same error. I tried restricting it to fewer colored pixels on the screen or none and I still am facing this problem.
My hunch, which is just a hunch, is something needs to be changed here:
if point(x, y) = rgb(0,0,0)
Here is the code provided in the book:
REM *** Seed random number generator ***
RANDOMIZE TIMER ()
REM *** Get the screen dimensions ***
width = SCREEN WIDTH ()
height = SCREEN HEIGHT()
REM *** Clear the screen ***
CLS
FOR c = 1 TO 10000
REM *** Choose a colour at random ***
colour = RGB(RND(255),RND(255),RND(255))
INK colour,0
REM *** Choose random position ***
x = RND(width)
Y = RND(height)
REM *** Draw a pixel on screen ***
DOT x, y
NEXT c
REM *** Check colour of random pixel ***
x = RND(width)
y = RND(height)
IF POINT(x,y) = RGB(0,0,0)
PRINT "The pixel at position (",x,",",y,")is black"
ELSE
PRINT "The pixel at position (",x,",",y,")is not black"
ENDIF
REM *** End program ***
WAIT KEY
END