xxxxxxxxxx
239
let mid_altezza, mid_larghezza;
let altezza_testo;
let punti = [];
let target_x = [];
let target_y = [];
let target_x_mouse = [];
let target_y_mouse = [];
let target_x_random = [];
let target_y_random = [];
let spazio;
let dens = 9;
let pulsazione = [];
let fase_pulsazione = [];
let amp_puls = [];
let pulsazione_pre = [];
let connessioni = [];
let cnv;
let cliccato = 0;
let cliccato_pre = 0;
let sample = [];
let polifonia = 16;
let campione = 0;
let costringilo = [0.5, 0.562, 0.633, 0.712, 0.8, 0.9, 1, 1.125, 1.265, 1.423, 1.6, 1.8, 2, 2.125, 2.265, 2.423];
let costringilo_pre;
let dist_link;
function setup() {
frameRate(20);
cnv = createCanvas(windowWidth, windowHeight);
cnv.touchStarted(traccia_mouse);
cnv.mousePressed(traccia_mouse);
mid_larghezza = width * 0.5;
mid_altezza = height * 0.5;
let lung_x = width;
let lung_y = height;
let lung;
if (lung_x >= lung_y) {
lung = lung_x;
}
else{
lung = lung_y;
}
spazio = floor(lung / dens);
for (let x = 0; x < lung_x; x += spazio) {
for (let y = 0; y < lung_y; y += spazio) {
let punto = createVector (x + floor(random(-10, 10)),
y + floor(random(-10, 10)));
punti.push(punto);
}
}
for (let i = 0; i < punti.length; i++) {
target_x[i] = floor(random(width));
target_y[i] = floor(random(height));
target_x_random[i] = target_x[i];
target_y_random[i] = target_y[i];
fase_pulsazione[i] = random(-2 * PI, 2 * PI);
amp_puls[i] = random(5) + 30;
pulsazione[i] = 10 + amp_puls[i] * abs(sin(fase_pulsazione[i]));
pulsazione_pre[i] = pulsazione[i];
connessioni[i] = 0;
}
dist_link = lung_y * 0.1 * 0.7;
}
function draw() {
background(0);
fill(255);
strokeWeight(1);
let pos_mouse_X = mouseX;
let pos_mouse_Y = mouseY;
for (let i = 0; i < punti.length; i++) {
//--------target x-------//
if (cliccato == 1) {
// ellipse(mouseX, mouseY, 50, 50);
target_x[i] = pos_mouse_X * 0.7 + target_x_random[i] * 0.3;
target_y[i] = pos_mouse_Y * 0.7 + target_y_random[i] * 0.3;
}
else {
target_x[i] = target_x_random[i];
target_y[i] = target_y_random[i];
}
if (punti[i].x == target_x_random[i]) {
target_x_random[i] = floor(random(width));
}
if (punti[i].x > target_x[i]) {
punti[i].x = punti[i].x - 1;
}
if (punti[i].x < target_x[i]) {
punti[i].x = punti[i].x + 1;
}
if (punti[i].y == target_y_random[i]) {
target_y_random[i] = floor(random(height));
}
if (punti[i].y > target_y[i]) {
punti[i].y = punti[i].y - 1;
}
if (punti[i].y < target_y[i]) {
punti[i].y = punti[i].y + 1;
}
// -------- disegno lucciola---------//
stroke(255);
fill(255, 255, 0, 255);
point(punti[i].x, punti[i].y, 0);
//---------- disegno alone---------//
noStroke();
fill(255, 255, 0, 100 * connessioni[i] + 50);
ellipse(punti[i].x, punti[i].y, pulsazione[i], pulsazione[i]);
fase_pulsazione[i] = fase_pulsazione[i] + 0.035;
pulsazione[i] = 10 + amp_puls[i] * abs(sin(fase_pulsazione[i]));
} // fine for lucciole
// calcolo e disegno collegamenti
for (let i = 0; i < punti.length; i++) {
let distanza;
for (let j = 0; j < punti.length; j++) {
if (i != j) {
distanza = dist(punti[i].x, punti[i].y, punti[j].x, punti[j].y );
if (distanza < dist_link) {
strokeWeight(1);
stroke(255, 255, 0, 50);
line(punti[i].x, punti[i].y, punti[j].x, punti[j].y);
strokeWeight(8);
stroke(255, 255, 0, 30);
line(punti[i].x, punti[i].y, punti[j].x, punti[j].y);
connessioni[i] = connessioni[i] + 1;
}
}
if (connessioni[i] > 0 && distanza >= 40 ) {
connessioni[i] = connessioni[i] - 1;
}
}
}
//-------------disegno punti grigi----------//
strokeWeight(1);
stroke(255);
//line(width * 0.5, 0, width * 0.5, height);
// line(0, height * 0.5, width, height * 0.5);
noFill();
//rect(mid_larghezza - 150, (mid_altezza * 0.01) - 5, mid_larghezza, mid_altezza * 0.65);
fill(255);
cliccato_pre = cliccato;
} // fine del draw
function traccia_mouse() {
cliccato = 1;
return cliccato;
}
function mouseReleased() {
cliccato = 0;
return cliccato;
}
function touchEnded() {
cliccato = 0;
return cliccato;
}