Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

The Type color [8/11]

Multiple variables of type color can coexist in the same program. Each variable of type color has its own members .r, .g and .b.
[Run the program]

An initializer can be given as an argument of a function or procedure. In this program, the last call of procedure disc has an unmarked initializer for type color as the last argument.

Exercises:

Important: Take a peak at a solution if an exercise is too challenging.

1. Modify the unmarked initializer in the last statement of the source code. Try to modify it so that the last disc is painted approximately in yellow.
[Run the program]

Solution

disc(760, 360, 100, [70, 70, 0]);

2. (Challenging!) Add another statement at the end of the source code. In it, create a variable named mycolor of type color, and set it to a value given by the marked initializer /purple.

Solution

#color mycolor = /purple;

3. Draw a disc in the color given by variable mycolor . Choose any on-screen coordinates of your preference.

Solution

disc(200, 500, 100, mycolor);

4. Add another statement at the end of the source code. In it, modify the value of variable mycolor by setting the member .b to value 0. Then draw a disc in the color stored in the variable mycolor somewhere below the second disc.

Solution

mycolor.b = 0;
disc(480, 500, 100, mycolor);

5. Add another statement at the end of the source code. In it, modify the value of variable mycolor by setting the green component to value 60. Then draw a disc in the color stored in the variable mycolor below the third disc.

Solution

mycolor.g = 60;
disc(760, 500, 100, mycolor);

Loading...