top of page

How to use processing: The basics

  • Karla G
  • 27 mar 2015
  • 3 Min. de lectura

In this post we will learn a little bit about the programming of computer graphics.

In processing you can get to do something like this:

tree.png

Or even like this:

face_test.png

But for now, we have to start from the easiest forms. In this tutorial we will draw a pyramid in a 3D plane. The first thing you have to do in processing is opening the setup.

void setup(){

}

Inside the setup we must call the variables that will be used in different methods and also set the configurations of the processing output window.

The size of the window:

size(500,500,P3D);

500 is the number of pixels that the window will have of height and width. The term "P3D" defines that the window will have a 3D plane with 3D figures. There will be a x,y and z axis.

The camera:

For setting the camera, we have this variables:

float fov = PI/3.0;

// This is a variable of type float called fov. It has a value of PI/3.0;

float cameraZ = (height/2.0) / tan(fov/2.0);

// The variable cameraZ depends on the height of the window

What is perspective?

"Sets a perspective projection applying foreshortening, making distant objects appear smaller than closer ones. The parameters define a viewing volume with the shape of truncated pyramid. Objects near to the front of the volume appear their actual size, while farther objects appear smaller. This projection simulates the perspective of the world more accurately than orthographic projection."

This is the specific meaning found in processing.org.

Now that you know this, you can imagine what the next line does:

perspective(fov, float(width)/float(height), cameraZ/100.0, cameraZ*10.0);

// The perspective will depend in the width and height of the window.

Now we have a setup that looks like this:

void setup(){

float fov=PI/3.0;

float cameraZ= (height/2.0) / tan(fov/2.0);

perspective(fov, float(width)/float(height), cameraZ/100.0, cameraZ*10.0);

}

Now, we create another method, called draw. In this method of type void, the drawings will be set and created.

void draw(){

}

As you can see in the bottom pictures, processing is based in lines and TRIANGLES. This triangles are like the basic unit of the drawings that are made in processing with a 3D plane.

Inside the void draw() a color for the background will be set:

background(0,0,0); //Black

Then the camera will be called to the method.

camera(50*mouseX/500.0, -50*mouseY/500.0,40, 0,0,0, 0,1,0);

// This sets the mobility of the camera with the mouse over the axis X and Y

Now the interesting part, drawing:

beginShape(TRIANGLES);

//Now you can draw triangles

How can you draw them? Easy:

In order to do a figure it has to be separated in triangles. You have to know how many triangles and vertices a figure has.

After separating the figure in triangles, you have to locate each vertex of each triangle.

The triangles will be drawn vertex by vertex in groups of three (for each vertex of a triangle)

Here is a pyramid:

vertex(25,0,0);

vertex(12.5,0,12.5);

vertex(0,0,0);

vertex(0,0,0);

vertex(12.5,0,12.5);

vertex(12.5,20,6.25);

vertex(12.5,0,12.5);

vertex(25,0,0);

vertex(12.5,20,6.25);

vertex(25,0,0);

vertex(0,0,0);

vertex(12.5,20,6.25);

Finally you just have to end the shape of triangles:

endShape();

Now, this is how the void draw looks completely:

void draw(){

background(0,0,0);

camera(50*mouseX/500.0, -50*mouseY/500.0,40, 0,0,0, 0,1,0);

noFill();

stroke(255,255,255);

beginShape(TRIANGLES);

vertex(25,0,0);

vertex(12.5,0,12.5);

vertex(0,0,0);

vertex(0,0,0);

vertex(12.5,0,12.5);

vertex(12.5,20,6.25);

vertex(12.5,0,12.5);

vertex(25,0,0);

vertex(12.5,20,6.25);

vertex(25,0,0);

vertex(0,0,0);

vertex(12.5,20,6.25);

endShape();

}

My final product:

Captura de pantalla 2015-03-27 a las 16.14.06.png

References:

Processing. (2001). Processing. 24 Marzo 2015, de Processing.org Sitio web: https://processing.org/

 
 
 

Comentários


 THE ARTIFACT MANIFAST: 

 

This is a great space to write long text about your company and your services. You can use this space to go into a little more detail about your company. Talk about your team and what services you provide. Tell your visitors the story of how you came up with the idea for your business and what makes you different from your competitors. Make your company stand out and show your visitors who you are. Tip: Add your own image by double clicking the image and clicking Change Image.

 UPCOMING EVENTS: 

 

10/31/23:  Scandinavian Art Show

 

11/6/23:  Video Art Around The World

 

11/29/23:  Lecture: History of Art

 

12/1/23:  Installations 2023 Indie Film Festival

 FOLLOW THE ARTIFACT: 
  • Facebook B&W
  • Twitter B&W
  • Instagram B&W
 RECENT POSTS: 
 SEARCH BY TAGS: 

© 2023 by Karla Lugo. Proudly created with Wix.com

bottom of page