Created
January 24, 2017 17:53
-
-
Save alekhinen/f01e96aabffc511bd378a2dd127343b3 to your computer and use it in GitHub Desktop.
processing visual rhythm
This file contains hidden or 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 FRAME_RATE = 30; | |
int BPM = 80; | |
float FPB = FRAME_RATE * 60.0 / BPM; | |
float BPF = BPM / 60.0 / FRAME_RATE; | |
float beatCount = 0.0; | |
int nodeSize = 20; | |
void setup() { | |
size(200, 200, P3D); | |
frameRate(FRAME_RATE); | |
} | |
void draw() { | |
background(255); | |
FPB = frameRate * 60.0 / BPM; | |
float modulationRate = FPB; | |
beatCount = (this.beatCount + 1) % modulationRate; // modulate on every four beats | |
float x = map(beatCount, 0, modulationRate, 0, (float) Math.PI); | |
float y = sin(x); | |
nodeSize = Math.round(map(y, 0, 1, 1, 20)); | |
fill(0); | |
rect(90, 90, nodeSize, nodeSize); | |
text(frameRate, 10, 20); | |
text(y, 10, 50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment