Learn To Code: Changing the Ink Colour (Pen Colour) and reading the Ink Colour

Started by kevin, January 08, 2023, 08:18:00 PM

Previous topic - Next topic

kevin

  Here's an example of how you can use the Ink function in a PlayBASIC program:

PlayBASIC Code: [Select]
; Set the Ink colour to RED and display a message
Ink RGB(255,0,0)
Print "This Test is in RED"

; Set the Ink colour to GREEN and display a message
Ink RGB(0,255,0)
Print "This Text is in GREEN"

; Set the Ink colour to BLUE and display a message
Ink RGB(0,0,255)
Print "This Text is in BLUE"

; Display the screen and wait for the user to press a key
Sync
WaitKey




 The Ink function is used to set the current pen colour for graphics operations such as Text, Dot, Box, Line, Circle, and DrawShape. The colour is specified in RGB format. The Print function is used to display a message on the screen. The Sync function is used to display the screen, and the WaitKey function is used to wait for the user to press a key.

In this example, the Ink function is used to set the pen colour to red, green, and blue, and the Print function is used to display a message in each of these colours.

Here are some other useful graphics-related functions in PlayBASIC:

   Cls: Clears the screen to the current background colour.
   Box: Draws a filled or outlined box on the screen.
   Circle: Draws a filled or outlined circle on the screen.
   Line: Draws a line on the screen.
   Text: Displays text on the screen.
   DrawShape: Draws a shape on the screen using a set of coordinates.


kevin

Here's an example of how you can use the GetInk function in a PlayBASIC program:

PlayBASIC Code: [Select]
; Set the INK colour
Ink RGB(200,50,100)

; Read the current Ink colour
ThisColour=GetInk()

; Display the R,G,B values of this colour
Print "Current Ink Colour R is:"+Str$(RgbR(ThisColour))
Print "Current Ink Colour G is:"+Str$(RgbG(ThisColour))
Print "Current Ink Colour B is:"+Str$(RgbB(ThisColour))

; Display the screen and wait for the user to press a key
Sync
WaitKey




The GetInk function is used to get the current pen colour in RGB format. The Ink function is used to set the current pen colour. The RgbR, RgbG, and RgbB functions are used to extract the red, green, and blue components of the colour, respectively. The Print function is used to display the values of the red, green, and blue components on the screen. The Sync function is used to display the screen, and the WaitKey function is used to wait for the user to press a key.

In this example, the GetInk function is used to get the current pen colour, which is then displayed on the screen using the Print function. The RgbR, RgbG, and RgbB functions are used to extract the red, green, and blue components of the colour and convert them to strings using the Str$ function, which allows them to be displayed on the screen.

Here are some other useful graphics-related functions in PlayBASIC:

   Cls: Clears the screen to the current background colour.
   Box: Draws a filled or outlined box on the screen.
   Circle: Draws a filled or outlined circle on the screen.
   Line: Draws a line on the screen.
   Text: Displays text on the screen.
   DrawShape: Draws a shape on the screen using a set of coordinates.