Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Let's take the Example 1 and expand it to use events:

Code Block
int length1 = 0;
int length2 = 0;

void setup() {
  size(300, 300); // define window size
  background(0); // define background colour
  stroke(255, 255, 255); // define }line colour
}
void draw() {
  background(0);
  length1 = mouseX;
   strokeWeight(1)length2 = mouseY;
  line(100, 10, 100,150 length1); // draw a line
  line(150, 10, 150,200 length2);
  line(200, 10, 200, 250);


  fill(0, 0, 0); // fill colour
  strokeWeight(5); // line thickness
  ellipse(100,150 length1, 50, 50); // draw an ellipse
  ellipse(150,200 length2, 50, 50); // draw an ellipse
  noFill(); // turn off fill
  ellipse(200, 250, 50, 50); // draw an ellipse
}


In this program we use two special functions:

...