Public
Edited
Feb 17, 2023
Insert cell
Insert cell
Insert cell
function getX(theta) {
return a*Math.cos(alpha)*Math.cos(theta) - b*Math.sin(alpha)*Math.sin(theta)
}
Insert cell
function getY(theta) {
return b*Math.cos(alpha)*Math.sin(theta) + a*Math.sin(alpha)*Math.cos(theta) - translateY
}
Insert cell
viewof theta = Inputs.range([0, 100], {label: "theta", step: 1})
Insert cell
translateY = Math.sqrt(a**2 * Math.sin(alpha)**2 + b**2 * Math.cos(alpha)**2)
Insert cell
mutable alpha = 0
Insert cell
rotate = {
var t = 0;
while (true) {
t += .005;
mutable alpha = (t * 2 * Math.PI) % (2 * Math.PI);
yield mutable alpha;
}
}
Insert cell
points = [0, Math.PI / 2, Math.PI, (3/2) * Math.PI, 2 * Math.PI].map(theta => [getX(theta), getY(theta)])
Insert cell
morePoints = d3.range(0, Math.PI * 2, .1).map(theta => [getX(theta), getY(theta)])
Insert cell
viewof a = Inputs.range([0, 100], {label: "a", step: 1})
Insert cell
viewof b = Inputs.range([0, 100], {label: "b", step: 1})
Insert cell
<svg width="500" height="300">
<g>
<line x1="0" x2="0" y1="-150" y2="150"/>
<line x1="-250" x2="250" y1="0" y2="0"/>
<!-- ${morePoints.map(([x, y]) =>
svg`<circle r="2" cx="${x}" cy="${y}"/>`
)} -->
${points.map(([x, y]) =>
svg`<circle class="sound" r="5" cx="${x}" cy="${y}"/>`
)}
</g>
</svg>
Insert cell
<style>
svg {
background: #fcf3f2;
}
g {
transform: translate(50%, 50%);
}
circle {
fill: black;
}
circle.sound {
fill: red;
}
line {
stroke: black;
stroke-width: 2px;
}
</style>
Insert cell
d3 = require("d3@5", "d3-array@2")
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