//PCS sixth grade inequalities code - K. Hicks (undersupervision of Z. Wood) //students can set the value of ranges to create patterns //students use the methods: xGreaterThan(some number, color) and the //similar commands for xLessThan, yGreaterThan and yLessThan to make //patterns //For drawing normal shapes (ellipse) - use centeredX(0) and centeredY(0) to //map your points into this more "normal" math grid 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(50, color(0, 255, 0)); //and this makes a red-ish area on the top for y values above 150 yGreaterThan(150, color(255, 0, 0)); yLessThan(100, color(255, 255, 0)); //TODO - also you can use //yLessThan(some number, some color); //xLessThan(some number, some color)); //draw an ellipse at the center of the math grid fill(128); ellipse(centeredX(0), centeredY(0), 20, 20); //you can also draw ellipse at the intersections of the regions ellipse(centeredX(50), centeredY(150), 10, 10); } 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 */ } void setup() { //size(screen.width, screen.height); size(800, 800); } 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(); }