Files
sunny9898/task8/wk9/wk9_example_8/wk9_example_8.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

75 lines
1.6 KiB
Plaintext

// This is an extension of Week 8 - exercise 2
// We use the amplitude of the microphone to control the step size of the noise() function
import processing.sound.*;
AudioIn input;
Amplitude loudness;
float xstart, xnoise, ystart, ynoise, tnoise;
void setup() {
size(300, 300);
xstart = random(10);
ystart = random(10);
input = new AudioIn(this, 0);
input.start();
//input.play();
loudness = new Amplitude(this);
loudness.input(input);
}
void draw() {
background(255);
// Detect the volume level of the microphone
float volume = loudness.analyze();
println(volume);
ynoise = ystart;
//tnoise +=0.005;
// Map the microphone volume level to the
// time-related noise parameter
tnoise += map(volume, 0, 1, 0.001, 0.1);
for (int y = 0; y <= height; y+=5) {
ynoise += 0.1;
xnoise = xstart;
for (int x = 0; x <= width; x+=5) {
xnoise += 0.1;
//set(x, y, color(255*noise(xnoise, ynoise, tnoise)));
drawLine(x, y, noise(xnoise, ynoise, tnoise));
//drawPoint(x, y, noise(xnoise, ynoise, tnoise));
}
}
}
// draw a 20-pixel long line from each point
// the amount of rotation is controlled by noise factor n
void drawLine(float x, float y, float n) {
pushMatrix();
translate(x, y);
rotate(n * TWO_PI);
stroke(0, 150);
line(0, 0, 20, 0);
popMatrix();
}
//fluffy clouds
void drawPoint(float x, float y, float n) {
pushMatrix();
translate(x,y);
rotate(n * radians(540));
noStroke();
float edgeSize = n * 35;
float grey = n * 100 + 155;
float alph = n * 100 + 155;
fill(grey, alph);
ellipse(0, 0, edgeSize, edgeSize/2);
popMatrix();
}