[sharing is fun] frameRate-independant frequencies
in
Share your Work
•
2 years ago
Hello,
This might interest a a few people: I wanted to have frameRate-independant frequencies and be able to express these frequencies in Hertz.
This simple code does it. Not really magnificent but handy.
This might interest a a few people: I wanted to have frameRate-independant frequencies and be able to express these frequencies in Hertz.
This simple code does it. Not really magnificent but handy.
- /*
- FRAMERATE-INDEPENDANT FREQUENCY
- I PREFER TO USE HERTZ ALSO
- */
- import processing.opengl.*;
- int rate = 120 ; //set framerate here
- float angle = 0.0 ;
- float frequency = 0.1; // frequency in Hertz
- void setup() {
- size (500, 500, OPENGL);
- frameRate(rate);
- }
- void draw() {
- translate(width/2, height/2, 0);
- angle = (( frequency * frameCount/(float(rate))) * TWO_PI) % TWO_PI; // ( frequency * frameCount/(float(rate)) is the most important part
- rotateZ(angle);
- rect(0, 0, 100, 10);
- }