Public
Edited
Apr 15, 2024
1 star
Insert cell
Insert cell
Insert cell
{
renderer.setSize(width, height);
renderer.setPixelRatio(devicePixelRatio);
const container = html`<div style="height:500px; position: relative; overflow: hidden;">
${renderer.domElement}`;
try {
while (true) {
render(scene, camera);
yield container;
}
} finally {
renderer.dispose();
}
}
Insert cell
Insert cell
Insert cell
camera = new THREE.PerspectiveCamera(27, width / height, 5, 3500)
Insert cell
renderer = new THREE.WebGLRenderer();
Insert cell
scene = new THREE.Scene()
Insert cell
init()
Insert cell
function init() {
camera.position.z = 2750;

scene.background = new THREE.Color(0x050505);
//scene.fog = new THREE.Fog(0x050505, 2000, 3500);

renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(width, height);

window.addEventListener('resize', onWindowResize, false);
}
Insert cell
points = {
var particles = 5000000;

var geometry = new THREE.BufferGeometry();

var positions = [];
var colors = [];

var color = new THREE.Color();

var n = 1000,
n2 = n / 2; // particles spread in the cube

for (var i = 0; i < particles; i++) {
// positions

var x = Math.random() * n - n2;
var y = Math.random() * n - n2;
var z = Math.random() * n - n2;

positions.push(x, y, z);

// colors

var vx = x / n + 0.5;
var vy = y / n + 0.5;
var vz = z / n + 0.5;

color.setRGB(vx, vy, vz);

colors.push(color.r, color.g, color.b);
}

geometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));

geometry.computeBoundingSphere();

var material = new THREE.PointsMaterial({
size: 3,
vertexColors: THREE.VertexColors
});

let p = new THREE.Points(geometry, material);
scene.add(p);
return p;
}
Insert cell
function onWindowResize() {
camera.aspect = width / height;
camera.updateProjectionMatrix();

renderer.setSize(width, height);
}
Insert cell
function render(scene, camera) {
points.rotation.x += 0.001;
points.rotation.y += 0.002;
renderer.render(scene, camera);
}
Insert cell
Insert cell
THREE = require("three@0.117.0")
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