Last active
August 29, 2015 13:56
-
-
Save Arty2/8955516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The object was to create a grading set of illusionist tiles. | |
Horizontal mouse movement sets hue. Vertical sets saturation. Scroll to increase/decrease tile count. | |
*/ | |
int sketchWidth = 600; | |
int sketchHeight = sketchWidth; | |
int grid = 6; //number of triangle columns and rows | |
int shapeWidth, shapeHeight; | |
int offset = 2; //to-do | |
int count = 0; | |
float x1, y1, x2, y2, x3, y3, x4, y4, w, h, hue, sat, bright; | |
void mouseWheel(MouseEvent event) { | |
float e = event.getAmount(); | |
if (e > 0 && grid < 100) { | |
grid++; //increase tiles on scroll down | |
} | |
else if (e < 0 && grid > 2) { | |
grid--; //decrease tiles on scroll up | |
} | |
} | |
void setup() { | |
size(sketchWidth, sketchHeight); | |
colorMode(HSB, 100); | |
background(hue, sat, 50); | |
noStroke(); | |
} | |
void draw() { | |
shapeWidth = ceil(sketchWidth / grid); | |
shapeHeight = ceil(sketchHeight / grid); | |
//there lies a bug when scrolling... | |
hue = map(mouseX, 0, sketchWidth, 0, 100); //move mouse horizontally for hue | |
sat = map(mouseY, 0, sketchHeight, 0, 100); //move mous evertically for saturation | |
for (int j = 0; j < grid; j++) { | |
for (int i = 0; i < grid; i++) { | |
count++; | |
bright = map(count, 0, grid*grid, 0, 100); //translate counter to 100 scale for brightness | |
//square | |
fill(hue, sat, (100 - bright)); | |
x1 = i * shapeWidth; | |
y1 = j * shapeHeight; | |
rect(x1, y1, shapeWidth, shapeHeight); | |
//ellipse | |
fill(hue, sat, bright); | |
w = shapeWidth; | |
h = shapeHeight; | |
x1 = i * shapeWidth + (shapeWidth / 2); | |
y1 = j * shapeHeight + (h / 2); | |
ellipse(x1, y1, shapeWidth, shapeHeight); | |
//quad | |
fill(hue, sat, (100 - bright)); | |
x1 = i * shapeWidth + (shapeWidth / 2); | |
y1 = j * shapeHeight; | |
x2 = (i + 1) * shapeWidth; | |
y2 = j * shapeHeight + (shapeHeight / 2); | |
x3 = x1; | |
y3 = (j + 1) * shapeHeight; | |
x4 = i * shapeWidth; | |
y4 = y2; | |
quad(x1, y1, x2, y2, x3, y3, x4, y4); | |
//smaller ellipse | |
fill(hue, sat, bright); | |
w = shapeWidth * sqrt(2)/2; | |
h = shapeHeight * sqrt(2)/2; | |
x1 = i * shapeWidth + (shapeWidth / 2); | |
y1 = j * shapeHeight + (shapeHeight / 2); | |
ellipse(x1, y1, w, h); | |
} | |
} | |
count = 0; //reset counter | |
//save("coursera_assignment_1.jpg"); //uncomment to save a screenshot | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment