Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Created March 20, 2014 05:48
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/2e7eb1ce7a751742b0fb to your computer and use it in GitHub Desktop.
Save jkwok91/2e7eb1ce7a751742b0fb to your computer and use it in GitHub Desktop.
more loops and mouseposition practice
/*
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