Skip to content

Instantly share code, notes, and snippets.

@ejfox
Created January 27, 2024 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejfox/a049d8bea5fa7257891d987fef455554 to your computer and use it in GitHub Desktop.
Save ejfox/a049d8bea5fa7257891d987fef455554 to your computer and use it in GitHub Desktop.
Processing RGB LED Matrix Visualizer (for Raspberry Pi)
import ddf.minim.*;
Minim minim;
AudioInput mic;
int rows = 128;
int cols = 64;
float scale = 4.5; // Scale factor for the size of the circles
float noiseScale = 0.012; // Scale factor for the Perlin noise
float micThreshold = -10;
float t = 0; // Noise offset
float noiseThreshold = 0.4;
void setup() {
size(400, 800); // Height is double the width
colorMode(HSB, 360, 100, 100);
noStroke();
// Initialize the microphone
minim = new Minim(this);
mic = minim.getLineIn();
}
void draw() {
background(0);
// Get the volume from the microphone
float vol = mic.mix.level();
if (vol < micThreshold) return;
// Map the volume to a larger range to make the effect more noticeable
float noiseSpeed = map(vol, 0, 1, 0, 50);
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
// Calculate the position for each circle
float xPos = map(x, 0, cols, 0, width);
float yPos = map(y, 0, rows, 0, height);
// Use Perlin noise to determine the color
float n = noise(x * noiseScale, y * noiseScale, t);
float hue = map(n, 0, 1, 0, 360);
if (n > noiseThreshold) {
fill(hue, 100, 100);
ellipse(xPos, yPos, scale, scale);
}
}
}
// Increment t based on the volume
t += noiseSpeed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment