Graphic arts. Using Procedures


Procedures
When creating graphics programs, you often have to draw the same shapes. To avoid copying the same commands, use procedures.
The general form of the procedure entry looks like this: 
 
void  procedure_name (procedure parameters)  
// parameters may be absent, but are more often used to
// to draw shapes of different shapes or in different places of the picture
{
    commands that are executed when a procedure is called
}

Procedures are most often written above the main function main()
In order to execute the commands of the procedure in the main program, it is enough to write the name of the procedure (the procedure will be called and the commands written inside the procedure will be executed.
 
void main()
{
    procedure_name
}

For example, a program that draws two filled circles, in which the drawing of the circle is separated into a separate procedure, would look like this:
// parameters x, y - the center of the circle, parameter r - the radius of the circle, parameter c - for the fill color of the circle
// the exact values ​​of these parameters will be specified when calling the procedure in the main program
void draw_circle (int x, int y, int r, int c)
{
    circle(x, y, c);
    floodfill(x, y, c);
}

void main()
{
 // in parentheses we put the values ​​of the parameters that must be used when drawing a circle
 // these parameters will be passed to the procedure
    draw_circle(100, 100, 50, 5);
    draw_circle(200, 200, 100, 10);
}