xxxxxxxxxx
77
let on = true;
let lines = [];
let whiteNoise;
let filter, filterFreq, filterWidth;
function setup() {
createCanvas(800, 800);
// frameRate(24);
angleMode(DEGREES);
lines.length = 1;
for (i = 0; i < lines.length; i++) {
lines[i] = new twirlingLine();
}
//noise stuff
filter = new p5.BandPass();
whiteNoise = new p5.Noise();
whiteNoise.disconnect(); // Disconnect soundfile from master output...
filter.process(whiteNoise); // ...and connect to filter so we'll only hear BandPass.
whiteNoise.start();
filterWidth = 0;
filterFreq = 0;
mouseX = 0;
}
function draw() {
// Map mouseX to a bandpass freq from the FFT spectrum range: 10Hz - 22050Hz
filterFreq = map(mouseX, 0, width, 300, 2000);
// Map mouseY to resonance/width
filterWidth = map(mouseY, 0, height, 0, 40);
// set filter parameters
filter.set(filterFreq, filterWidth);
lines[0].display(width/2, -1*height/4, 45, 1, 0, 0 );
}
function mousePressed () {
lines.push
}
function keyPressed () {
if (key == 80) {
on = !on;
}
}
function twirlingLine() {
this.x = width/2;
this.y = -1*height/16;
this.rot = 45;
this.nx = 0;
this.ny = 0;
this.t = 20;
this.lineWidth = 1;
this.display = function () {
translate(this.x,this.y);
rotate(this.rot);
background(220, 1);
this.nx = mouseY * noise(this.t + 5);
this.ny = mouseX * noise(this.t + 6);
fill(255);
strokeWeight(this.lineWidth);
line(this.nx, this.ny, this.ny + this.t, this.nx + this.t);
if (on) {
this.t = this.t + 0.01;
} else {
this.t = this.t;
}
}
}