Next we need to discuss how colours are specified. Colours are given by specifying how much red, green and blue (RGB colour scheme) you want for each pixel displayed. You specify how much by giving a number between 0 and 255 for each colour. Zero means none of that color and 255 means maximum of that colour. There is a method called color that allows you to create a colour by specifying the 3 values for RGB. For instance, color red = color(255,0,0); would create a variable called red (maximum red, no green and no blue) that you could use later in your program any time you want red (using background, stroke or fill).
|
|
| ![]() |
Notice how only two sides of the triangle have a black line (the right side and bottom). If we wanted the whole triangle to be outlined in black we would need to change the first endShape(); to endShape(CLOSE); so that the last vertex of the triangle would be connected the the first vertex with a line.
This program specifies colour using hexadecimal values. The first 2 digits are for the amount of red (0 means no red, FF means max red). The middle two digits are for green and the last 2 digits are for blue.
|
Another option is to download the Colour.pde file. It has a large number of predefined colour constants. To use this file you need to add a tab like we did to use Input.pde. Here is an example of a program that uses it. The advantage of this is you can use names for colours instead of numbers.
|
|