Skip to content

Instantly share code, notes, and snippets.

@fogleman
Created October 17, 2016 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fogleman/cd4f199097446dceb8402ed10f1c40ec to your computer and use it in GitHub Desktop.
Save fogleman/cd4f199097446dceb8402ed10f1c40ec to your computer and use it in GitHub Desktop.
function flat_piece(r, h, a, o) {
var shape = CAG.fromPoints([
[0, 0],
[r, 0],
[cos(a) * r, sin(a) * r],
]);
shape = linear_extrude({height: h}, shape);
return shape.rotateZ(o);
}
function round_piece(r, h, a, o) {
var shape = CAG.circle({
center: [0, 0],
radius: r,
resolution: 360,
});
shape = linear_extrude({height: h}, shape);
return intersection(shape, flat_piece(r * 2, h, a, 0)).rotateZ(o);
}
function half_circle(r, h) {
var shape = CAG.circle({
center: [0, 0],
radius: r,
resolution: 360,
});
shape = linear_extrude({height: h}, shape);
square = CAG.fromPoints([
[-r, 0],
[r, 0],
[r, r],
[-r, r],
]);
square = linear_extrude({height: h}, square);
return intersection(shape, square);
}
function horizon(w, h, d) {
var shape = CAG.fromPoints([
[-w/2, 0],
[w/2, 0],
[w/2, -h],
[-w/2, -h],
]);
shape = linear_extrude({height: d}, shape);
return shape;
}
function main() {
var shapes = [];
var a = 9.4736842105;
for (var o = 0; o < 180 - a / 2; o += a * 2) {
var shape = round_piece(12, 0.5, a, o);
shapes.push(shape.setColor([0.75, 0.44, 0.22]));
}
for (var o = a; o < 180 - a / 2; o += a * 2) {
var r = Math.random() * 3 + 13;
var shape = flat_piece(r, 0.75, a, o);
shapes.push(shape.setColor([0.33, 0.25, 0.20]));
}
shapes.push(half_circle(4, 1).setColor([0.45, 0.16, 0.29]));
var h1 = horizon(26, 2, 1);
var h2 = horizon(26, 6, 1);
h2 = h2.translate([0, 1, 0]).rotateX(20);
shapes.push(h1.intersect(h2).setColor([0.96, 0.80, 0.59]));//(26, 2, 1).setColor([0.96, 0.80, 0.59]));
return union(shapes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment