mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-19 18:22:05 +02:00
Added initial Fractal Tree demo tutorial. Still need to gen images.
This commit is contained in:
@@ -1,48 +1,17 @@
|
||||
include <BOSL2/std.scad>
|
||||
include <BOSL2/paths.scad>
|
||||
include <BOSL2/beziers.scad>
|
||||
|
||||
module leaf(s) {
|
||||
path = [
|
||||
[0,0], [1.5,-1],
|
||||
[2,1], [0,3], [-2,1],
|
||||
[-1.5,-1], [0,0]
|
||||
];
|
||||
xrot(90)
|
||||
linear_sweep_bezier(
|
||||
scale_points(path, [s,s]/2),
|
||||
height=0.02
|
||||
);
|
||||
}
|
||||
|
||||
module branches(minsize, s1, s2){
|
||||
if(s2>minsize) {
|
||||
module tree(l=1500, sc=0.7, depth=10)
|
||||
recolor("lightgray")
|
||||
cylinder(l=l, d1=l/5, d2=l/5*sc)
|
||||
attach(TOP)
|
||||
zrot(gaussian_rands(90,20)[0])
|
||||
zrot_copies(n=floor(log_rands(2,5,4)[0]))
|
||||
zrot(gaussian_rands(0,5)[0])
|
||||
yrot(gaussian_rands(30,10)[0]) {
|
||||
sc = gaussian_rands(0.7,0.05)[0];
|
||||
cylinder(d1=s2, d2=s2*sc, l=s1)
|
||||
branches(minsize, s1*sc, s2*sc);
|
||||
}
|
||||
} else {
|
||||
recolor("springgreen")
|
||||
attach(TOP) zrot(90)
|
||||
leaf(gaussian_rands(100,5)[0]);
|
||||
}
|
||||
}
|
||||
|
||||
module tree(h, d, minsize) {
|
||||
sc = gaussian_rands(0.7,0.05)[0];
|
||||
recolor("lightgray") {
|
||||
cylinder(d1=d, d2=d*sc, l=h) {
|
||||
branches(minsize, h, d*sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tree(d=300, h=1500, minsize=10);
|
||||
if (depth>0)
|
||||
zrot(90)
|
||||
zrot_copies(n=2)
|
||||
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();
|
||||
|
||||
|
||||
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
||||
|
48
examples/randomized_fractal_tree.scad
Normal file
48
examples/randomized_fractal_tree.scad
Normal file
@@ -0,0 +1,48 @@
|
||||
include <BOSL2/std.scad>
|
||||
include <BOSL2/paths.scad>
|
||||
include <BOSL2/beziers.scad>
|
||||
|
||||
module leaf(s) {
|
||||
path = [
|
||||
[0,0], [1.5,-1],
|
||||
[2,1], [0,3], [-2,1],
|
||||
[-1.5,-1], [0,0]
|
||||
];
|
||||
xrot(90)
|
||||
linear_sweep_bezier(
|
||||
scale_points(path, [s,s]/2),
|
||||
height=0.02
|
||||
);
|
||||
}
|
||||
|
||||
module branches(minsize, s1, s2){
|
||||
if(s2>minsize) {
|
||||
attach(TOP)
|
||||
zrot(gaussian_rands(90,20)[0])
|
||||
zrot_copies(n=floor(log_rands(2,5,4)[0]))
|
||||
zrot(gaussian_rands(0,5)[0])
|
||||
yrot(gaussian_rands(30,10)[0]) {
|
||||
sc = gaussian_rands(0.7,0.05)[0];
|
||||
cylinder(d1=s2, d2=s2*sc, l=s1)
|
||||
branches(minsize, s1*sc, s2*sc);
|
||||
}
|
||||
} else {
|
||||
recolor("springgreen")
|
||||
attach(TOP) zrot(90)
|
||||
leaf(gaussian_rands(100,5)[0]);
|
||||
}
|
||||
}
|
||||
|
||||
module tree(h, d, minsize) {
|
||||
sc = gaussian_rands(0.7,0.05)[0];
|
||||
recolor("lightgray") {
|
||||
cylinder(d1=d, d2=d*sc, l=h) {
|
||||
branches(minsize, h, d*sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tree(d=300, h=1500, minsize=10);
|
||||
|
||||
|
||||
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
Reference in New Issue
Block a user