Course Info

#Programming Fundamentals 1

This is an introductory Programming module and assumes no prior knowledge of programming.

In this module, we will introduce you to the Java programming language through the Processing Development Environment (PDE) and then IntelliJ.

First, we will work through non-complex problems that will introduce you to the basic constructs of programming languages i.e. Sequence, Selection and Loops. You will also learn to use variables, different data types, manipulate the data, logical operators and methods. This will be done using processing.org

Then, using IntelliJ, we will progress to more complex problems that will briefly introduce you to object-oriented programming and data structures. You will do a deeper dive into both of these areas in the semester 2 module, Programming Fundamentals 2.

Abstracting code to a method

In this step, you will draw many eyes (the examples 6.1 - 6.3 from your lectures).

Coding the setup() method

Create a new Processing sketch in your workspace and call it Example_6_1.

Your display window should be 100x100. Write the line of code that will ensure all subsequent shapes are drawn with no outline.

Coding the draw() method

Include the following code in your sketch:

void draw()
{
  background(204);
  fill(255);
  ellipse(50,50,60,60);    //outer white circle
  fill(0);
  ellipse(50+10, 50, 30, 30);  //black circle
  fill(255);
  ellipse(50+16, 46, 6, 6);  //small, white circle
}

Run your code; a single eye should be drawn.

Save your work.

Drawing two eyes

With your Example_6_1 sketch open, perform a Save as… and enter the name Example_6_2.

Now refactor the code above so that you have a method called eye. This method should:

  • accept two parameters of type int, representing the x and y coordinates of the eye.
  • have a void return type.

Call the eye method twice from the draw method so that your display window is rendered like so:

2 Eyes

Save your work.

Drawing six eyes

With your Example_6_2 sketch open, perform a Save as… and enter the name Example_6_3.

Now refactor the code to call the eye method six times from the draw method so that your display window is rendered like so:

6 Eyes

Save your work.