Colored circles

with functions

Colors are composed of three primary colors on the computer: red, green and blue (RGB). You can also set the alpha value. This value determines the transparency of the color. All these values must be a number between 0 and 255. If you set the alpha value to 0, the color is fully transparent, with 255 it is fully opaque. For all functions that expect a color, e.g. Fill, Background, Stroke, you can also specify these four values to set the color.

    

Draw a circle of size 50 at x and y coordinates 100, 100. Set the fill color to red (Red=255, Green=0, Blue=0, Alpha=255). You can also omit the alpha value. Set the background to gray tone 128 beforehand. The dash of the circle should not be displayed.

Background, NoStroke, Fill, Circle

Background(128);
NoStroke();

Fill(255, 0, 0, 255);
// without alpha value
// Fill(255, 0, 0);
Circle(100, 100, 50);

 

Modify exercise 2 so that the color and the alpha values are determined using a random number between 0 and 255.
double, Random, Background, NoStroke, Fill, Circle

Background(228);
NoStroke();

double red   = Random(0, 255);
double green = Random(0, 255);
double blue  = Random(0, 255);
double alpha = Random(0, 255);

Fill(red, green, blue, alpha);

Circle(100, 100, 50);

 

Now modify exercise 3 and set the Timer variable to your own Draw function, in which the random values are determined and the circle is drawn. Draw the circle at the current mouse position.
Timer, void, MouseX, MouseY, double, Random, Background, NoStroke, Fill, Circle

Background(128);
NoStroke();

Timer = Draw;

void Draw()
{
	double red   = Random(0, 255);
	double green = Random(0, 255);
	double blue  = Random(0, 255);
	double alpha = Random(0, 255);
	
	Fill(red, green, blue, alpha);
	
	Circle(MouseX, MouseY, 50);
}

 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License