Audiovisual Study

Listen with headphones.

N=3

N=10

N=30

				
					/* Audiovisual Study*/
/* Andreas Pirchner, 2018*/


var mainRadius = 250;
var population =10;
var lineWidth = 2;
//let dot1;
var circleColor; 
//ArrayList<Dot> particles;
var Dots = [];
var centerPoint = new p5.Vector(mainRadius+5, mainRadius +5);
var centerShift = new p5.Vector(centerPoint.x-50, centerPoint.y-50);
var soundOn = true;

function setup() {
  var canvas = createCanvas(mainRadius*2+10, mainRadius*2+10);
  canvas.parent('sketchone');
  frameRate(14);
  colorMode(HSB);
  //centerPoint = new PVector(mainRadius+5, mainRadius +5);
  for (var i = 0; i < population; i++) {
  	Dots[i] = new Dot(random(TWO_PI), random(-0.005,0.005), mainRadius, random(10, 50));
  }

  for (var i = 0; i < Dots.length; i++){
  	Dots[i].setMatch();
  }
  strokeCap(SQUARE);
  rectMode(CENTER);
  circleColor = color(0, 10, 70, 0);
  //print(centerPoint);

  button = createButton('turn sound off');
  button.position(width-400, height - 200);
  button.mousePressed(buttonFunction);
}

 function buttonFunction(){

    if(soundOn == true){
       button.html("turn sound on");
       soundOn = false; 
       for (var i = 0; i < Dots.length; i++){
          Dots[i].whiteNoise.stop();        
        }
    }else{
       button.html("turn sound off");
       soundOn = true;
       for (var i = 0; i < Dots.length; i++){
          
          Dots[i].whiteNoise.start();     
        }
    }
  }

function draw() {
  background(255);
  //fill(circleColor);
  //stroke(0,0.3);
  //strokeWeight(1);
  //ellipse(205,205,mainRadius*2, mainRadius*2);
  fill(0);
  //let ale = Dots.length;
  for (var i = Dots.length-1; i >= 0; i--) {
  	Dots[i].update();
  	Dots[i].paint();
  	if (Dots[i].getLifespan() <= 10){
  		Dots[i].kill();
  		Dots.splice(i,1);
  		Dots.push(new Dot(random(TWO_PI), random(-0.005,0.005), mainRadius, random(10, 50)));
  		Dots[Dots.length-1].setMatch();
  		//print("i`m so dead!");
  	}
  	stroke(0, 60);
  	strokeWeight(lineWidth);
  	noFill();
  	xStart = Dots[i].x;
  	yStart = Dots[i].y;
  	xGoal = Dots[Dots[i].getMatch()].x;
  	yGoal = Dots[Dots[i].getMatch()].y;
  	//line(xStart, yStart ,xGoal, yGoal);
  	if (Dots[i].getColor() != undefined){
  		stroke(Dots[i].getColor());
  	}

  	for (var j = 0; j < 10; j++) {
  		//var difference = random(-10,10);
  		var difference = Dots[i].differences[j];
      var diff = 100;
      
  		bezier(xStart, yStart , centerShift.x+difference,centerShift.y+difference,centerShift.x+difference,centerShift.y+difference,xGoal, yGoal);
      
  	}
  	

  }
  
}