Project 4

What could you do with the absolute value of your position? TEKS Standards 1G and 2A

// Declare that you want to use variables.
float middleX;
float middleY;
float distanceY;
float absoluteDistanceY;
float rectWidth;
float rectHeight;

// Set the size of your drawing canvas and
// initialize your variables.
void setup() {
  size(500, 500);
  rectMode(CENTER);
  noStroke();
  middleX = width/2;
  middleY = height/2;
  distanceY = 0;
  absoluteDistanceY = distanceY;
  rectWidth = absoluteDistanceY;
  rectHeight = 2;
  background(255, 255, 255);
}

// Resize the width of a rectangle based
// on your mouse/touch position.
void draw() {
  distanceY = mouseY - middleY;
  if (distanceY >= 0) {
    absoluteDistanceY = distanceY;
  } else {
    absoluteDistanceY = -distanceY;
  }
  rectWidth = absoluteDistanceY;
  pushMatrix();
  // Adjust x-axis to properly mimic
  // horizontal shifts
  scale(-1, 1);
  translate(-width, 0);
  // Blue rectangles
  fill(0, 0, 255);
  rect(middleX - 50, mouseY, rectWidth, rectHeight);
  // Red rectangles
  fill(255, 0, 0);
  rect(middleX + 50, mouseY, rectWidth, rectHeight);
  // Green rectangles
  fill(0, 255, 0);
  rect(middleX, mouseY, rectWidth, rectHeight);
  popMatrix();
}

/**
 * What do adding and subtracting from middleX do
 * to the absolute value graphs?
 *  
 *  
 *  
 */

All source code is licensed under the MIT License. Text and images are free to remix under the terms of a Creative Commons Attribution 4.0 International License.