IPPJ-Introduction to Programming with Processing Lesson

Introduction to Programming with Processing

Most programming languages come with a prewritten set of methods and functions that are kept in a library called an API. In computer programming, an API is an Application Programming Interface that contains a set of routines, protocols, and tools that explain the syntax for building software applications with that particular programming language. The Processing Reference Links to an external site. explains every pre-defined function and code element with a description and example of the syntax. There, you can browse all the available functions by category or alphabetically.  

We will begin by exploring some of the basic functions used for drawing in Processing.  

What is a function?  

In programming, a function performs a specific task. In this sense, a function is a type of procedure or routine for doing something.  

Functions have a name followed by a set of arguments enclosed in parentheses. The arguments are values that the method needs in order to execute. These values are passed through the parameter to the function.  

Let's look at the function in Processing to draw a line.

function, lin (x1,y1,x2,y2); ends with a smicolon

The name of the function is line. Notice it starts with a lowercase letter. The x1, y1 represent the beginning x and y location on the coordinate grid. The x2 and y2 represent the ending x and y location on the coordinate grid. They are inside parentheses. This area is called the parameter. When you pass a value through the parameter the value is called an argument.  

Notice how the function line(1, 4, 6, 7);   is represented on the coordinate grid.  

coordinate grid showing the graphing

The beginning x1 and y1 are at (1, 4) the ending x2 and y2 are at (6, 7).  1, 4, 6, 7 are all arguments passed through the parameter to the line method.

Each function call always ends with a semicolon. This is the only time a function is followed with a semicolon.

The Processing library consists of many pre-made functions that make it easy to create basic shapes.

Functions to Draw Primitive Shapes in Processing Activity

Let's examine the functions used to create the four primitive shapes. Do not skip the Learning Object below.  You will need this information in the next assignment!  Make sure to click the arrow beneath the learning object so you see ALL the shapes!

There is one more function you need to understand before you start coding.      

size(x, y);  This function will size the frame for sketching. Since computers read instructions sequentially, this will need to be the first instruction in your program.  

[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION