Created
October 25, 2023 19:09
-
-
Save KrabCode/7cfa579243c103432a693131dafa9afb 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
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; | |
} |
Author
KrabCode
commented
Oct 25, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment