Introducing Processing 1.0
The purpose of writing this topic is to introduce you to the wonderful language Processing . This PL cannot boast of wide functionality or rich expressive means, but it is able to offer something else ...
So, processing is a java based programming language with a simple and clear si-like syntax.
Processing makes it possible to quickly and easily create multimedia applications (in the terminology of processing - sketches). By multimedia, I mean language tools that allow you to develop graphics, animation, varied visualizations, interactive applications ...
In principle, nothing prevents even creating 3D applications (including games), because processing has OpenGL support. All these features, coupled with a large number of functions and a very logical syntax, make this language ideal for learning and instilling an interest in programming.
Knowing full well that a picture is worth a thousand words, I want to introduce a couple of examples of visualization created in processing:
Procesing 1.0 is free, open source, cross-platform software.
The source archive includes a java machine, the interpreter itself, a mini-IDE, and several dozen examples. Versions for different platforms are available on the download page (all links at the end of the topic).
After downloading and unpacking the archive, you need to find the executable file in the root directory that launches the IDE, in which you can and should write code.
Everything is ready to go!
I did not set myself the task of teaching someone the basics of this language. This is not necessary, because on the offsite, in addition to the detailed manual, there are several articles in which it is very accessible, in simple English, all the basics and features of working with processing are explained. Everything is described in great detail, there are even illustrations. Also at your service is an extensive community, represented by a forum with tens of thousands of posts.
Therefore, I will focus only on a few points that beginners should know about. To tell you the truth, I myself am still a complete beginner, but I have already learned something and am in a hurry to share it.
So, let's start with the main thing - with the language syntax.
In my opinion, he is very like a classic si. So if you have experience working with languages such as C, PHP, JavaScript, etc, then you can assume that you practically know processing - so many language constructs, operators, loops look exactly the same.
We will deal with terminology.
Sketch is the source file of your program.
Sketchbook - a directory containing source files, resource files, etc. In short, everything related to one project.
PDE - Processing Development Environment. Native language development environment.
Once again about the possibilities
Before I start looking at the code examples, I want to once again mention the possibilities that processing offers us.
So, we have at our disposal tools for constructing graphic primitives, 3D objects, working with light, text, and transformation tools. We can import and export audio / video / sound format files, handle mouse / keyboard events, work with third-party libraries (openGL, PDF, DXF), work with the network.
This is what PDE looks like in Windows XP:
The result of the program:
We write a hello world
Finally we got to the most important thing - the first code example. An analogue of the classic "hello, world" we will have this code:
The line function takes four arguments and draws a line in the two-dimensional plane with the coordinates specified in the arguments, with the default color and thickness. Arguments in the order of use: x1, y1, x2, y2 - coordinates of the start and end points.
Actually, almost all problems are solved in this language in the same simple ways. For 3D objects, the Z axis is naturally added.
Although processing is a very simple language that allows a lot of liberties, but if we want to write a good program, we need to follow some conventions.
So, for example, all initialization functions: size () - window size, stroke () - line color, background () - background color, and some others, must be placed inside the special service function void setup () . It is recommended to write it first.
The next utility function is void draw () . Its counterpart can be called int main () in C ++.
This function is the basis for building any animation. Its feature is that it is automatically called every time the framebuffer is updated.
The last agreement is related to the positioning of objects in the coordinate plane.
After initializing the window size with the setup () function , two global constants become available inside the program - WIDTH and HEIGHT, which store the width and height of the window, respectively. Every time you want to position, say, a circle in the center of the screen, use the following entry:
Anticipating possible exclamations, like "Why is this processing better than the same Adobe Flash / Microsoft Silverlight etc ...".
First: This is a great free and open source alternative. Moreover, the result of your work can be converted into a Java applet and inserted into a web page.
Secondly: the developers themselves have already answered this question in their FAQ . I can not help but quote one paragraph from there:
I repeat once again: processing is very well suited for training - there is nothing superfluous in it, and the result is accessible quickly and very clearly. I think this language is not a means of serious development, but just an interesting hobby that allows you to relax and distract from the main work.
What is it?
So, processing is a java based programming language with a simple and clear si-like syntax.
Processing makes it possible to quickly and easily create multimedia applications (in the terminology of processing - sketches). By multimedia, I mean language tools that allow you to develop graphics, animation, varied visualizations, interactive applications ...
In principle, nothing prevents even creating 3D applications (including games), because processing has OpenGL support. All these features, coupled with a large number of functions and a very logical syntax, make this language ideal for learning and instilling an interest in programming.
Knowing full well that a picture is worth a thousand words, I want to introduce a couple of examples of visualization created in processing:
How to start
Procesing 1.0 is free, open source, cross-platform software.
The source archive includes a java machine, the interpreter itself, a mini-IDE, and several dozen examples. Versions for different platforms are available on the download page (all links at the end of the topic).
After downloading and unpacking the archive, you need to find the executable file in the root directory that launches the IDE, in which you can and should write code.
Everything is ready to go!
Fast start
I did not set myself the task of teaching someone the basics of this language. This is not necessary, because on the offsite, in addition to the detailed manual, there are several articles in which it is very accessible, in simple English, all the basics and features of working with processing are explained. Everything is described in great detail, there are even illustrations. Also at your service is an extensive community, represented by a forum with tens of thousands of posts.
Therefore, I will focus only on a few points that beginners should know about. To tell you the truth, I myself am still a complete beginner, but I have already learned something and am in a hurry to share it.
So, let's start with the main thing - with the language syntax.
In my opinion, he is very like a classic si. So if you have experience working with languages such as C, PHP, JavaScript, etc, then you can assume that you practically know processing - so many language constructs, operators, loops look exactly the same.
We will deal with terminology.
Sketch is the source file of your program.
Sketchbook - a directory containing source files, resource files, etc. In short, everything related to one project.
PDE - Processing Development Environment. Native language development environment.
Once again about the possibilities
Before I start looking at the code examples, I want to once again mention the possibilities that processing offers us.
So, we have at our disposal tools for constructing graphic primitives, 3D objects, working with light, text, and transformation tools. We can import and export audio / video / sound format files, handle mouse / keyboard events, work with third-party libraries (openGL, PDF, DXF), work with the network.
This is what PDE looks like in Windows XP:
The result of the program:
We write a hello world
Finally we got to the most important thing - the first code example. An analogue of the classic "hello, world" we will have this code:
- line(25, 100, 125, 100);
What this function does, I think, needs no explanation. But just in case, I’ll tell :) The line function takes four arguments and draws a line in the two-dimensional plane with the coordinates specified in the arguments, with the default color and thickness. Arguments in the order of use: x1, y1, x2, y2 - coordinates of the start and end points.
Actually, almost all problems are solved in this language in the same simple ways. For 3D objects, the Z axis is naturally added.
Initial initialization
Although processing is a very simple language that allows a lot of liberties, but if we want to write a good program, we need to follow some conventions.
So, for example, all initialization functions: size () - window size, stroke () - line color, background () - background color, and some others, must be placed inside the special service function void setup () . It is recommended to write it first.
The next utility function is void draw () . Its counterpart can be called int main () in C ++.
This function is the basis for building any animation. Its feature is that it is automatically called every time the framebuffer is updated.
The last agreement is related to the positioning of objects in the coordinate plane.
After initializing the window size with the setup () function , two global constants become available inside the program - WIDTH and HEIGHT, which store the width and height of the window, respectively. Every time you want to position, say, a circle in the center of the screen, use the following entry:
- ellipse(WIDTH/2, HEIGHT/2, 50, 50);
Here is an example of a small program written using conventions:- void setup() {
- size(400, 400);
- stroke(255);
- background(192, 64, 0);
- }
-
- void draw() {
- line(150, 25, mouseX, mouseY);
- }
The mouseX and mouseY functions return the current coordinates of the mouse cursor. Thus, with each movement of the mouse new lines will be drawn. It looks like this:In the end
Anticipating possible exclamations, like "Why is this processing better than the same Adobe Flash / Microsoft Silverlight etc ...".
First: This is a great free and open source alternative. Moreover, the result of your work can be converted into a Java applet and inserted into a web page.
Secondly: the developers themselves have already answered this question in their FAQ . I can not help but quote one paragraph from there:
There are things that are always going to be better in Flash, and other types of work that will always be better in Processing. But fundamentally (and this cannot be emphasized enough), this is not an all-or-nothing game ... We're talking about tools. Do people refuse to use pencils because pens exist? No, you just use them for different things, and for specific reasons. If Processing works for you, then use it. If not, don't. It's easy! It's free! You're not being forced to do anything.And indeed: these are different things, different tools, each of which is suitable for its own purposes. So no holivars, please.
I repeat once again: processing is very well suited for training - there is nothing superfluous in it, and the result is accessible quickly and very clearly. I think this language is not a means of serious development, but just an interesting hobby that allows you to relax and distract from the main work.