Graphical method to use
Drawing things to the screen can help you make much more interactive programs. The following methods will give you a start building graphical programs.
To create graphical programs you will need the following using directives:
You can use the same terminal methods as described previously to read values from the user in the terminal. Then you also have access to the following methods to perform drawing actions:
What do the different arguments represent?
When you open a window, you create an area onto which you can draw. The width
and height
arguments will determine how large the window is. You could create a 4 by 3 aspect ratio with something like 800 by 600, or a widescreen using 1280 by 720 - though you can create any shape window you want.
Shape drawing methods need a color to know what color shape to draw. You can get a color value by calling the different Color...
methods such as ColorRed()
, and pass that as the color argument value. Following the color, the methods indicate where the shape should appear, and its size. The position is indicated use x
and y
coordinates. The x
value represents the distance from the left side of the window, while y
is the distance from the top of the window. Size values will depend on the shape, a rectangle has a width and height, a circle has a radius, triangles have three points, etc.
We will explore this further in the guided tour and trailside stop. For now, it is enough to remember that these methods exist.
Example
The following example draws a house in a rectangular window.