chapter 1
1 First example:the snowflake curve
symbols:图像的节点,如F,RU,Axiom
turtle command:从左到右读取命令
F:划一条直线
RU:转向
Axiom:绘制图像的起点,每一个RGG工程中只能有一个起点,并且是代码保存后就存在的,但是视图中看不见;
==> 用右边的替代左边的
Axiom ==> F(2);
//用一条长度为2的线条替代起点
1.1 规则申明:会生成一个名为derivation的按钮
public void derivation() [
...
]
1.2 参数化(parametrization)
F(x)代表长度为x的直线
F(x) ==> F(x/3)
//使用x/3长的线条代替F
也可以直接在属性编辑器里更改线条属性
(但是视图结果改了,代码并没有改,reset后还是原来该有的样子,暂时还不知道这个功能的意义是什么)
2 Second example:Getting three-dimensional-Fractal cuboids
三维图像建立:RU、RH、RL 代表围绕三个不同的轴转动方向,转动两次后由平面啊图转化为三维图像
2.1 init指令
创建初始结构的一种方法,代码保存后函数内代码描述的结构就会出现在试图中
public void step ()
[
// replacement rule for structure
Box ==> Box(L, true) RU(90) Box(L, true) RU(-90) Box(L, true)
RU(-90) Box(L, true) RU(90) Box(L, true);
// rescaling of structure to one third of the previous scale
// so that the overall size remains the same
Scale(x) ==> Scale(x/3);
]
Box(x,ture) //代表长度为x的长方体,true 代表连续的盒子的面相邻
const 目前尝试只能在所有函数的最前面定义
const int L = 2;
scale 缩放
scale(x) //缩放x倍
scale的使用并没有改变几何结构的实际长度,只是视图的变化
另外不同于F(x)改变单个F的长度,scale是三维结构的整体缩放
// length of building blocks
const int L = 2;
protected void init ()
[
// create initial structure
Axiom ==>
Scale(1) // scaling factor of whole structure, initially 1
RU(90) Box(L, true)
RH(-90) RU(-90) Box(L, true)
RH(90) RU(-90) Box(L, true)
RH(-90) RU(-90) Box(L, true) Box(L, true)
RH(90) RU(-90) Box(L, true) Box(L, true)
RH(-90) RU(-90) Box(L, true) Box(L, true)
RH(90) RU(-90) Box(L, true) Box(L, true)
RH(90) RL(-90) Box(L, true);
]
public void step ()
[
// replacement rule for structure
Box ==> Box(L, true) RU(90) Box(L, true) RU(-90) Box(L, true)
RU(-90) Box(L, true) RU(90) Box(L, true);
// rescaling of structure to one third of the previous scale
// so that the overall size remains the same
Scale(x) ==> Scale(x/3);
]
3 Third example: Creating branched structures
好抽象,完全看不懂,想象不出来
F [RU(90) F] [RU(-90) F] F [RU(90) F] [RU(-90) F] F
^
//第一个分支,该括号内龟标单独执行,并保留离开的位置
//在执行完[]内的内容后龟标回到保留的原点处
龟标执行完分支的语句后会回到分支的起点
Fourth example: Declaring own symbols - Nodes and classes
在java中调用de.grogra.turtle.库
// X represents the growing tips of the binary tree.
// It will create a segment of the specified length
module X(float length);
protected void init ()
[
Axiom ==> X(1);
]
public void grow ()
[
// growth rule of a binary tree
X(len) ==> F(len)
[RU(30) X(len*0.7)] [RU(-30) X(len*0.7)];
//[RL(30) X(len*0.7)] [RL(-30) X(len*0.7)];
]
Capter2都是一些库里的函数介绍,看就完事了
chapter 4
初始化对象属性
protected void init ()
[
Axiom ==> Cylinder(2, 1).(setShader(WHITE))
Cone(1, 1).(setShader(BLUE))
Sphere(1).(setShader(RED), setTranslation(0, 0, 1));
]
没有办法在构造函数中构造对象的所有属性,所以有一个setter库可以调用,调用方式如下:
Cylinder(r, h).(setShader(color));
Sphere(1).(setShader(RED), setTranslation(0, 0, 1));
. + ()并逗号分隔的方法调用参数设置的函数
读取对象属性
在读取的时候方法也不同于普通的构造函数的参数
Cylinder(l, r) ==> Cone(l, r);
x:Cylinder(l, r) ==> Cone(l, r).($[shader] = x[shader]);
x:Cone(l, r) ==> Cylinder(l, r).(setShader(x[shader]));