Published
Edited
Jul 16, 2020
Insert cell
Insert cell
Insert cell
Insert cell
random_walk.length
Insert cell
Insert cell
Insert cell
md `Function that accesses synthesizer to play note`
Insert cell
Insert cell
play2 = function(note, dur){
return synth.triggerAttackRelease(note, dur)
}
Insert cell
md `Run cell below to make sure audio is working. If not switch to Chrome or unmute`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof count = {
let value = 0;
const button = html`<button>Click to increment`;
Object.defineProperty(button, "value", {get() { return value; }});
button.onclick = function(){
if (value > random_walk.length - 2){
value = 0;
} else {
++value;
}
}
return button;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`This is the data object. Currently changes when different json strings are passed in from python`
Insert cell
Insert cell
md`Defining height of the chart's viewbox`
Insert cell
height = 800
Insert cell
md`This ontrols the node color. Currently determined by the indevidual node ID but we should update it to refect communities`
Insert cell
color = {
const scale = d3.scaleOrdinal(d3.schemeCategory10);
return d => scale(d.id);
}
Insert cell
md`Drag simulation. This is legacy code from force-directed graph. Not quite sure how it works`
Insert cell
drag = simulation => {
function dragstarted(d) {
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragended(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
md`Again legacy code. I think this is initializing d3`
Insert cell
d3 = require("d3@5")
Insert cell
md ` Section for defining and testing Synthesizer. Code adapted from https://observablehq.com/@tmcw/playing-with-tone-js`
Insert cell
Insert cell
Insert cell
Insert cell
viewof type = DOM.select(['sine', 'triangle', 'sawtooth', 'square'])
Insert cell
Insert cell
Insert cell
Insert cell
viewof volume = html`<input type='range' min=-24 max=0 value=-12 />`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{ Volume.mute = mute }
Insert cell
Insert cell
Insert cell


viewof start_walk = html`<form>${Object.assign(html`<button type=button>Start Random Walk`, {onclick: event => event.currentTarget.dispatchEvent(new CustomEvent("input", {bubbles: true}))})}`

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