Skip to content

Instantly share code, notes, and snippets.

@benhardy
Last active December 16, 2015 11:18
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 benhardy/5426293 to your computer and use it in GitHub Desktop.
Save benhardy/5426293 to your computer and use it in GitHub Desktop.
Generate a broccoli using POV-Ray's macros, which can be recursive.
// Generate a broccoli like structure
#include "colors.inc"
#include "textures.inc"
light_source {
<-100, 400,-200>
color <0.8,0.8,0.8>
area_light <50,0,0>, <0,0,50>, 5, 5
adaptive 1
jitter
}
light_source {
<0,0,-100>
color <0.7,1.0,0.5>
area_light <20,0,0>, <0,20,0>, 5, 5
adaptive 1
jitter
}
camera {
location <-4, 5,-3>
look_at <0,1.0,0>
}
// This is the smallest size object we want to render
// The smaller this is, the more complex our resulting rendering will be (using more RAM and CPU too).
// use larger values for low quality test renders.
#declare CellSizeThreshold = 0.01;
#declare Cell = sphere { <0,0,0>,1 }
#declare TrunkRatio = 0.50;
#declare TrunkTwist = 32; // deg
#declare BranchRatio = 0.55;
#declare BranchAngle = 42;
#declare BranchCount = 5;
#declare InterBranchAngle = (360/BranchCount);
#macro Arrangement(Size)
#if (Size < CellSizeThreshold)
object { Cell } // having this outside a union avoids single-element union warning
#else
union {
object { Cell }
object { Arrangement(Size*TrunkRatio)
scale TrunkRatio
rotate y* TrunkTwist
translate y
}
#local branch = 0;
#while (branch < BranchCount)
object { Arrangement(Size*BranchRatio)
scale BranchRatio
rotate y* 60
translate y
rotate x*BranchAngle
rotate y *72*branch
}
#local branch = branch + 1;
#end
}
#end
#end
union {
Arrangement(1)
cylinder { <0,0,0>,<0,-1,0>,1 }
pigment { color <0.1, 0.6, 0> }
finish { diffuse 0.7 ambient 0.2 }
scale 1.5
}
plane {
y, 0
translate y*-1.5
pigment {
checker
color <0.10, 0.10, 0.10>
color <0.07, 0.07, 0.07>
scale 0.5
}
finish {
ambient 0.2 diffuse 0.6 reflection 0.2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment