/*
* metronome
*/
int stage = 600;
int mains = int(random(3,9) );
int subs = int(random(3,6) );
float moon_size = 3;
int bpm = 60;
int active_main = 0;
int active_sub = 0;
color main_color = #292B89;
color first_color = #1A1B55;
color active_color = 0x95FFFFFF;
int my_frame_rate = 12;
float bps = float(bpm) / 60 ;
void setup() {
size(stage, stage);
frameRate(my_frame_rate);
noStroke();
}
void draw() {
background(#989898);
if( frameCount % (my_frame_rate/bps) < 1 ){
active_main+=1;
if(active_main>=mains){
active_main=0;
}
}
if( frameCount % (my_frame_rate/bps/subs) < 1 ){
active_sub+=1;
if(active_sub==subs){
active_sub=0;
}
}
Circle a = new Circle(width/2, height/2, stage/2, mains);
a.make_moons( active_main );
a.moons[active_main].make_moons( active_sub );
}
void mouseMoved(){
mains = 2 + mouseX /(stage/10);
moon_size = mains/1.555;
active_main=0;
}
class Circle{
float r, x, y;
int active_moon, each_angle, sections;
Circle moons[] = new Circle[23];
Circle(float x_init,float y_init,float r_init, int divisions_init){
x = x_init;
y = y_init;
r = r_init;
sections = divisions_init;
each_angle = 360 / sections;
}
void make(){
ellipse(x, y, r, r);
}
void make_moons( int active_moon ){
int angle = each_angle;
for(int i = 0; i < sections; i+=1 ){
float moon_x = x + cos(radians(angle)) * (r/2);
float moon_y = y + sin(radians(angle)) * (r/2);
moons[i] = new Circle(moon_x, moon_y, r / 4, subs);
if(i==active_moon){fill(active_color);}else if(i==0){fill(first_color);} else{fill(main_color);} // HIGHLIGHT FIRST & ACTIVE MOON
moons[i].make();
angle = angle + each_angle;
}
}
}
Visual Metronome
This entry was posted in javascript. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
One Comment
I can create anywhere from two to twelve spheres, but I am failing to detect the purpose of this.
I am looking at the end of next week for fun wall drilling/ceiling cutting. Will call.
One Trackback
[...] from my first iteration on a visual metronome, this is an improvement to simplify things while providing greater control in the UI for: tempo, [...]