
Constructing shapes on a computer

Upgrade for more content
When we want to draw a geometric shape on a piece of paper, we can use a pencil and a ruler. Here is... a square. But, if we want to draw a similar square on a computer screen, how do we do that? The computer needs to know some things: How large should the square be?
What is the length of one side? And its orientation --where should the square be drawn? On a screen, we cannot use units of measurement like centimetres to tell the computer how large the square should be, or where it should be drawn. A screen is not divided into centimetres or millimetres but into small squares, called pixels. So instead, we tell the computer what pixels on the screen should be colored, in the color we want the square to be.
The computer screen, made up of pixels, is a coordinate system with an x-axis and a y-axis. In the upper left corner of the screen, x equals zero and y equals zero. Just as in a regular coordinate system, the x-values increase to the right. But, the y-axis on a computer screen is upside down compared to the y-axis in ordinary mathematics. The further down the screen you go, the higher the y value.
Enough talking! Let’s draw a square. We start in the upper left corner of the square. In this example, the pixel has the position x equals 100 and y equals 200. Let's draw a square with a side length of 100 pixels.
The first line of the square goes straight to the right from the starting pixel. The x value increases with the side length, 100 pixels. In the y-direction, nothing changes because the line does not go up or down, it is horizontal. The x-value of the last pixel of the line is 100, i.e. the value where we started, plus the side length 100, equals 200.
The last pixel has the same y-value as the starting pixel, 200. All pixels between the starting pixel and the end pixel are coloured in the colour we want. The next line, the second side of the square, goes straight down on the screen. This line doesn't change in the x-direction. The last pixel has the same x-value as in the upper right corner.
But the y-value changes with the square’s side length, 100 pixels. As the y-value increases as we move down the screen, the last pixel’s y-value becomes: our starting value, 200, plus 100, equals 300. The third line is 100 pixels to the left of the x-axis. Then the x-value decreases by 100 pixels. The y-value does not change.
We end up with x equal to 100 and y equal to 300. Now only the fourth line is left, the last side of the square. It is drawn from ‘x equal to 100’ and ‘y equal to 300’ to the pixel where we started. There, x equals 100 and y equals 200. Now all sides of the square are drawn on the screen.
Good! Let’s color all the pixels inside the square in red. So, in order to draw on a computer screen, we must use the screen's coordinate system. Then the computer knows where to draw. Screen distances are measured in the number of squares on the screen, pixels.
We draw on the screen by coloring pixels. To draw a geometric shape, we must know the properties of the shape. For a square we need the side length. For a circle we need the midpoint and diameter, or radius, and so on. All these properties, we must tell the computer.
And we do this by using a language that the computer understands, a programming language.