Initial script to generate tutorial images.

This commit is contained in:
Revar Desmera
2020-03-24 00:02:24 -07:00
parent cb42c0d9aa
commit a3c917bfe9
4 changed files with 400 additions and 60 deletions

View File

@@ -2,78 +2,55 @@
### Start with a Tree Trunk
Firstoff, include the BOSL2 library, then add a tapered cylinder for the tree trunk.
Firstoff, include the BOSL2 library, then make a starting module that just has a tapered cylinder for the tree trunk.
```openscad-example
```openscad
include <BOSL2/std.scad>
cylinder(l=1500, d1=300, d2=210);
module tree(l=1500, sc=0.7)
cylinder(l=l, d1=l/5, d2=l/5*sc);
tree();
```
### Parameterize It
### Attaching a Branch
It's easier to adjust a model if you split out the defining parameters.
You can attach a branch to the top of the trunk by using `attach()` as a child of the trunk cylinder.
```openscad-example
include <BOSL2/std.scad>
l = 1500;
sc = 0.7;
cylinder(l=l, d1=l/5, d2=l/5*sc);
```
### Attaching Branches
You can attach branches to the top of the trunk by using `attach()` as a child of the trunk cylinder.
```openscad-example
include <BOSL2/std.scad>
l = 1500;
sc = 0.7;
cylinder(l=l, d1=l/5, d2=l/5*sc) {
attach(TOP) yrot( 30) cylinder(l=l*sc, d1=l/5*sc, d2=l/5*sc*sc);
attach(TOP) yrot(-30) cylinder(l=l*sc, d1=l/5*sc, d2=l/5*sc*sc);
}
```
### Replicate Branches
Instead of attaching each branch individually, you can attach multiple branch copies at once.
```openscad-example
include <BOSL2/std.scad>
l = 1500;
sc = 0.7;
cylinder(l=l, d1=l/5, d2=l/5*sc)
attach(TOP)
zrot_copies(n=2) // Make multiple rotated copies
yrot(30) cylinder(l=l*sc, d1=l/5*sc, d2=l/5*sc*sc);
```
### Make it a Module
Lets make this into a module, for convenience.
```openscad-example
```openscad
include <BOSL2/std.scad>
module tree(l=1500, sc=0.7)
cylinder(l=l, d1=l/5, d2=l/5*sc)
attach(TOP)
zrot_copies(n=2)
yrot(30) cylinder(l=l*sc, d1=l/5*sc, d2=l/5*sc*sc);
tree();
```
### Replicating the Branch
Instead of attaching each branch individually, you can make multiple copies of one branch, that are rotated relative to each other.
```openscad
include <BOSL2/std.scad>
module tree(l=1500, sc=0.7)
cylinder(l=l, d1=l/5, d2=l/5*sc)
attach(TOP)
zrot_copies(n=2) // Replicate that branch
yrot(30) cylinder(l=l*sc, d1=l/5*sc, d2=l/5*sc*sc);
tree();
```
### Use Recursion
Since branches look much like the main trunk, we can make it recursive. Don't forget the termination clause, or else it'll try to recurse forever!
Since branches look much like the main trunk, we can make the tree recursive. Don't forget the termination clause, or else it'll try to recurse forever!
```openscad-example
```openscad-Med
include <BOSL2/std.scad>
module tree(l=1500, sc=0.7, depth=10)
cylinder(l=l, d1=l/5, d2=l/5*sc)
attach(TOP)
if (depth>0) // Important!
if (depth>0) { // Important!
zrot_copies(n=2)
yrot(30) tree(depth=depth-1, l=l*sc, sc=sc);
}
tree();
```
@@ -81,15 +58,16 @@ tree();
A flat planar tree isn't what we want, so lets bush it out a bit by rotating each level 90 degrees.
```openscad-example
```openscad-Med
include <BOSL2/std.scad>
module tree(l=1500, sc=0.7, depth=10)
cylinder(l=l, d1=l/5, d2=l/5*sc)
attach(TOP)
if (depth>0)
if (depth>0) {
zrot(90) // Bush it out
zrot_copies(n=2)
yrot(30) tree(depth=depth-1, l=l*sc, sc=sc);
}
tree();
```
@@ -97,18 +75,19 @@ tree();
Let's add leaves. They look much like squashed versions of the standard teardrop() module, so lets use that.
```openscad-example
```openscad-Big
include <BOSL2/std.scad>
module tree(l=1500, sc=0.7, depth=10)
cylinder(l=l, d1=l/5, d2=l/5*sc)
attach(TOP)
if (depth>0)
if (depth>0) {
zrot(90)
zrot_copies(n=2)
yrot(30) tree(depth=depth-1, l=l*sc, sc=sc);
else
} else {
yscale(0.67)
teardrop(d=l*3, l=1, anchor=BOT, spin=90);
}
tree();
```
@@ -119,21 +98,21 @@ their descendants to the new color, even if they were colored before. The `recol
however, will only color children and decendants that don't already have a color set by a more
nested `recolor()`.
```openscad-example
```openscad-Big
include <BOSL2/std.scad>
module tree(l=1500, sc=0.7, depth=10)
recolor("lightgray")
cylinder(l=l, d1=l/5, d2=l/5*sc)
attach(TOP)
if (depth>0)
if (depth>0) {
zrot(90)
zrot_copies(n=2)
yrot(30)
tree(depth=depth-1, l=l*sc, sc=sc);
else
yrot(30) tree(depth=depth-1, l=l*sc, sc=sc);
} else {
recolor("springgreen")
yscale(0.67)
teardrop(d=l*3, l=1, anchor=BOT, spin=90);
}
tree();
```