这是我试图消化的povray代码:
#include "colors.inc"
camera {
location <4, 0, -10>
look_at <4, 0, 0>
}
background{White}
light_source { <10, 10, 5> color White}
light_source { <0, 20, 0> color White}
//********************** Turtle Position ****************************
// These represent the position and angle of the turtle
#declare cylinderWidth=.1;
#declare locx = 0;
#declare locy = 0;
#declare myAngle = 0;
//************************* Macros **********************************
// This is a macro that moves the turtle forward by a distance s.
#macro kmove(s)
#declare locx_new = locx + s*cos(radians(myAngle));
#declare locy_new = locy + s*sin(radians(myAngle));
cylinder { <locx, locy, 0>, <locx_new, locy_new, 0>, s*cylinderWidth}
#declare locx = locx_new;
#declare locy = locy_new;
#end
// This is a macro that is recursive for moving the turtle around.
#macro koch(s, recursion_depth)
#if (recursion_depth > 0)
union {
object { koch(s/3, recursion_depth-1) }
object {
#declare myAngle = myAngle + 60;
koch(s/3, recursion_depth-1)
}
object {
#declare myAngle = myAngle -120;
koch(s/3, recursion_depth-1)
}
object {
#declare myAngle = myAngle + 60;
koch(s/3, recursion_depth-1)
}
}
#else
kmove(s);
#end
#end
//************************* Parameters **********************************
// This sets the number of levels of recursion
#declare myDepth = 0;
// This is the distance along x that the turtle moves.
#declare mySize = 8;
//*********************** DRAW THE TURTLE!! *******************************
// This is the command for actually drawing the Turtle's path based in the
// distance and levels of recursion.
object{
koch(mySize,myDepth)
pigment { color Blue }
}
我不明白的是涉及 if 语句的宏“koch”。它是如何制造圆柱体的,因为它不涉及函数 kmove(s)。似乎每次迭代都会产生三个线段,每个线段的长度为 s/3;然后它将它们旋转某个角度。但是当它甚至不涉及 kmove(s) 时,它是如何做到的呢?
另外,为什么没有任何翻译命令?不是每次迭代都会产生重叠的线段吗?
编辑:显然,我在发表这篇文章之前运行了代码,它确实有效。但是,从我上面所说的很明显,我想了解这段代码是如何工作的。