Graphics in Pascal: features, methods of creation and examples

Do programmers need graphics? Especially for those who have just begun to learn the language? Should I first study all the constructions for writing basic and standard tasks, and leave the graphics for later?

Everyone should answer these questions for himself. For example, for those who learn a programming language as part of a school course, the graphics in Pascal will be a great way to stimulate yourself to further learning. After all, at this time I want to see the results of my thinking, writing programs. If we are talking about a student, then the graphics have a different purpose. Rather, it acts as an auxiliary element that helps make written products more dynamic. But in any case, this section of the programming language is, of course, important.

It is worth considering that not all tools have graphics support. Pascal, in turn, is equipped with this function, therefore, its structure will be described in the article.

pascal graphics

Graphics in Pascal

Where to start? With what you need to understand, what is the minimum unit of the screen in different modes of operation of the Pascal language. If we are talking about text, then that will be the symbol. In the graph, they are a pixel. It has its coordinates, which are represented by the symbols X and Y, as well as color (standard - white). In order for the pixel to get the address (0; 0), you need to place it in the upper left corner. It is from here that the coordinates begin to count.

Graphics in "Pascal ABC" is enabled using the module, which must be written in the uses line.

graphics in pascal examples

Point

As an easy example, the task of displaying a point on the screen (photo below) will be given.

In the descriptions section, you can see the names of the modules recorded in the uses line. They include the graphical mode in the program. If the developer has already become familiar with the structure of programs, then he might think that in var you just need to write auxiliary variables. But a section like graphics in Pascal works a little differently. After the word var, you must write the video adapter installed on the PC, and then indicate in what mode it works. These designations are generally accepted. After opening the operator brackets, the actual type and mode must be noted. If the user does not know which adapter is installed, then you need to write line No. 7 in your program. Such a section as the graphics in Pascal is arranged in such a way that the detect procedure is able to automatically determine the data. It is worth remembering that all adapters have their own digital value, for each it can be found by looking on the Internet. In the eighth line, you can notice the Initgraph procedure. She launches the graphic mode. Lines No. 9 and No. 10 are needed so that if the initialization is unsuccessful, the program stops working. The closegraph function closes the graphic mode, allowing you to switch back to text mode.

Lines 2, 3, 7-10, 17 need to be remembered, because they can be used as a template, since all the graphics in Pascal have a common creation structure. Consider other elements of the problem.

By the variable color you need to understand the range of colors, in "Pascal" there are only 15. Assigning it a value of random, you need to understand that the tone will be chosen randomly. 14 line allows you to create a point on the screen. In this problem, it will be located where the random selection mode β€œleaves” it.

function chart in pascal

Function graph

You need to understand that the function graph in Pascal is built in two stages. First you need to build a coordinate system, and then draw the graph itself. Moreover, the first is also divided into several stages.

In order for the chart to not fit in full screen, you need to set its coordinates. The top corner is (xLeft; yLeft). The lower one is written in the same way - (xRight; yRight). In order to create coordinate axes, which in mathematics have well-known notation, you need to know the center. And to determine the latter, you need to understand how the argument and value of the function change. Having selected the necessary points, you can continue recording the program.

The graphics in Pascal implies the use of the SetPixel procedure, after which the coordinates of the point (the usual x and y) and the color (variable c) should be indicated in brackets. And the Line function allows you to draw the axis.

You need to write the program in this sequence: first, the coordinate system, and at the very end you need to calculate the value of the function and calculate the coordinates of the point.

graphics in pascal abc

Total

Displaying a point on the screen and plotting a function in Pascal are key points, so to speak, the basis of the entire section. Having learned to write programs for their execution, the programmer will be able to use graphics in its various versions. One should only know the theory well. The graphics in Pascal (examples are given in the article) are a very simple and interesting question.


All Articles