Week 8

by Miranda Phillips

Tutorial 15: Interaction 1 - Mouse

  • Show Code
/** @peep sketch */
color lightBlue = color(66, 168, 237);
 
void setup() {
  size(200, 200);
  noStroke();
}
 
void draw() {
  background(245);
  fill(lightBlue);
  ellipse(mouseX/1.5, mouseY/1.5, 20, 20);
  ellipse(mouseX/2.5, mouseY/2.5, 15, 15);
  ellipse(mouseX/3.5, mouseY/3.5, 10, 10);
  ellipse(mouseX/4.5, mouseY/4.5, 10, 10);
}
  • Show Code
/** @peep sketch */
 
color lightBlue = color(66, 168, 237);
color darkBlue = color(0, 102, 153);
color orange = color(204, 102, 0);
 
int spacing = 20;
int length = 15;
 
void setup() {
  size(200, 200);
  noStroke();
}
 
void draw() {
  background(255-16);
  for (int x = 10; x < width; x += spacing) {
    for (int y = 10; y < width; y += spacing) {
      float distance = dist(mouseX, mouseY, x, y);
      if (distance < length) {
        fill(darkBlue);
      } else {
        fill(lightBlue);
      }
      float factor = map(distance, 0, width, 1.3, 0.3);
      pushMatrix();
      translate(x, y);
      scale(factor);
      rotate(factor*(-2));
      rect(0, 0, length, length);
      popMatrix();
      }
    }
  }
  • 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 <= 40) && (mousePressed)) {
    float r = (mouseX + mouseY)/2;
    float g = max(mouseX, mouseY);
    float b = 255 - max(mouseX, mouseY);
    float s = constrain(10-d, 2, 10);
    stroke(r, g, b, 255-16);
    strokeWeight(s);
    ellipse(pmouseX, pmouseY, mouseX, mouseY);
  }
}
  • Show Code
/** @peep sketch */
 
color lightBlue = color(66, 168, 237);
color darkBlue = color(0, 102, 153);
color orange = color(204, 102, 0);
 
void setup() {
  size(200, 200);
  background(255-16);
}
 
void draw() {
  if (mousePressed) {
    if (mouseButton == LEFT) {
      stroke(darkBlue);
    } else if (mouseButton == RIGHT) {
      strokeWeight(10);
      stroke(255-16);
    }
    line(pmouseX, pmouseY, mouseX, mouseY);
  }
}
  • Show Code
/** @peep sketch */
 
color lightBlue = color(66, 168, 237);
color darkBlue = color(0, 102, 153);
color orange = color(204, 102, 0);
color backgroundColor = color(204, 102, 0);
 
int radius = 100;
color fillColor = lightBlue;
 
void setup() {
  size(200, 200);
}
 
void draw() {
  background(255-16);
  strokeWeight(4);
  float distance = dist(mouseX, mouseY, width/2, height/2);
  if (mousePressed && distance < radius/2) {
    fill(lightBlue);
    background(backgroundColor);
  } else {
    fill(lightBlue);
  }
  ellipse(width/2, height/2, radius, radius);
}

Comments

Nobody has said anything yet.