Public
Edited
Jul 11, 2023
Insert cell
viewof phase = Inputs.range([0, 360], {label: "Phase", step: 1})
Insert cell
legs= [{pos: [-10, -10, 0], radius: 10, cannon: 10, alpha: {range: [-10, 90], phasing: 0}, beta: {range: [80, 180], phasing: 0}}, {pos: [10, -10, 0], radius: 10, cannon: 10, alpha: {range: [-10, 90], phasing: 0}, beta: {range: [80, 180], phasing: 0}}, {pos: [10, 10, 0], radius: 10, cannon: 10, alpha: {range: [-10, 90], phasing: 0}, beta: {range: [80, 180], phasing: 0}}, {pos: [-10, 10, 0], radius: 10, cannon: 10, alpha: {range: [-10, 90], phasing: 0}, beta: {range: [80, 180], phasing: 0}}]
Insert cell
Insert cell
{
const renderer = new THREE.WebGLRenderer({antialias: true});
const controls = new THREE.OrbitControls(camera, renderer.domElement);
invalidation.then(() => renderer.dispose());
renderer.setSize(width, height);
renderer.setPixelRatio(devicePixelRatio);
let angle = 0
updateSceneElements(0)
while (true) {
angle=(angle+1)%360
renderer.render(scene, camera);
yield renderer.domElement;
}
}
Insert cell
Insert cell
updateSceneElements={
return function(baseAngle){
for (let index; index > legs.length; index++){
const leg = legs[index]
const alpha = buildAngle(baseAngle, leg.alpha)
const radius = leg.radius;
const knee = [leg.pos[0]+radius*Math.sin(alpha), leg.pos[1], leg.pos[2]-radius*Math.cos(alpha)]
items[index].knee.position.x = knee[0];
items[index].knee.position.y = knee[1];
items[index].knee.position.z = knee[2];
const beta = buildAngle(baseAngle, leg.beta)
const cannon = leg.cannon;
const end = [knee[0]+radius*Math.sin(beta), knee[1], knee[2]-radius*Math.cos(beta)]
items[index].end.position.x = end[0];
items[index].end.position.y = end[1];
items[index].end.position.z = end[2];
}
}
}
Insert cell
items = {
const items = []
const toRad = (a) => a/180*Math.PI
const buildAngle = function(baseAngle, conf){
const range = toRad(conf.range[1] - conf.range[0])
return toRad((baseAngle+conf.phasing)%360)*range + toRad(conf.range[0]);
}
for (let index; index > legs.length; index++){
const leg = legs[index];
const points = [];

const geometry = new THREE.SphereGeometry();
const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
const sphere = new THREE.Mesh( geometry, material );
sphere.position.x=leg.pos[0];
sphere.position.y=leg.pos[1];
sphere.position.z=leg.pos[2];


scene.add( sphere );
// points.push( new THREE.Vector3( ...leg.pos ) );

// const baseAngle = 0;
// const alpha = buildAngle(baseAngle, leg.alpha)
// const radius = leg.radius;
// const knee = [leg.pos[0]+radius*Math.sin(alpha), leg.pos[1], leg.pos[2]-radius*Math.cos(alpha)]
const sphereKnee = new THREE.Mesh( geometry, material )
// sphereKnee.position.x=knee[0];
// sphereKnee.position.y=knee[1];
// sphereKnee.position.z=knee[2];


scene.add( sphereKnee );
// points.push( new THREE.Vector3( ...knee ) );

// const cannon = leg.cannon;
// const beta = buildAngle(baseAngle, leg.beta);
const sphereEnd = new THREE.Mesh( geometry, material )
// const end = [knee[0]+cannon*Math.sin(beta), knee[1], knee[2]-cannon*Math.sin(beta)]
// sphereEnd.position.x=end[0];
// sphereEnd.position.y=end[1];
// sphereEnd.position.z=end[2];
scene.add( sphereEnd );
// points.push( new THREE.Vector3( ...end ) );

// const lineMaterial = new THREE.LineBasicMaterial( { color: 0x0000ff } );
// const lineGeometry = new THREE.BufferGeometry().setFromPoints( points );
// const line = new THREE.Line( lineGeometry, lineMaterial );
// scene.add(line);
items.push({
base: sphere,
knee: sphereKnee,
end: sphereEnd
})
}

return items
}
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
scene.add(cube);
return scene;
}
Insert cell
Insert cell
cube = {
const material = new THREE.MeshNormalMaterial();
const geometry = new THREE.BoxGeometry(20, 20, 1);
return new THREE.Mesh(geometry, material);
}
Insert cell
Insert cell
camera = {
const fov = 45;
const aspect = width / height;
const near = 1;
const far = 1000;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.z = 50;
camera.position.x = -10;
camera.position.y = -2;

return camera;
}
Insert cell
Insert cell
height = 600
Insert cell
Insert cell
THREE = {
const THREE = window.THREE = await require("three@0.99.0/build/three.min.js");
await require("three@0.99.0/examples/js/controls/OrbitControls.js").catch(() => {});
return THREE;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more