Visual applications with Processing and Java

What is Processing

Processing is a programming language based on Java, tailored for visual applications

The objective is to quickly sketch some idea an produce something that other people can understand

Drawing pretty stuff

What is Processing

Processing is a programming language based on Java, tailored for visual applications

The objective is to quickly sketch some idea an produce something that other people can understand

Visualizing data

What is Processing

Processing is a programming language based on Java, tailored for visual applications

The objective is to quickly sketch some idea an produce something that other people can understand

Plotting mathematical functions

What is Processing

Processing is a programming language based on Java, tailored for visual applications

The objective is to quickly sketch some idea an produce something that other people can understand

Simulating Newton's gravitation laws

What is Processing

Processing is a programming language based on Java, tailored for visual applications

The objective is to quickly sketch some idea an produce something that other people can understand

Simulating Artificial Intelligence ( Little robots following a path while avoiding each other )

The Processing Interactive Development Environment (IDE)

Go get it at https://processing.org/download/

We will review most of the COMP 202 Java concepts within this Processing window

Processing

Processing is a programming language based on Java

It facilitates building graphical user interfaces ( GUI ), by abstracting some of the lower level concepts from Java

Moving on from our console ( text input and output ) applications

Hello world in Java

Hello world in Processing

Pixel coordinate system

Going back to Assignment 2

Pixel coordinate system

Going back to Assignment 2

point(x,y) draws a point centered at pixel coordinates (x,y)

strokeWeight(pixels) lets you set the size of the point

Shapes

Drawing a line

line(x1,y1,x2,y2) draws a line segment from (x1,y1) to (x2,y2)

Shapes

Drawing a rectangle

rect(x,y,w,h) draws a rectangle whose top left corner is at (x,y) and its size is w by h pixels

Shapes

Drawing an ellipse

ellipse(x,y,w,h) draws an ellipse centered at (x,y) with a size of w by h pixels

Color

stroke(val) sets the color of lines to val in grayscale

fill(val) sets the color inside a shape to val in grayscale

background(val) sets the color of the background to val in grayscale

Color

stroke(r,g,b) sets the color of lines to r,g,b in the red-green-blue scale

fill(r,g,b) sets the color inside a shape to val in the red-green-blue scale

background(r,g,b) sets the color of the background to val in red-green-blue scale

Interaction

Making things animated and interactive

In Processing this is managed by two methods

Interaction

Making things animated and interactive

In Processing this is managed by two methods

The speed of the drawing loop can be set with the frameRate(fps), where fps is the desired number of frames per second

Interaction

Making things animated and interactive

The simplest kind of interaction that we get from Processing is keyboard and mouse input

Interaction

Making things animated and interactive

We can manage all the key presses outside the drawing loop

Using Objects and Classes in Processing

Processing is based on Java, so we can use all of the things we learned during the COMP 202. Let's create a program that draws robots with the following rules:

Some additional rules

  • All the Robot instances are attracted towards the location of the mouse pointer.

  • Robot instances hate each other: add a repelling force between Robot instances that keeps them apart.

Next class

Now that we can draw stuff on a screen and animate it, we're going to:

Resources

/