Hi
I’m new to the world of Processing and I’ve turned to the community to get some help on a very specific issue I’ve been trying to solve.
I’m creating a “BMP clock”( or a "circular BPM visualizer), so to speak, and I’m trying to get the hand that shows the beat to cycle between different colors/moods. Right now I’ve only been able to, by looking at examples on the old forums, get it to cycle between two colors. However, I would like to cycle between at least four.
Here’s the code that I’ve cobbled together from different examples. I’d reckon it’s not the “neatest” code in the world, but it represents what I’m trying to do.
int cx, cy;
float secondsRadius;
float minutesRadius;
float hoursRadius;
float clockDiameter;
float colorAngle = 0.0;
float xRed = 62, xGreen = 20, xBlue = 173;
float yRed = 207, yGreen = 1, yBlue = 106;
float redX = xRed, greenX = xGreen, blueX = xBlue;
float speed = 0.02;
float BPM = 60; // beats per minute
float millisPerBeat = 1000/(BPM/60.0);
void setup() {
size(960, 540);
stroke(255);
//colorMode(HSB);
int radius = min(width, height) / 2;
secondsRadius = radius * 0.9;
minutesRadius = radius * 0.60;
hoursRadius = radius * 0.50;
clockDiameter = radius * 1.8;
cx = width / 2;
cy = height / 2;
}
//float c;
void draw() {
background(0);
// Draw the clock background
fill(0);
stroke(255);
strokeWeight(0);
ellipse(cx, cy, clockDiameter, clockDiameter);
// Angles for sin() and cos() start at 3 o'clock;
// subtract HALF_PI to make them start at the top
float s = millis() / millisPerBeat - HALF_PI;
// float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI;
// float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;
// Draw the hands of the clock
stroke(redX, greenX, blueX);
float sinval1 = sin(colorAngle);
println(sinval1);
redX = map(sinval1, -1, 1, xRed, yRed);
greenX = map(sinval1, -1, 1, xGreen, yGreen);
blueX = map(sinval1, -1, 1, xBlue, yBlue);
//ellipse(width/2, height/2, 300, 300);
colorAngle += speed;
strokeWeight(24);
line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
// strokeWeight(2);
// line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
// strokeWeight(4);
//line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
}
Any tips to what I can do?