File: lesson.cfdg

package info (click to toggle)
contextfree 3.4.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,448 kB
  • sloc: cpp: 37,995; lex: 414; makefile: 123; sh: 43; python: 34
file content (234 lines) | stat: -rw-r--r-- 3,965 bytes parent folder | download | duplicates (4)
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* CFDG Lesson */

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

shape 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 [ ]
}

shape 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.
}

shape SHAPES
{
	SQUARE []
	CIRCLE [b 0.3]
	TRIANGLE [b 0.5]
	TRIANGLE [r 60 b 0.7]
}

shape 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 rotation 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
}
shape 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
}

shape CHAPTER3
{
    ## RECURSION ##
    SPIRAL [ x 0 y 3 ]
}
shape 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 too small to see
}

shape 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
}
shape TREE
rule 20 {
	// first rule for TREE
    CIRCLE [ size 0.25 ]
    TREE [ y 0.1 size 0.97 ]
}
rule 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

shape BRANCH
{
    BRANCH_LEFT [ ]
    BRANCH_RIGHT [ ]
}
shape BRANCH_LEFT
rule {
    TREE [ rotate 20 ]
}
rule {
    TREE [ rotate 30 ]
}
rule {
    TREE [ rotate 40 ]
}
rule {
	// 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

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



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

shape 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 ]
}
shape TITLE1
{
	O_5by5 [ x 0 ]
	N_5by5 [ x 1.2 ]
	E_5by5 [ x 2.4 ]
}
shape TITLE2
{
	T_5by5 [ x 0 ]
	W_5by5 [ x 1.2 ]
	O_5by5 [ x 2.4 ]
}
shape 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 ]
}
shape TITLE4
{
	F_5by5 [ x 0 ]
	O_5by5 [ x 1.2 ]
	U_5by5 [ x 2.4 ]
	R_5by5 [ x 3.6 ]
}