Public
Edited
Feb 20, 2024
Insert cell
Insert cell
Insert cell
genererFigures = {
const figures = [];
const features = { Name: "" };

// ------ your code starts here ------

// Here the variable u is the unit used to scale
const u = 1;
const r = fxrand;
const rint = (n) => Math.floor(r() * n);

//simple cube

const cube = (args, pos, full) =>
figures.push({
geometry: {
type: "BoxGeometry", // Type of geometry
args
},
pos,
rot: {
// Rotation
x: 0,
y: 0,
z: 0
},
lines: !full, // Display color segments (like wireframe, but faces not triangles)
hatch: !full, // Fill with white texture
full // Fill with color texture (in the anaverse, red and cyan)
});

const chair = {
height: 0.5 + r() * 2,
width: 0.25 + r(),
depth: 0.25 + r(),
theme: r() < 0.2
};

chair.assise = chair.height * (0.2 + r() * 0.5);

const nbTraversLateraux = r() > 0.5 ? 1 : 1 + rint(chair.height * 4);

//travers droit
for (let i = 0; i < nbTraversLateraux; ++i) {
cube(
[0.1, 0.1, chair.depth * 2],
{ x: -chair.width, y: chair.height - 0.05 - i * 0.2, z: 0 },
chair.theme
);

//travers gauche
cube(
[0.1, 0.1, chair.depth * 2],
{ x: chair.width, y: chair.height - 0.05 - i * 0.2, z: 0 },
chair.theme
);
}
// traversDossier
const nbTraversDossier = rint(chair.height * 4);
for (let i = 0; i < nbTraversDossier; ++i) {
cube(
[chair.width * 2, 0.1, 0.1],
{ x: 0, y: chair.height - 0.05 - i * 0.2, z: -chair.depth },
chair.theme
);
}
//assise
cube(
[chair.width * 2 + 0.1, 0.1, chair.depth * 2 + 0.1],
{ x: 0, y: chair.assise, z: 0 },
chair.theme
);

//montants
const nbMontantsLateraux = r() > 0.5 ? 1 : 1 + rint(chair.depth * 8);
for (let i = 0; i < nbMontantsLateraux; ++i) {
cube(
[0.1, chair.height, 0.1],
{ x: -chair.width, y: chair.height / 2, z: -chair.depth + i * 0.2 },
chair.theme
);

cube(
[0.1, chair.height, 0.1],
{ x: chair.width, y: chair.height / 2, z: -chair.depth + i * 0.2 },
chair.theme
);
}

cube(
[0.1, chair.height, 0.1],
{ x: -chair.width, y: chair.height / 2, z: chair.depth },
chair.theme
);

cube(
[0.1, chair.height, 0.1],
{ x: chair.width, y: chair.height / 2, z: chair.depth },
chair.theme
);

// ------ your code ends here ------

return { figures, features };
}
Insert cell
Insert cell
Insert cell
fxrand()
Insert cell
Insert cell
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x001b42);

//manufacture
genererFigures.figures.forEach((fig) => {
var geometry = new THREE[fig.geometry.type](...fig.geometry.args);
var edgeGeometry = new THREE.EdgesGeometry(geometry);

geometry.center();

var pos = new THREE.Vector3(fig.pos.x, fig.pos.y, fig.pos.z);
var rot = new THREE.Vector3(fig.rot.x, fig.rot.y, fig.rot.z);
if (fig.scale) {
var scale = new THREE.Vector3(fig.scale.x, fig.scale.y, fig.scale.z);
}

if (fig.lines) {
const line = new THREE.LineSegments(edgeGeometry, lineMaterial);
line.position.set(pos.x, pos.y, pos.z);
line.rotation.set(rot.x, rot.y, rot.z);
if (fig.scale) {
line.scale.set(scale.x, scale.y, scale.z);
}
scene.add(line);
}

if (fig.hatch) {
const hatch = new THREE.Mesh(geometry, hatchMaterial);
hatch.position.set(pos.x, pos.y, pos.z);
hatch.rotation.set(rot.x, rot.y, rot.z);
if (fig.scale) {
hatch.scale.set(scale.x, scale.y, scale.z);
}
scene.add(hatch);
}

if (fig.full) {
const full = new THREE.Mesh(geometry, fullMaterial);
full.position.set(pos.x, pos.y, pos.z);
full.rotation.set(rot.x, rot.y, rot.z);
if (fig.scale) {
full.scale.set(scale.x, scale.y, scale.z);
}
scene.add(full);
}
});

return scene;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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