Skip to content

Commit

Permalink
Seperate tracks randomly between audience
Browse files Browse the repository at this point in the history
  • Loading branch information
Dermah committed Oct 13, 2019
1 parent 2ede322 commit 60e6424
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions pulsar/assets/js/audience/audience-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ new p5(p => {
const widthPc = widthPercent => (p.width * widthPercent) / 100;
const heightPc = heightPercent => (p.height * heightPercent) / 100;

let instrument;

let pulseSize = 0;
let energyData = [];
let totalAmp;
Expand All @@ -40,6 +42,7 @@ new p5(p => {
p.preload = () => {};

p.setup = () => {
instrument = Math.floor(Math.random() * 5);
const canvas = p.createCanvas(p.windowWidth, p.windowHeight);

canvas.mouseClicked(function() {
Expand All @@ -48,11 +51,14 @@ new p5(p => {
};

p.draw = () => {
p.background(0, 0, totalAmp * 255 || 0);

p.textAlign(p.CENTER);
p.fill(255);
p.text(`You are ${instrument}`, p.width / 2, 15);
p.push();
p.translate(p.width / 2, p.height / 2);

p.background(0, 0, totalAmp * 255 || 0);

if (pulseSize > 0) {
p.circle(0, 0, pulseSize);
pulseSize--;
Expand All @@ -61,22 +67,25 @@ new p5(p => {
p.push();
p.rectMode(p.CENTER);
p.translate(-p.width / 2, -p.height / 2);
energyData.map((freqEnergy, i) => {
p.fill(250);
freqEnergy.map((amp, j) => {
j / freqEnergy.length > 0.5 && p.fill(25) && p.stroke(255);
p.rect(
(j * widthPc(100)) / freqEnergy.length +
(1 * widthPc(100)) / (2 * freqEnergy.length),
(i * heightPc(100)) / energyData.length +
(1 * heightPc(100)) / (2 * energyData.length),
// 10,
// 10
widthPc(100) / freqEnergy.length,
(heightPc(100 / energyData.length) * amp) / 255
);
});

// energyData.map((freqEnergy, i) => {
const i = 0;
const freqEnergy = energyData[instrument] || [];
const channels = 1; //energyData.length
p.fill(250);
freqEnergy.map((amp, j) => {
j / freqEnergy.length > 0.5 && p.fill(25) && p.stroke(255);
p.rect(
(j * widthPc(100)) / freqEnergy.length +
(1 * widthPc(100)) / (2 * freqEnergy.length),
(i * heightPc(100)) / channels + (1 * heightPc(100)) / (2 * channels),
// 10,
// 10
widthPc(100) / freqEnergy.length,
(heightPc(100 / channels) * amp) / 255
);
});
// });

p.pop();
};
Expand Down

0 comments on commit 60e6424

Please sign in to comment.