-
Notifications
You must be signed in to change notification settings - Fork 5
Project: Small World
pentacular edited this page Sep 3, 2019
·
6 revisions
const tree = assemble()
.above(minkowski(Cube(), Sphere())
.material('leaves')
.as('leaves'))
.above(Cylinder(0.4, 2)
.material('wood'))
.above();
const grass = Cube(10, 10, 1)
.color('lightgreen')
.material('grass')
.below();
const field = Cube(10, 10, 2)
.color('yellow')
.material('paper')
.below()
.move(0, 0, 1);
const water = Cube(10, 10, 0.5)
.color('blue')
.material('water')
.below()
.move(0, 0, -0.5);
const mountain = () => hull(Square(10),
Point(Math.random() * 10 - 5,
Math.random() * 10 - 5,
Math.random() * 10),
Point(Math.random() * 10 - 5,
Math.random() * 10 - 5,
Math.random() * 10),
Point(Math.random() * 10 - 5,
Math.random() * 10 - 5,
Math.random() * 10),
Point(Math.random() * 10 - 5,
Math.random() * 10 - 5,
Math.random() * 10))
.material('rock')
.above()
.move(0, 0, -1);
const house = assemble()
.above(Triangle(4)
.scale([0.5, 1])
.extrude(3)
.rotateY(-90)
.center()
.material('wood'))
.above(Cube(3, 3, 2)
.material('brick'))
.above();
const cloud = Sphere(5)
.color('lightblue')
.material('glass')
.above()
.move(0, 0, 20);
const tile = () => {
let base;
let feature;
let skyFeature;
base = grass;
if (Math.random() < 0.3) {
feature = tree;
}
if (Math.random() < 0.1) {
feature = house;
}
if (Math.random() < 0.2) {
base = field;
feature = undefined;
}
if (Math.random() < 0.1) {
base = water;
feature = undefined;
}
if (Math.random() < 0.05) {
base = mountain();
feature = undefined;
}
return assemble(base, feature, skyFeature);
}
assemble(...numbers({ to: 20 * 20 })
.map(n => [Math.floor(n / 20), n % 20])
.map(([x, y]) => tile().move(x * 10, y * 10)));