xxxxxxxxxx
67
// Variables for the oscillating circle (first code)
let blue, yellow, red;
let currentOscillationColor;
// Variables for the arcs (second code)
let colors = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF'];
let currentColorIndex = 0;
let activeParts = 0;
let oscillationCycleCompleted = false;
let changeSpeed = 2000; // Speed of change in milliseconds for arcs
let lastChangeTime = 0;
let oscillationComplete = false;
function setup() {
createCanvas(800, 800);
colorMode(RGB); // Using RGB for specific colors in the oscillating circle
angleMode(DEGREES); // Using DEGREES for the arcs
// Define the three colors for the oscillating circle
blue = color(0, 0, 255); // Blue
yellow = color(255, 255, 0); // Yellow
red = color(255, 0, 0); // Red
noStroke();
}
function draw() {
background(220); // Draw the background
// Draw the arcs over the background first (second code)
translate(width / 2, height / 2); // Move to the center
// Check if a full oscillation cycle is completed
if (!oscillationCycleCompleted && (sin(millis() * 0.01) * 0.5 + 0.5) >= 0.99) {
oscillationCycleCompleted = true;
} else if ((sin(millis() * 0.01) * 0.5 + 0.5) <= 0.01) {
oscillationCycleCompleted = false;
}
// If an oscillation cycle is completed, change the active part
if (oscillationCycleCompleted && !oscillationComplete) {
activeParts++;
if (activeParts > 4) {
activeParts = 1;
currentColorIndex = (currentColorIndex + 1) % colors.length; // Cycle through the color array
}
oscillationComplete = true;
lastChangeTime = millis();
}
// Reset the oscillationComplete flag after half a cycle to allow the next cycle
if ((sin(millis() * 0.01) * 0.5 + 0.5) <= 0.01) {
oscillationComplete = false;
}
// Draw the filled arcs behind the oscillating circle
for (let i = 0; i < activeParts; i++) {
fill(colors[currentColorIndex]);
arc(0, 0, 300, 300, i * 90, (i + 1) * 90, PIE);
}
// Draw the oscillating circle (first code)
let oscillation = (sin(millis() * 0.01) * 0.5 + 0.5); // Speed up oscillation
// Transition between blue, yellow, and red
if (oscillation < 0.5) {
currentOscillationColor = lerpColor(blue, yellow, oscillation * 2); // From blue to yellow
} else {
currentOscillationColor = lerpColor(yellow, red, (oscillation - 0.5) * 2); // From yellow to red
}
fill(currentOscillationColor);
circle(0, 0, 250); // Draw the oscillating circle at the center
}