-
-
Save jkwok91/2e7eb1ce7a751742b0fb to your computer and use it in GitHub Desktop.
more loops and mouseposition practice
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
/* | |
a heatmap | |
*/ | |
int w = 200; | |
int h = 200; | |
int cx = w/2; | |
int cy = h/2; | |
int side = 10; | |
color c; | |
void setup() { | |
size(w, h); | |
background(0); | |
} | |
void draw() { | |
for (int i = 0; i < width; i += side) { | |
for (int j = 0; j < height; j += side) { | |
float delta = dist(mouseX,mouseY,i,j); | |
c = getColor(delta/10+mouseX*side); | |
fill(c); | |
stroke(c); | |
rect(i,j,side,side); | |
} | |
} | |
} | |
/* | |
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