//PCS sixth grade velocities and inequalities to build an animation //For drawing normal shapes (ellipse) - use centeredX(0) and centeredY(0) to //map your points into this more "normal" math grid //variables to move the face int vx, vy; int px, py; void setup() { //size(screen.width, screen.height); size(800, 800); vx = 1; vy = 0; } void draw() { //intersect union background(255); drawCoordinateSystem(); //TODO add some inequalities to make patterns - for example //this command makes a green area to the right for x values above 50 xGreaterThan(150, color(0, 255, 0)); xLessThan(-150, color(0, 255, 0)); yGreaterThan(150, color(0, 255, 0)); //TODO add the bottom - pick a yValue //yLessThan(yValue, color(0, 255, 0)); //update the postition of the face using velocity px = px + vx; py = py + vy; //draw a face at the center of the math grid fill(34, 34, 128); ellipse(centeredX(px), centeredY(py), 40, 40); fill(255); ellipse(centeredX(px - 10), centeredY(py+5), 10, 10); ellipse(centeredX(px + 10), centeredY(py+5), 10, 10); //you can add more shapes or lines to make a face //ellipse(centeredX(px), centeredY(py), 2, 2); //stroke(255); //line(centeredX(px-3), centeredY(py-5), centeredX(px+3), centeredY(py-5)); //noStroke(); //logic to change the direction the face is traveling //if the face hits the right wall, start going up if (px > 150) { vx = 0; vy = 1; px = 150; } //TODO add logic to change the face direction if it hit the top //TODO add logic to change the direction if hits the left //TODO add logic to change the direction if hits the bottom } void xLessThan(int value, color col) { fill(red(col), green(col), blue(col), 64); float minX = 0; float minY = 0; float maxX = min(centeredX(value), width); float maxY = height; quad(minX, minY, /* bottom left */ minX, maxY, /* top left */ maxX, maxY, /* top right */ maxX, minY); /* bottom right */ } void xGreaterThan(int value, color col) { fill(red(col), green(col), blue(col), 64); float minX = max(centeredX(value), 0); float minY = 0; float maxX = width; float maxY = height; quad(minX, minY, /* bottom left */ minX, maxY, /* top left */ maxX, maxY, /* top right */ maxX, minY); /* bottom right */ } void yLessThan(int value, color col) { fill(red(col), green(col), blue(col), 64); float minX = 0; float minY = height; // inverted y float maxX = width; float maxY = max(centeredY(value), 0); // inverted y quad(minX, minY, /* bottom left */ minX, maxY, /* top left */ maxX, maxY, /* top right */ maxX, minY); /* bottom right */ } void yGreaterThan(int value, color col) { fill(red(col), green(col), blue(col), 64); float minX = 0; float minY = min(centeredY(value), height); // inverted y float maxX = width; float maxY = 0; // inverted y quad(minX, minY, /* bottom left */ minX, maxY, /* top left */ maxX, maxY, /* top right */ maxX, minY); /* bottom right */ } float centeredX(float x) { return x + width/2.0; } float centeredY(float y) { //return y + height/2.0; return (height - y) - height/2.0; } void drawCoordinateSystem() { stroke(0); strokeWeight(1); int lineLength; int tickMark = 0; for (int x = (int) 0; x < (int)width / 2; x += 10, tickMark++) { lineLength = 2; if (tickMark == 5) { lineLength = 5; tickMark = 0; } if (width/2 - x > 0) { line(width/2 - x, height/2 - lineLength, width/2 - x, height/2 + lineLength); } if (width/2 + x < width) { line(width/2 + x, height/2 - lineLength, width/2 + x, height/2 + lineLength); } } tickMark = 0; for (int y = (int) 0; y < (int)height / 2; y += 10, tickMark++) { lineLength = 2; if (tickMark == 5) { lineLength = 5; tickMark = 0; } if (height/2 - y > 0) { line(width/2 - lineLength, height/2 - y, width/2 + lineLength, height/2 - y); } if (height/2 + y < height) { line(width/2 - lineLength, height/2 + y, width/2 + lineLength, height/2 + y); } } line(0, height/2.0, width, height/2.0); line(width/2.0, 0, width/2.0, height); noStroke(); }