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.

Overloading methods

In this step, you will draw many X’s (the processing examples 6.4 - 6.9 from your lectures).

Coding the setup() method

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

Your display window should be 100x100 and have a light grey background.

Coding the drawX() method

Write a method called drawX that:

  • has a void return type
  • has an empty parameter list
  • sets the stroke to light grey
  • sets the weight of the stroke to 20
  • draws two lines that intersect in the shape of an X

Call this method from the setup() method.

When you run your code, it should look like this:

A light grey, heavy X

Save your work.

Coding a second drawX() method

With your Example_6_4 sketch open, perform a Save as… and enter the name Example_6_5.

To the existing code, write another method called drawX that:

  • has a void return type
  • accepts a parameter of type int
  • sets the stroke to the parameter
  • sets the weight of the stroke to 20
  • draws two lines that intersect in the shape of an X

In the setup() method, comment out the call to the previous draw method. Now call this method instead, passing the value of 0 as a parameter.

When you run your code, it should look like this:

A black, heavy X

Save your work.

Coding a third drawX() method

With your Example_6_5 sketch open, perform a Save as… and enter the name Example_6_6.

To the existing code, write another method called drawX that:

  • has a void return type
  • accepts two parameters of type int
  • sets the stroke to the first parameter
  • sets the weight of the stroke to the second parameter
  • draws two lines that intersect in the shape of an X

In the setup() method, comment out the call to the previous draw method. Now call this method instead, passing the value of 0, 30 as parameters.

When you run your code, it should look like this:

A black, really heavy X

Save your work.

Coding a fourth drawX() method

With your Example_6_6 sketch open, perform a Save as… and enter the name Example_6_7.

Write another method called drawX that:

  • has a void return type
  • accepts five parameters of type int
  • sets the stroke to the first parameter
  • sets the weight of the stroke to the second parameter
  • draws two lines that intersect in the shape of an X. The third parameter represents X, fourth represents Y and the fifth represents the size of the line.

In the setup() method, comment out the call to the previous draw method. Now call this method instead, passing the values: (0, 30, 40, 30, 35) as parameters.

When you run your code, it should look like this:

A black, really heavy X

Save your work.

Drawing multiple X’s

With your Example_6_7 sketch open, perform a Save as… and enter the name Example_6_8.

Using the most appropriate drawX method, reproduce the following output (you will have three individual method calls):

Three different X's

Save your work.

Drawing shadowed X’s

With your Example_6_8 sketch open, perform a Save as… and enter the name Example_6_9.

Using the most appropriate drawX method and a for or while loop, reproduce the following output:

Shadowed X's

Save your work.

Versioning Software

For our drawX project, you will notice that we now have 5 sketches, Example_6_4 to Example_6_9. This means that we have 5 different versions of the drawX project. As we incrementally worked on our drawX project and got a new method working, we saved off that work and starting working in a new file. This is a standard approach in programming and we will focus more on this approach throughout the course.