Dave Drohan (SETU)

BACK NEXT

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:

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:

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:

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:

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.