Use of MOUSE x,y,buttons; POINT(x,y); Message Boxes - Tutorial 012


Painting Program

      MODE8:OFF
      FOR n=1 TO 15
        GCOL0,n
        CIRCLE FILL RND(1279), RND(1070),30+RND(170)
      NEXT

      message$ = "Right click on a colour; left click and drag to paint"
      caption$ = "Painting"
      SYS "MessageBox", @hwnd%, message$, caption$, 0
     
      c=1
      REPEAT
        MOUSE x,y,b
        IF b=4 THEN
          GCOL0,c
          ELLIPSE FILL  x+5,y+5,15,25
        ENDIF
        IF b=1 THEN
          c=POINT(x,y)
          GCOL0,c
        ENDIF
      UNTIL FALSE


Annotated listing - how the program works

      MODE8:OFF
-----------------------------------------------------------------------------------------------------------------------
*******Draws 15 filled circles of different colour with random radii and random positions for incorporation into your artistic masterpiece; don't forget to select black (background) if you want to erase or go on top of other colours********

         FOR n=1 TO 15


        GCOL0,n *** sets the graphics colour ***

        CIRCLE FILL RND(1279), RND(1070),30+RND(170)

      NEXT
---------------------------------------------------------------------------------------------------------------------
      message$ = "Right click on a colour; left click and drag to paint" ********************************

      caption$ = "Painting" ***************************************How to make a message box!!!

      SYS "MessageBox", @hwnd%, message$, caption$, 0  **************************************
----------------------------------------------------------------------------------------------------------------------  

      c=1   ********* starts with colour red if no other colour selected

      REPEAT
-----------------------------------------------------------------------------------------------------------------------
        MOUSE x,y,b  

*** x and y record the graphics co-ordinates of the mouse in graphics units; b reads the state of the three buttons on the mouse : b=4 if LEFT BUTTON pushed ; b=1 if right button pushed; (b=2 if middle button/wheel pushed)

        IF b=4 THEN    ****** for a left click

          GCOL0,c  ****** sets the graphics colour

          ELLIPSE FILL  x+5,y+5,15,25  
**** Plots a small filled ellipse in colour c, near to the mouse pointer to act as the "brush"

        ENDIF
------------------------------------------------------------------------------------------------------------------------------
        IF b=1 THEN ****** a right click

          c=POINT(x,y)    *******POINT returns the graphics colour at position x,y as read by MOUSE x,y,b above

          GCOL0,c sets the new graphics colour

        ENDIF
       
      UNTIL FALSE


Next Tutorial

Richard Weston's Homepage