Dave Drohan (SETU)

BACK NEXT

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:

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.