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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining color by pixel in graphics mode

Status
Not open for further replies.

freestyled14

Programmer
Apr 8, 2002
1
0
0
US
I'm expecting this to be an easy question to answer, but I was trying to find a way to determine the color of an individual pixel while working in graphics mode(Screen 12 to be precise). I am attempting to draw a line across the screen that will stop when it "hits" a pixel differing from the background color. How can I do this?
 

Load this little demo. Hopefully, it will explain everything you need to know. Essentially, a yellow pixel will travel through a red outlined box until it sees a red pixel; and then the yellow pixel will reverse direction. And so on.

Normally, all you have to do is interrogate the point position with IF POINT(X, Y) = such and such color THEN branch to a different routine.

I have included two lines that show what the colors are on two spots on the screen, so you'll know this can be done, also.

Hope this helps.

Dr. Jon


SCREEN 12
CLS
LINE (0, 45)-(100, 55), 4, B
COLOR 7
LOCATE 1, 1: PRINT "The color at POINT(50,50) ="; POINT(50, 50)
LOCATE 2, 1: PRINT "The color at POINT(100,50) ="; POINT(100, 50)
LOCATE 6, 1: PRINT "Hit Esc"

x = 1 ' 1 makes the not so bouncing ball go forward. -1 makes it go back.
y = 2 ' starting position on the left side

a:
a$ = INKEY$: IF a$ <> &quot;&quot; THEN END

y = y + x

PSET (y - x, 50), 0 ' trailing black pixel
PSET (y, 50), 14 ' the not so bouncing ball

IF POINT(y + 1, 50) = 4 THEN x = -1 ' if point is color 4 (right side), go back
IF POINT(y - 1, 50) = 4 THEN x = 1 ' if point is color 4 (left side), go forward

FOR t = 1 TO 15000: NEXT ' delay loop

GOTO a

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top