Skip to content

Instantly share code, notes, and snippets.

@KrabCode
Created October 25, 2023 19:09
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 KrabCode/7cfa579243c103432a693131dafa9afb to your computer and use it in GitHub Desktop.
Save KrabCode/7cfa579243c103432a693131dafa9afb to your computer and use it in GitHub Desktop.
int freq = 49;
int num = 128; // column and row count
int darkColor = 36;
int litColor = 200;
void setup() {
fullScreen(P2D);
noStroke();
// set sane default input
mouseX = width/2;
mouseY = height/2;
}
void draw() {
// read mouse input
freq = floor(map(mouseX, 0, width, 0, 60));
// w means cell size
float w = width / (float) num;
float t = radians(frameCount);
// draw the grid
background(darkColor);
translate(0, height/2-width/2);
for (int xi = 0; xi < num; xi++) {
for (int yi = 0; yi < num; yi++) {
float x = xi*w;
float y = yi*w;
if(isLit(xi,yi,num/2, num/2, t)){
fill(litColor);
rect(x, y, w, w);
}
}
}
}
boolean isLit(int xi, int yi, float centerX, float centerY, float t) {
return ((xi ^ yi) % freq) == 1
|| (yi ^ xi) % (freq/2) == 0;
}
@KrabCode
Copy link
Author

Screenshot_20231025-210330~2
Screenshot_20231025-210348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment