xxxxxxxxxx
79
// i can use this to prototype picking the frequency range by changing the smoothstep function to have a falloff if they go beyond a certain point.
let linecount = 40
let reso = 200;
let totalreso = 5000;
let a,b,w;
let lineslider;
function setup() {
createCanvas(400, 400);
lineslider = createSlider(1,100,40,0)
lineslider.size(width)
lineslider.mouseMoved(customdraw)
aslider = createSlider(0,1,0.75,0)
aslider.size(width)
aslider.mouseMoved(customdraw)
bslider = createSlider(0,1,0.40,0)
bslider.size(width)
bslider.mouseMoved(customdraw)
customdraw()
}
function customdraw() {
background(0);
a = aslider.value()
b = bslider.value()
w = (2*PI)/b
linecount = lineslider.value();
reso = round(totalreso/linecount) //comment for constant x resolution. uncomment for constant total resolution
noFill()
stroke(50);
strokeWeight(2)
for(let i=0; i<linecount*reso; i++){
const prog = i/(linecount*reso);
// const boost = smoothStep(noise(prog*1000), 0.75, 0.85);
const boost = movingpeak(noise(prog*1000));
// stroke(50 + 200 * boost); //monochrome
stroke(
(-1 * pow(prog * 3.0 -0.3, 2) + 1) * 150 + 1000 * boost,
(-1 * pow(prog * 3.0 -1.5, 2) + 1) * 150 + 1000 * boost,
(-1 * pow(prog * 3.0 -2.7, 2) + 1) * 150 + 1000 * boost,
)
point( (i%reso) * (width/reso) , prog*height);
}
}
function movingpeak(x){
if(x<a - PI/w){
return 0
}
if(x>a + PI/w){
return 0
}
return 0.5 - cos( (x-a ) * w - PI ) * 0.5
}
function smoothStep(x, loEdge, hiEdge){
if(x<loEdge){
return 0
}
if(x>hiEdge){
return 1
}
return (x-loEdge) / (hiEdge - loEdge)
}