xxxxxxxxxx
201
let valore_noise;
//Incremento x di 0.01
let incremento = 0.022;
let x_increment = incremento; //zoom x
//Increment z di 0.03 ogni ciclo
let y_increment = incremento; //zoom x
//Increment z di 0.03 ogni ciclo
let z_increment = incremento; //zoom z
//0.02 buono
//valori offset
let z_off, y_off, x_off;
let campione = [];
let sample = [];
let ampiezza;
let punto = [];
let suoni_play = 0;
let cnv;
let numero_sample = 20;
let lettura_punti;
let conta_sample;
let fs = false;
let mouse_pre = false, mouse_ora = false;
function preload() {
soundFormats('ogg', 'mp3');
sample[0] = loadSound('sala1.mp3');
sample[1] = loadSound('sala2.mp3');
sample[2] = loadSound('sala3.mp3');
sample[3] = loadSound('sala4.mp3');
sample[4] = loadSound('sala5.mp3');
sample[5] = loadSound('sala6.mp3');
sample[6] = loadSound('sala7.mp3');
}
function setup() {
cnv = createCanvas(displayWidth, displayHeight);
//cnv = createCanvas(windowWidth, windowHeight);
cnv.mouseClicked(attiva_audio);
frameRate(10);
//gestione ottave e armoniche perlin
noiseDetail(4, 0.7);
z_off = 0;
lettura_punti = floor(height / numero_sample);
for (let i = 0; i < numero_sample; i++) {
campione[i] = sample[floor(random(0, 7))];
campione[i].rate(random(0.2, 3));
campione[i].pan(random(-1, 1));
campione[i].loop();
}
getAudioContext().suspend();
}
function draw() {
x_off = 0;
y_off = 0;
background(0);
for (let y = 0; y < height; y+= 10) {
x_off += x_increment;
y_off = 0;
punto[y] = [];
for (let x = 0; x < width; x+= 10) {
valore_noise = noise(x_off, y_off, z_off);
strokeWeight(4); //larghezza punto
if (valore_noise >= 0.65) {
stroke(255, 200, 0);
punto[y][x] = 1;
}
else {
stroke(0);
punto[y][x] = 0;
}
y_off += y_increment;
point(x, y); //disegno punto
}
}// fine for grafico
z_off += z_increment;
//-------sintesi sonora -------//
let somma = 0;
for (let y = 0; y < height; y+= 20) {
for (let x = 0; x < width; x+= 20) {
somma = somma + punto[y][x];
}
}
let somma_max = (width * height) * 0.01;
ampiezza = map(somma, 0, somma_max, 0, 1);
let area = map(somma, 0, somma_max, 0, width);
for (let i = 0; i < numero_sample; i++) {
campione[i].setVolume(ampiezza * 0.25);
if (ampiezza < 0.2) {
campione[i].pan(random(-1, 1));
}
if (random(10) > 5) {
campione[i].rate(random(0.3, 5));
}
/*
if (campione[i].isPlaying() == false) {
campione[i].loop();
} */
}
let stato_audio = getAudioContext().state;
rectMode(CENTER);
strokeWeight(1);
if (stato_audio !== 'running') {
stroke(255, 0, 0);
noFill();
rect(width * 0.5, height * 0.5, 100, 21);
textAlign(CENTER);
fill(255, 0, 0);
text("AUDIO ON", width * 0.5, height * 0.5 + 5);
}
if (fs == false) {
noFill();
stroke(255, 0, 0);
rectMode(CORNER);
rect(10, 10, 100, 30)
textAlign(LEFT);
fill(255, 0, 0);
text("FULL SCREEN", 20, 30);
}
mouse_ora = mouseIsPressed;
if (mouse_ora == true && mouse_pre == false) {
if (mouseX > 10 && mouseX < 100 && mouseY > 10 && mouseY < 30) {
fs = fullscreen();
fullscreen(!fs);
// fs = !fs;
}
}
mouse_pre = mouse_ora;
} //fine draw
function attiva_audio() {
if (mouseX > 150 && mouseY > 150) {
if (getAudioContext().state !== 'running') {
userStartAudio();
}
else {
getAudioContext().suspend();
}
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}