Published
Edited
Apr 11, 2018
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart
Insert cell
max = Math.max.apply(Math,chart.map(function(o){return o[1];}))
Insert cell
min = Math.min.apply(Math,chart.map(function(o){return o[1];}))
Insert cell
function find_mean(array) {
let sums = 0
let average = 0

for (var i = 0; i < array.length; i++) {
sums += array[i][1];
}

average = sums / array.length;
return average;
}
Insert cell
mean = find_mean(chart)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function music(stat){
if (stat < -1){
synth.triggerAttackRelease('C4', '4n')
}
else if (stat > -1 && stat < -0.5){
synth.triggerAttackRelease('E4', '4n')
}
else if (stat > -0.5 && stat < 0.5){
synth.triggerAttackRelease('G4', '4n')
}
else if (stat > 0.5 && stat < 1){
synth.triggerAttackRelease('B4', '4n')
}
else{
synth.triggerAttackRelease('E4', '8n')
}
}
Insert cell
synth.triggerAttackRelease('C4', '8n')
//synth.triggerAttackRelease('C4', '8n')
Insert cell
Insert cell
Insert cell
music_stat(stat)
Insert cell
Insert cell
function music_stat(stat){
if(stat === "max"){
music(max)
}
else if(stat === "min"){
music(min)
}
else if(stat === "mean"){
music(mean)
}
else{
music(mean)
}
}
Insert cell
Insert cell
synth = new Tone.Synth().toMaster()
Insert cell
//play a middle 'C' for the duration of an 8th note
synth.triggerAttackRelease('C4', '8n')
Insert cell
Insert cell
// function to randomly generate X values
randomX = d3.randomUniform(0, 10)
Insert cell
// function to randomly generate Y values
randomY = d3.randomNormal(-0.5, 0.5)
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
// generate data using the X and Y values
data = d3.range(800).map(function() { return [randomX(), randomY()]; })
Insert cell
// declaring margin variable
margin = ({top: 194, right: 50, bottom: 214, left: 50})
Insert cell
Insert cell
// import d3
d3 = require("d3@4")
Insert cell
Tone = require("tone")
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more