var socket = io.connect(":30000?sketch=1020978");
let wait_message = false;
let NOTES = ['C3','D3','E3','F3','G3','A3','B3','C4','D4','E4','F4','G4','A4','B4','C5'];
cnv = createCanvas(windowWidth, windowHeight);
cnv.mousePressed(notTyping);
colorMode(HSB,360,100,100);
message_field = createInput();
message_field.position(10,0);
message_field.size(width/4);
message_field.mousePressed(typing);
synth = new p5.PolySynth();
panner = new p5.Panner3D();
me.name = prompt('Name?');
while(!me.name) { me.name = prompt('Please enter a name'); }
socket.on('update', updatePerson);
socket.emit('update', me);
for (let person of people) {
fill(person.h,70,100,0.8);
ellipse(person.x,person.y,person.d);
text(person.name,person.x,person.y-person.d/2-5);
text(person.message,person.x,person.y+person.d/2+20);
if(me.playing) {me.playing = false;}
function instructions() {
let cooldown_seconds = round(me.message_cooldown/fps);
text(`Message Cooldown: ${cooldown_seconds}`,10,40);
if(wait_message) {text(`Please wait for cooldown to send again`,10,60);}
text(`Use WASD to move around`,10,height-20);
text(`Send messages in the top input by typing and pressing enter`,10,height-40);
function playSynth(person) {
if(person.name == me.name) {velocity = 0.1;}
else {velocity = map(dist(me.x,me.y,person.x,person.y),0,1000,1,0);}
let pos = get_position(person);
panner.set(pos[0],pos[1],0);
synth.play(person.note, velocity, time, dur);
function get_position(person){
return[me.x-person.x,person.y-me.y];
if(me.message_cooldown > 0) {
if(me.message_cooldown == 0) {
me.message_cooldown -= 1;
function personControls() {
if(keyIsDown(65) && (me.x > me.d/2)) {
if(keyIsDown(68) && (me.x < width - me.d/2)) {
if(keyIsDown(87) && (me.y > me.d/2)) {
if(keyIsDown(83) && (me.y < height - me.d/2)) {
if((keyCode == 65 || keyCode == 68 || keyCode == 87 || keyCode == 83) && noKeysDown()){
return !(keyIsDown(65) || keyIsDown(68) || keyIsDown(87) || keyIsDown(83));
if(me.message_cooldown == 0) {
} else {wait_message = true;}
me.message = message_field.value();
me.message_cooldown = fps*3;
function updatePerson(person) {
let ch = people.filter(p=>p.name == person.name);
ch[0].message = person.message;
ch[0].playing = person.playing;