Tut­o­r­i­a­l 13

by Giselle Gray

Changing size/direction of mouse movement

  • Show Code
/** @peep sketch */
 
color brightPink = color(240, 39, 220);
color darkBlue = color(255, 255, 255);
color greenBright = color(51, 255, 51);
 
void setup() {
  size(200, 200);
  noStroke();
}
 
void draw() {
  background(255-16);
  float radius1 = 10 + mouseY / 2;
  float radius2 = 40 + (width - mouseY) / 2;
  fill(brightPink, 110);
  ellipse(width/2, mouseY, radius1, radius1);
  fill(greenBright, 150);
  ellipse(width/2, mouseY, radius2, radius2);
}

Playing with movement of mouse II

  • Show Code
/** @peep sketch */
void setup() {
  size(255, 255);
  background(255-16);
  stroke(0);
}
 
void draw() {
  float d = dist(pmouseX, pmouseY, mouseX, mouseY);
  if (d <= 100) {
    float r = (mouseX + mouseY)/10;
    float g = max(mouseX, mouseX);
    float b = 255 - max(mouseY, mouseY);
    float s = constrain(50-d, 2, 10);
    stroke(r, g, b, 255-16);
    strokeWeight(s);
    line(pmouseY, pmouseY, mouseX, mouseY);
  }
}

Playing with movement of mouse II

  • Show Code
/** @peep sketch */
void setup() {
  size(255, 255);
  background(255-16);
  stroke(255);
}
 
void draw() {
  float d = dist(pmouseX, pmouseY, mouseX, mouseY);
  if (d <= 100) {
    float r = (mouseX + mouseY)/10;
    float g = max(mouseX, mouseX);
    float b = 255 - max(mouseY, mouseY);
    float s = constrain(50-d, 100, 255);
    stroke(r, g, b, 255-16);
    strokeWeight(s);
    line(pmouseY, pmouseY, mouseX, mouseY);
  }
}

Creating an eraser: (right click for erasing)

  • Show Code
/** @peep sketch */
 
color lightBlue = color(66, 168, 237);
color darkBlue = color(0, 102, 153);
color eraser = color(255-16);
 
void setup() {
  size(200, 200);
  background(255-16);
}
 
void draw() {
  if (mousePressed) {
    if (mouseButton == LEFT) {
      stroke(darkBlue);
    } else if (mouseButton == RIGHT) {
      stroke(eraser);
      strokeWeight(10);
    }
    line(pmouseX, pmouseY, mouseX, mouseY);
  }
}

Comments

Nobody has said anything yet.