Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkwok91/930a66ad4296ab18b65c to your computer and use it in GitHub Desktop.
Save jkwok91/930a66ad4296ab18b65c to your computer and use it in GitHub Desktop.
why haven't i made one of these already
/*
rect moving
*/
float theta;
int side;
void setup() {
size(300, 300);
background(255);
side = 20;
}
void draw() {
background(255);
for (int h = 0; h < height/side; h++) {
for (int w = 0; w < width/side; w++) {
makeT(w, h);
}
}
theta += 0.1;
}
void makeT(int w, int h) {
pushMatrix();
translate(w*(side+5), h*(side+5));
rotate(theta);
float delta = dist(mouseX, mouseY, w, h);
color c = getColor(mouseX+delta);
fill(c);
rect(-side/2, -side/2, side, side);
popMatrix();
}
/*
resources:
http://krazydad.com/tutorials/makecolors.php
*/
color getColor(float i) {
int center = 205; //pastelly
int widthh = 55;
double frequency = .3;
int red = (int)Math.ceil(Math.sin(frequency*i+0) * widthh + center);
int green = (int)Math.ceil(Math.sin(frequency*i+2) * widthh + center);
int blue = (int)Math.ceil(Math.sin(frequency*i+4) * widthh + center);
return color(red,green,blue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment