Unit 2 – LA 1 – 1.1

Although I have already worked with if else statements before this chapter went in on that, so again this has been easy. We had to work with the statements and change the colors depending on the mouse position. We had 2 exercises:

var b;
function setup() {
  createCanvas(400, 400);
}


function draw() {


  if (mouseX > 200) {
    background(225, 0, 0);
  } else {
    background(0, 0, 225);
}
  noStroke();
  rect(160, 160, 80, 80);
  if (mouseX > 200) {
    fill(0, 0, 225);
  } else {
    fill(225, 0, 0);
  }
  rect(160, 160, 80, 80);
}
var x, y;
function setup() {
  createCanvas(400, 400);
}

function draw() {
  if (mouseX > 200) {
    background(0, 0, 225);
  } else {
    background(225, 0 , 0);
  }
  noStroke();
  if (mouseX > 200) {
    fill(225, 0, 0);
  } else {
    fill(0, 0, 225);
  }
  if (mouseY < 200) {
    y = 275;
  } else {
    y = 75;
  }
  if (mouseX < 200) {
    x = 275;
  } else {
    x = 75;
  }
  rect(x, y, 50, 50);
}