xxxxxxxxxx
95
var amp;
var mouse_down = false;
var max_amp = -4;
var min_amp = -5;
var zoom_by = 4;
var zoom_slider;
var ellipse_slider;
function setup() {
createCanvas(256, 512);
background(220);
pixelDensity(1);
background(0);
stroke(255);
line(0, height / 2 + 1, width, height / 2 + 1);
createDiv("Zoom:");
zoom_slider = createSlider(1, 5, 1, 0.1);
createDiv("Pen size:");
ellipse_slider = createSlider(1, 20, 10, 0.1);
}
function draw() {
noStroke();
if (mouse_down) {
ellipse(mouseX, mouseY, ellipse_slider.value(), ellipse_slider.value());
}
stroke(255);
line(0,height/2+1,width,height/2+1);
}
function mousePressed() {
mouse_down = true;
//
// updateAmp();
}
function mouseClicked() {
mouse_down = false;
updateAmp();
}
function updateAmp() {
loadPixels();
amp = [];
for (i = 0; i < width; i++) {
var tmp = [];
for (j = 0; j < height / 2; j++) {
tmp.push([pixels[4 * (j + i * width)] / 255.0, 0.0]);
}
amp.push(tmp);
}
const F2d0 = fft2dr(amp);
for (i = 0; i < width; i++) {
for (j = 0; j < height / 2; j++) {
var im_intensity =
F2d0[(i + width / 2) % width][(j + height / 4) % (height / 2)][0] ** 2 +
F2d0[(i + width / 2) % width][(j + height / 4) % (height / 2)][1] ** 2;
min_amp = 0.0;
max_amp = max(max_amp, sqrt(im_intensity));
}
}
for (i = 0; i < width; i++) {
for (j = 0; j < height / 2; j++) {
var im_intensity =
F2d0[(i + width / 2) % width][(j + height / 4) % (height / 2)][0] ** 2 +
F2d0[(i + width / 2) % width][(j + height / 4) % (height / 2)][1] ** 2;
//im_intensity = map(log(im_intensity+1e-7),min_amp,max_amp,0,255);
im_intensity = map(sqrt(im_intensity), 0, max_amp, 0, 255);
pixels[4 * (i + j * width + (width * height) / 2) + 0] = im_intensity;
pixels[4 * (i + j * width + (width * height) / 2) + 1] = im_intensity;
pixels[4 * (i + j * width + (width * height) / 2) + 2] = im_intensity;
}
}
updatePixels();
zoom_by = zoom_slider.value();
image(
get(
width / 2 - width / 2 / zoom_by,
height / 2 + height / 4 - height / 4 / zoom_by,
width / zoom_by,
height / 2 / zoom_by
),
0,
height / 2,
width,
height / 2
);
}