Skip to content

Instantly share code, notes, and snippets.

@nstielau
Created July 11, 2018 22:29
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 nstielau/0d6bafed712bf0b34c18398e7e20a99e to your computer and use it in GitHub Desktop.
Save nstielau/0d6bafed712bf0b34c18398e7e20a99e to your computer and use it in GitHub Desktop.
Recursive Deciduous Trees
/* [Tree] */
// Base size for trunk
size = 25; //[10:500]
// Depth of recursion (more depth, more complexity)
depth = 8; //[1:9]
// ratio of bottom of branch to previous branch
widthBottom = 0.25; //[0.1:0.05:1.2]
// ratio of top of branch to previous branch
widthTop = 0.18; //[0.1:0.05:1.2]
/*
Based on "Procedurally Generated Trees" by steveweber314 on instructables
http://www.instructables.com/id/Procedurally-Generated-Trees/
*/
linear_extrude(10) {
branch(size = size, depth = depth);
}
module trapezoid(h = 10, bottom = 10, top = 5) {
points=[[-bottom/2, 0], [bottom/2, 0], [top/2, h], [-top/2, h]];
polygon(points);
}
module branch(size, depth, rotation) {
trapezoid(h = size, bottom = size*widthBottom, top = size*widthTop);
if (depth > 0) {
mod = rands(0.9,1,1)[0];
translate([0, size, 0]){
rotate([0, 0, -25])
branch(size*0.8*mod, depth-1);
rotate([0, 0, 25])
branch(size*0.8*mod, depth-1);
}
}
}
/* [Tree] */
// Base size for trunk
size = 25; //[10:500]
// Depth of recursion (more depth, more complexity)
depth = 8; //[1:9]
// ratio of bottom of branch to previous branch
widthBottom = 0.25; //[0.1:0.05:1.2]
// ratio of top of branch to previous branch
widthTop = 0.18; //[0.1:0.05:1.2]
/*
Based on "Procedurally Generated Trees" by steveweber314 on instructables
http://www.instructables.com/id/Procedurally-Generated-Trees/
*/
linear_extrude(10) {
branch(size = size, depth = depth);
}
module trapezoid(h = 10, bottom = 10, top = 5) {
points=[[-bottom/2, 0], [bottom/2, 0], [top/2, h], [-top/2, h]];
polygon(points);
}
module branch(size, depth, rotation) {
// Draw current branch segment
// If we have more segments to draw...
// Move cursor up to top of current segment
// Rotate left, draw branch and subbranches
// Rotate right, draw branch and subbraches
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment