*Extracted method for spawning new wave and clearing wave
*Changed some variable names to be move representative of their function
*Changed fade and radius to float to have more control on rates
*Fixed fade bug
*Waves spawn on mouseclick
This commit is contained in:
Stedd 2022-12-24 11:47:58 +01:00
parent fb5e341963
commit d9f98a7641
1 changed files with 40 additions and 17 deletions

View File

@ -1,21 +1,22 @@
//Config
int initialRadius = 5;
int radiusIncrease = 2;
int delay = 10; // Declare and initialize delay in frames
int bufferSize = 50; // Declare and initialize ring buffer size
float initialRadius = 5;
float radiusDelta = 3;
float fadeDelta = -0.5;
int delay = 30; // Declare and initialize delay in frames
int bufferSize = 20; // Declare and initialize ring buffer size
int sourceX = mouseX; // Declare and initialize source point x coordinate to current mouse x coordinate
int sourceY = mouseY; // Declare and initialize source point y coordinate to current mouse y coordinate
int[] buffer = new int[bufferSize]; // Declare and initialize radius buffer
float[] radiusBuffer = new float[bufferSize]; // Declare and initialize radius buffer
int[] sourceXBuffer = new int[bufferSize]; // Declare and initialize source point x coordinate buffer
int[] sourceYBuffer = new int[bufferSize]; // Declare and initialize source point y coordinate buffer
int[] colors = new int[bufferSize]; // Declare and initialize color buffer
float[] fades = new float[bufferSize]; // Declare and initialize fade buffer
int bufferIndex = 0; // Declare and initialize buffer index
int frameCount = 0; // Declare and initialize frame counter
void setup() {
size(800, 800); // Set canvas size
size(1600, 1200); // Set canvas size
colorMode(HSB, 360, 100, 100); // Set color mode to HSB
}
@ -23,23 +24,23 @@ void draw() {
background(255); // Clear canvas
for (int i = 0; i < bufferSize; i++) { // Iterate over ring buffer
int r = buffer[i]; // Get radius value from buffer
float r = radiusBuffer[i]; // Get radius value from buffer
int x = sourceXBuffer[i]; // Get source point x coordinate from buffer
int y = sourceYBuffer[i]; // Get source point y coordinate from buffer
stroke(colors[i]); // Set stroke color from color buffer
stroke(colors[i], fades[i]); // Set stroke color from color buffer
noFill(); // Remove fill
ellipse(x, y, r, r); // Draw circle with radius and source point coordinates from buffers
buffer[i]+=radiusIncrease;
radiusBuffer[i]+=radiusDelta;
fades[i] = max(0, fades[i] + fadeDelta); // Decrease fade value by 5
}
if (frameCount % delay == 0) { // Check if delay has passed
buffer[bufferIndex] = initialRadius; // Add current radius to buffer
sourceXBuffer[bufferIndex] = sourceX; // Add current source point x coordinate to buffer
sourceYBuffer[bufferIndex] = sourceY; // Add current source point y coordinate to buffer
colors[bufferIndex] = color(0); // Add random color to color buffer
bufferIndex = (bufferIndex + 1) % bufferSize; // Increment buffer index and wrap around if necessary
//radius = 5; // Reset radius to small value
if(mousePressed){
if (frameCount % delay == 0) { // Check if delay has passed
SpawnNewWave();
}
}
sourceX = mouseX;
@ -47,3 +48,25 @@ sourceY = mouseY;
//radius += 2; // Increment radius
frameCount++; // Increment frame counter
}
void SpawnNewWave(){
radiusBuffer[bufferIndex] = initialRadius; // Add current radius to buffer
sourceXBuffer[bufferIndex] = sourceX; // Add current source point x coordinate to buffer
sourceYBuffer[bufferIndex] = sourceY; // Add current source point y coordinate to buffer
colors[bufferIndex] = color(0); // Add random color to color buffer
fades[bufferIndex] = 255; // Add full fade value to fade buffer
bufferIndex = (bufferIndex + 1) % bufferSize; // Increment buffer index and wrap around if necessary
//radius = 5; // Reset radius to small value
}
void ClearWave(){
// Clear source point buffers
for (int i = 0; i < bufferSize; i++) {
sourceXBuffer[i] = 0;
sourceYBuffer[i] = 0;
}
}
void mousePressed() {
}