File: lesson.cfdg

package info (click to toggle)
contextfree 2.2%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,292 kB
  • ctags: 4,316
  • sloc: cpp: 20,388; yacc: 507; objc: 494; ansic: 270; makefile: 114; lex: 92; sh: 35; xml: 24
file content (217 lines) | stat: -rw-r--r-- 4,012 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* CFDG Lesson */

startshape TOC
	// each grammar file must
	// have a "startshape"
	// statement to say which
	// shape to begin with

rule TOC {
	// a "rule" statement says how
	// to compose a shape out of
	// other shapes

    CHAPTER1 { x 0 y 0 }
    CHAPTER2 { x 10 y 0 }
    CHAPTER3 { x 0 y -10 }
    CHAPTER4 { x 10 y -10 }
	// each entry in the rule
	// names a shape to draw and
	// some "adjustments" in curly
	// braces

    TITLES { }
}

rule CHAPTER1 {
    ## BASIC SHAPES ##
    SQUARE { x 2 y 5 size 3 }
    CIRCLE { x 6 y 5 size 3 }
    TRIANGLE { x 4 y 2 size 3 }
	// these shapes are special:
	// they draw a shape into the
	// image, centered at the
	// current location
    SHAPES { y 1 size 3 }
	// This tells you the relative
	// sizes and positions of each
	// basic shape.
}

rule SHAPES {
	SQUARE {}
	CIRCLE {b 0.3}
	TRIANGLE {b 0.5}
	TRIANGLE {r 60 b 0.7}
}

rule CHAPTER2 {
    ## BASIC ADJUSTMENTS ##
    SQUARE { }
	// empty adjustments
	// this is the lone square in
	// chapter 2's area

    SQUARE { x 3 y 7 }
	// adjust location

	// even though adjustments
	// are written after the shape
	// they are applied before!

    SQUARE { x 5 y 7 rotate 30 }
	// adjust rotation
    SQUARE { x 3 y 5 size 0.75 }
	// adjust size

	// notice that rotaion and size
	// are adjusted after location

    SQUARE { x 5 y 5
        brightness 0.5 }
	// adjust brightness

    SQUARE { x 7 y 6
	// shorthands:
        r 45 // for rotate
        s 0.7 // for size
        b 0.7 // for brightness
    }

    FOURSQUARE { x 5 y 1
        size 0.2 rotate 10 }
	// adjustments are cumulative
}
rule FOURSQUARE {
    SQUARE { x 0 y 0 size 5  3}
    SQUARE { x 0 y 5 size 2 4 }
    SQUARE { x 5 y 5 size 3 }
    SQUARE { x 5 y 0 size 2 }
	// even though these are
	// at locations and sizes
	// that seem big, they have
	// all been relocated, scaled
	// and rotated when the rule
	// for CHAPTER2 used
	// FOURSQUARE
	// Two SQUAREs have been
	// have been turned into
	// rectangles
}

rule CHAPTER3 {
    ## RECURSION ##
    SPIRAL { x 0 y 3 }
}
rule SPIRAL {
    CIRCLE { size 0.5 }
    SPIRAL { y 0.2
         rotate -3
         size 0.995 }
	// a shape can use itself so
	// long as it keeps getting
	// smaller

	// the system will stop the
	// recursion when the shapes
	// get to small to see
}

rule CHAPTER4 {
    ## RANDOMNESS ##
    TREE { x 1 y 0 }
    TREE { x 6 y 0 }
    TREE { x 1 y 4 }
    TREE { x 6 y 4 }
	// even though these are the
	// same shape used four
	// times, each looks different
}
rule TREE 20 {
	// first rule for TREE
    CIRCLE { size 0.25 }
    TREE { y 0.1 size 0.97 }
}
rule TREE 1.5 {
	// second rule for TREE
    BRANCH {  }
}
// When expanding a TREE, a
// rule is picked randomly.
// The first rule has been given a
// weight of 20, the second of 1.5,
// so the first will be picked
// proportionally more often

rule BRANCH {
    BRANCH_LEFT { }
    BRANCH_RIGHT { }
}
rule BRANCH_LEFT {
    TREE { rotate 20 }
}
rule BRANCH_LEFT {
    TREE { rotate 30 }
}
rule BRANCH_LEFT {
    TREE { rotate 40 }
}
rule BRANCH_LEFT {
	// empty rules are okay
}
// If no weight is given for a rule
// the weight is 1.  Hence, the
// above four rules are picked
// equally randomly

rule BRANCH_RIGHT {
    TREE { rotate -20 }
}
rule BRANCH_RIGHT {
    TREE { rotate -30 }
}
rule BRANCH_RIGHT {
    TREE { rotate -40 }
}
rule BRANCH_RIGHT {
	// empty rules are okay
}



## Utilities ##
include i_pix.cfdg
// The "include" statement reads
// in all the rules from another file.
// Any "startshape" in the included
// file is ignored.

rule TITLES {
	TITLE1 { x 0 y 8.5 }
	TITLE2 { x 10 y 8.5 }
	TITLE3 { x 0 y -1.5 }
	TITLE4 { x 10 y -1.5 }
}
rule TITLE1 {
	O_5by5 { x 0 }
	N_5by5 { x 1.2 }
	E_5by5 { x 2.4 }
}
rule TITLE2 {
	T_5by5 { x 0 }
	W_5by5 { x 1.2 }
	O_5by5 { x 2.4 }
}
rule TITLE3 {
	T_5by5 { x 0 }
	H_5by5 { x 1.2 }
	R_5by5 { x 2.4 }
	E_5by5 { x 3.6 }
	E_5by5 { x 4.8 }
}
rule TITLE4 {
	F_5by5 { x 0 }
	O_5by5 { x 1.2 }
	U_5by5 { x 2.4 }
	R_5by5 { x 3.6 }
}