CSC 108 – Program 1 Even

Assignment:

Write a Processing program that draws a white circle at the mouse position in a drawing window that is sized 700 x 500 pixels, and draws a red circle that tracks the position of the center of the circle, wherever it moves in the drawing window, slowly catching up to its position.

Starting Point:

To get started on this assignment, make a new Processing sketch, then copy Example 2-2 from Chapter 2 of the text into the editor.

Example 2-2:
void setup() {
  size(480, 120);
}

void draw() {
  if (mousePressed) {
    fill(0);
  } else {
    fill(255);
  }
  ellipse(mouseX, mouseY, 80, 80);
}

Next, change the parameters in the size function so that the screen size is correct for this problem. Then delete all of the lines inside the draw function EXCEPT for the last one (the “ellipse(mouseX, mouseY, 80, 80);” line). If you run the program now, you should see a bunch of circles being drawn over one another.

Paste the following code as the first lines that are inside the curly braces of your draw function:

        // clear screen and set background color
        background(204);

        // set filling color for circle at mouse position
        fill(255);

If you run the program now, the trail of circles won’t be there; only one circle should be drawn, with its center at the mouse position.

Your Task:

You need to add code to the draw function of your program that will draw a red circle, who’s position will be adjusted by some value porportional to the difference between it and the cursor’s (white circle) position. Comment Header at the Top of your Program: Place a comment header at the top of your program similar to this example, with information specific to you and your assignment:

/********************************
 * CSC 108
 * Programming Assignment # 1
 * Author: Bill Gates
 * Date: January 21, 2022
 ********************************/