Graphics is obviously a vitally important area of programming which has been advanced by the commercial importance of cartoons, films, websites and computer games. Although the ability to write the types of programs introduced here is unlikely to be required by an A-level course, you may need to know some of the theory and it is an interesting and rewarding field in which to hone your programming skills.
The first topic of this tutorial is vector graphics. Vector graphics programs generate images by drawing objects such as rectangles and circles. A source file needs only a small amount of data (such as the colour, line thickness, radius and coordinates of the centre of a circle) to represent an object, so vector graphics files tend to be small. Vector graphics are easily and effectively scaled, as demonstrated in program Draw.
The second topic is bitmapped graphics. A bitmap file contains a header and data describing the colour of each individual pixel, so bitmaps tend to be large. As a consequence, compression is often used. We will cover the processing of compressed files in a later tutorial. In this tutorial we give examples of graphics programs that manipulate data for viewing instantly on screen and others that change the data in .bmp files.
Motion graphics is a popular topic and we provide a few programs to get you started. This is another area that we intend to develop in a later tutorial. Some of the code is advanced, and is intended to stretch enthusiasts. Do not be put off if it is beyond you at this stage.
Nowadays, most programmers draw graphics on the screen using a canvas in Object Oriented Pascal /Delphi, so in recent versions of Delphi there is no CRT or Graph unit. We provide instructions for downloading and including these Pascal files in your programs and also include Delphi versions of our demonstration programs using these units. The well-documented wingraph.pas file can also be used in Lazarus and it offers many advantages over the inbuilt Graph unit.
For advanced graphics you can use OpenGL code (1) within SDL (as demonstrated in programs by Max Foster, Christopher Winward and Steven Binns), (2) within PasSFML (as shown in Getting Started with PasSFML), (3) on a form or (4) using Glut. We show you how to use the last two methods in the last section of this tutorial.
Other relevant sections
Several other sections including these cover graphics:
- Overview of Graphics
- Drawing on a Form's Canvas
- Game Development
- Developing Graphical Web Pages
- Using Sprites
- Graphics2D Applets
Continue with the following topics first to learn more about this vital area of programming: