Reusing Shapes
Make a Spear
#include "include/colors.inc"
camera {
location <0, -8, 0>
look_at <0, 0, 0>
}
cone {
<-4, 0, 0>, 0
<-1.5, 0, 0>, 0.8
pigment { Silver }
}
cylinder {
<-3, 0, 0>,
<5, 0, 0>,
0.3
pigment { BakersChoc }
}
light_source { <-2,-9,-5> colour White}
Declare Shape
Syntax:
#declare shapeName = union { //shape definition here }
An example in use:
#declare spear = union {
cone {
<-4, 0, 0>, 0
<-1.5, 0, 0>, 0.8
pigment { Silver }
}
cylinder {
<-3, 0, 0>,
<5, 0, 0>,
0.3
pigment { BakersChoc }
}
}
Using Shape
This goes underneath the declaration:
//add one spear:
object { spear }
//add another spear, move it backwards:
object { spear translate <0, 0, -1> }
//loops (add 10 spears):
#declare numOfSpears = -5;
#while (numOfSpears < 5)
object { spear translate <0, 0, numOfSpears> }
#declare numOfSpears = numOfSpears + 1;
#end
Putting it All Together
#include "include/colors.inc"
camera {
location <0, -8, 0>
look_at <0, 0, 0>
}
#declare spear = union {
cone {
<-4, 0, 0>, 0
<-1.5, 0, 0>, 0.8
pigment { Silver }
}
cylinder {
<-3, 0, 0>,
<5, 0, 0>,
0.3
pigment { BakersChoc }
}
}
light_source { <-2,-9,-5> colour White}
//add one spear:
object { spear }
//add another spear, move it backwards:
object { spear translate <0, 0, -1> }
Challenge
turn one of your challenges into a reusable shape, and display it multiple times