OpenSource For You

Getting started with Processing

-

Java developers would find it easy to use Processing as the programmin­g style matches Java. Most of the object-oriented concepts can be used. There are two special functions in Processing, which are called internally: setup(): This function will be executed only once during the initial start of the sketch. Initial screen layout, UI initialisa­tion and other basic configurat­ions are done in this function. draw(): This will be called automatica­lly by Processing for each frame and it renders graphical animation. Apart from these two functions, there are many in-built core functions and event handlers to handle user actions and to design various shapes. All functions in Processing are straightfo­rward and the names are self-explanator­y. Refer to http://processing.org/reference/ for a detailed list of functions and their documentat­ion, along with examples.

Static sketch – ‘Hello World!’: In this example, let’s look at how to draw a static sketch. In Processing, you need X-Y pixel coordinate­s to draw the shapes. For example, to draw a line, you need two points with X-Y coordinate­s. Similarly, to draw a rectangle or ellipse, you need four points with X-Y coordinate­s.

size(400,400); int widthLen = width/2; int heightLen = height/2-100; rectMode(CENTER); rect(widthLen, heightLen + 75, 60, 100); line(widthLen,heightLen+20, widthLen+80, heightLen+80); line(widthLen,heightLen+20, widthLen-80, heightLen+80); ellipse(widthLen-55,heightLen-5,12,25); ellipse(widthLen+55,heightLen-5,12,25); ellipse(widthLen,heightLen,100,100); ellipse(widthLen-25,heightLen-7,25,12);

 ??  ?? Figure 1: Processing PDE
Figure 1: Processing PDE

Newspapers in English

Newspapers from India