Task

Get color information from an arbitrary pixel on the screen, such as the current location of the mouse cursor.

The mouse cursor may or may not have to be active in a GUI created by your program. These functions are OS related.




PROC Main()
  BYTE POINTER ptr
  BYTE 
    w=[160],h=[160],x=[0],y=[0],c,k,update=[1],
    CH=$02FC ;Internal hardware value for last key pressed
  CARD size=[6400],i
 
  Graphics(15) ;Graphics 160x160 with 4 colors with text window
  ptr=PeekC(88)
 
  ; Fill screen with random colors
  FOR i=1 TO size
  DO
    ptr^=Rand(0)
    ptr==+1
  OD
 
  PrintE("Use arrow keys to change position and Esc to exit.")
  DO
    IF update THEN
      c=Locate(x,y)
      PrintF("x=%B y=%B c=%B%E",x,y,c)
    FI
 
    k=CH
    CH=$FF
    update=1
    IF k=134 THEN
      IF x=0 THEN x=w-1
      ELSE x==-1 FI
    ELSEIF k=135 THEN
      IF x=w-1 THEN x=0
      ELSE x==+1 FI
    ELSEIF k=142 THEN
      IF y=0 THEN y=h-1
      ELSE y==-1 FI
    ELSEIF k=143 THEN
      IF y=h-1 THEN y=0
      ELSE y==+1 FI
    ELSEIF k=28 THEN
      EXIT
    ELSE
      update=0
    FI
  OD
RETURN