Public
Edited
Jan 17, 2023
Insert cell
Insert cell
//renderer.domElement
Insert cell
Insert cell
genererFigures = {
const figures = [];
const features = { Name: "" };

// you can't import anything from outside (no functions or libraries)
// you should not produce any collateral effect
// You have access to fxrand()

// if you are unsure of the scale, make all geometry sizes and positions related
// to a constant;

// you can use the anaverse bool to decide if a function has to be executed in
// anaverse or out of it.
// In the anaverse, there is a global (worker-wide) constant as
// const anaverse = true;
//

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

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

function addcube(figures, u, a, b, c, x, y, z, t, empt) {
let empty = empt ? true : fxrand() < 0.2;
figures.push({
geometry: {
type: "BoxGeometry", // Type of geometry
args: [
// Arguments relevant to the geometry (check THREE API)
a * u, // Cube width
b * u, // Cube height
c * u // Cube depth
]
},
pos: {
// Position
x: x * u,
y: y * u,
z: z * u
},
rot: {
// Rotation
x: 0,
y: 0,
z: 0
},
lines: empty ? true : t, // Display color segments (like wireframe, but faces not triangles)
hatch: empty ? false : t, // Fill with white texture
full: empty ? false : !t // Fill with color texture (in the anaverse, red and cyan)
});
}

let h = 2 + rint(15);
let w = 2 + rint(15);

if (fxrand() < 0.5) {
h = 3;
} else {
w = 3;
}

let density = 0.1 + fxrand() * 0.7;

function addpass(empty) {
for (let x = -h / 2; x < h / 2; ++x) {
for (let y = -w / 2; y < w / 2; ++y) {
if (fxrand() < density) {
var a = rint(3);
if (a === 0) {
a = 0.1;
}
var b = rint(3);
if (b === 0) {
b = 0.1;
}
addcube(
figures,
u,
a,
0.1,
b,
x * 2,
rint(10),
y * 2,
fxrand() < 0.5,
empty
);
}
}
}
}

addpass();

if (density < 0.3 && fxrand() < 0.7) {
addpass();
}

if (figures.length < 10) {
density = 0.8;
addpass();
}

if (fxrand() < 0.3) {
addpass(true);
}

//simple cube

//addcube(figures,u, a, b, c, x, y, z, t)

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

return { figures, features };
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { encreur } from "@guillaume-levrier/encreur"
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