ComputersProgramming

Graphics in Pascal: features, ways of creating and examples

Do programmers need graphics? Especially for those who have just started learning 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, those who teach the programming language within the school course, the graphics in "Pascal" will be an excellent way to encourage themselves to further learning. After all at this time I want to see the results of my thinking, writing programs. If it is already a student, then the graphics have a different purpose. It rather acts as an auxiliary element, which helps make the written products more dynamic. But in any case, this section of the programming language, of course, is important.

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

Graphics in Pascal

Where should we begin? From what you need to understand, what is the minimum unit of the screen in different modes of the Pascal language. If it is a text, then this will be a symbol. In the graphics, they are represented by a pixel. It has its coordinates, which are represented by the symbols X and Y, and also the color (standard - white). In order for the pixel to get the address (0; 0), it needs to be located in the upper left corner. It is from here that the coordinates begin to be measured.

The graphics in Pascal ABC are enabled using a module that you need to register in the uses line.

Dot

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

In the descriptions section, you can see the names of the modules written in the uses line. They include the graphical mode in the program. If the developer has already familiarized himself with the structure of the programs, he may think that in var it is necessary to simply write the auxiliary variables. But this section, like the graphics in Pascal, works somewhat differently. After the word var, you need to write the video adapter installed on the PC, and then specify in which mode it works. These designations are generally accepted. After opening the operator brackets, the actual type and mode should be noted. If the user does not know which adapter is installed, then you need to write in your program line number 7. This section, like the graphics in Pascal, is designed 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 meaning, for each one you can find out by looking on the Internet. In the eighth line you can see the procedure Initgraph. It starts the graphical mode. Lines Nos. 9 and 10 are needed in order that if the initialization fails, the program stops working. The closegraph function closes the graphical mode, allowing you to switch back to text mode.

The lines under numbers 2, 3, 7-10, 17 should be remembered, because they can be used as a template, since all the graphics in Pascal have a common creation structure. Let us consider other elements of the problem.

Under the variable color you need to understand the range of colors, in Pascal there are only 15. Assigning the 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 task, it will be located where it is "left" by a random selection mode.

Function graph

It should be understood that the schedule of the function in Pascal is built in two stages. First you need to build a coordinate system, and then draw the graph itself. And the first is also divided into several stages.

To ensure that the graph does not fit into the full screen, you need to specify its coordinates. The upper 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 known notations, it is necessary to know the center. And to determine the latter, you need to understand how the argument and the value of the function change. After selecting the necessary points, you can continue recording the program.

The graphics in Pascal involve 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 parentheses. And the Line function lets you draw axes.

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.

The result

The output of the point on the screen and the construction of the graph of the function in Pascal are the key moments, so to speak, the base of the whole section. Having learned how to write programs to execute them, the programmer can use the graphics in various ways. You just need to know the theory well. The graphics in Pascal (examples are given in the article) is a very simple and interesting question.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.unansea.com. Theme powered by WordPress.