]> gitweb.factorcode.org Git - factor.git/blob - contrib/lindenmayer/lindenmayer.factor
Nicer polygon-normal
[factor.git] / contrib / lindenmayer / lindenmayer.factor
1 ! Eduardo Cavazos - wayo.cavazos@gmail.com
2
3 REQUIRES: contrib/math
4           contrib/vars
5           contrib/slate/slate
6           contrib/lindenmayer/opengl
7           contrib/lindenmayer/turtle
8           contrib/lindenmayer/camera
9           contrib/lindenmayer/camera-slate ;
10
11 USING: kernel alien namespaces arrays vectors math opengl sequences threads
12        hashtables strings gadgets
13        math-contrib vars slate turtle turtle-camera camera-slate
14        opengl-contrib ;
15
16 IN: lindenmayer 
17
18 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
19
20 : record-vertex ( -- ) position> gl-vertex ;
21
22 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23
24 DEFER: polygon-vertex
25
26 : draw-forward ( length -- )
27 GL_LINES glBegin record-vertex step-turtle record-vertex glEnd ;
28
29 : move-forward ( length -- ) step-turtle polygon-vertex ;
30
31 : sneak-forward ( length -- ) step-turtle ;
32
33 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34
35 ! (v0 - v1) x (v1 - v2)
36
37 : polygon-normal ( {_v0_v1_v2_} -- normal ) first3 dupd v- -rot v- swap cross ;
38
39 : (polygon) ( vertices -- )
40 GL_POLYGON glBegin dup polygon-normal gl-normal [ gl-vertex ] each glEnd ;
41
42 : polygon ( vertices -- ) dup length 3 >= [ (polygon) ] [ drop ] if ;
43
44 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45
46 ! Maybe use an array instead of a vector
47
48 VAR: vertices
49
50 : start-polygon ( -- ) 0 <vector> >vertices ;
51
52 : finish-polygon ( -- ) vertices> polygon ;
53
54 : polygon-vertex ( -- ) position> vertices> push ;
55
56 : reset-vertices start-polygon ;
57
58 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
59 ! Lindenmayer string rewriting
60 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
61
62 ! Maybe use an array instead of a quot in the work of segment
63
64 VAR: rules
65
66 : segment ( str -- seq )
67 { { [ dup "" = ] [ drop [ ] ] }
68   { [ dup length 1 = ] [ unit ] }
69   { [ 1 over nth CHAR: ( = ]
70     [ CHAR: ) over index 1 +            ! str i
71       2dup head                         ! str i head
72       -rot tail                         ! head tail
73       segment swap add* ] }
74   { [ t ] [ dup 1 head swap 1 tail segment swap add* ] } }
75 cond ;
76
77 : lookup ( str -- str ) dup 1 head rules get hash dup [ nip ] [ drop ] if ;
78
79 : rewrite ( str -- str ) segment [ lookup ] map concat ;
80
81 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
82 ! Lindenmayer string interpretation
83 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
84
85 SYMBOL: command-table
86
87 : segment-command ( seg -- command ) 1 head ;
88
89 ! : segment-parameter ( seg -- parameter )
90 ! dup length 1 - 2 swap rot subseq parse call ;
91
92 : segment-parameter ( seg -- parameter )
93 dup length 1 - 2 swap rot subseq string>number ;
94
95 : segment-parts ( seg -- param command )
96 dup segment-parameter swap segment-command ;
97
98 : exec-command ( str -- ) command-table get hash dup [ call ] [ drop ] if ;
99
100 : exec-command-with-param ( param command -- )
101 command-table get hash dup [ peek unit call ] [ 2drop ] if ;
102
103 : (interpret) ( seg -- )
104 dup length 1 =
105 [ exec-command ] [ segment-parts exec-command-with-param ] if ;
106
107 : interpret ( str -- ) segment [ (interpret) ] each ;
108
109 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
110 ! Lparser dialect
111 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
112
113 VAR: angle
114 VAR: len
115 VAR: thickness
116 VAR: color-index
117
118 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
119
120 DEFER: set-thickness
121 DEFER: set-color-index
122
123 TUPLE: state position orientation angle len thickness color-index ;
124
125 VAR: states
126
127 : reset-state-stack ( -- ) V{ } clone >states ;
128
129 : save-state ( -- )
130 position> orientation> angle> len> thickness> color-index> <state>
131 states> push ;
132
133 : restore-state ( -- )
134 states> pop
135 dup state-position    >position
136 dup state-orientation >orientation
137 dup state-len         >len
138 dup state-angle       >angle
139 dup state-color-index set-color-index
140 dup state-thickness   set-thickness
141 drop ;
142
143 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
144
145 : scale-len ( m -- ) len> * >len ;
146
147 : scale-angle ( m -- ) angle> * >angle ;
148
149 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
150
151 VAR: color-table
152
153 : init-color-table ( -- )
154 { { 0    0    0 }    ! black
155   { 0.5  0.5  0.5 }  ! grey
156   { 1    0    0 }    ! red
157   { 1    1    0 }    ! yellow
158   { 0    1    0 }    ! green
159   { 0.25 0.88 0.82 } ! turquoise
160   { 0    0    1 }    ! blue
161   { 0.63 0.13 0.94 } ! purple
162   { 0.00 0.50 0.00 } ! dark green
163   { 0.00 0.82 0.82 } ! dark turquoise
164   { 0.00 0.00 0.50 } ! dark blue
165   { 0.58 0.00 0.82 } ! dark purple
166   { 0.50 0.00 0.00 } ! dark red
167   { 0.25 0.25 0.25 } ! dark grey
168   { 0.75 0.75 0.75 } ! medium grey
169   { 1    1    1 }    ! white
170 } [ 1 set-color-alpha ] map color-table set ;
171
172 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
173
174 : material-color ( color -- )
175 GL_FRONT_AND_BACK GL_AMBIENT_AND_DIFFUSE rot gl-material-fv ;
176
177 : set-color-index ( i -- )
178 dup >color-index color-table> nth dup gl-color material-color ;
179
180 : inc-color-index ( -- ) color-index> 1 + set-color-index ;
181
182 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
183
184 : set-thickness ( i -- ) dup >thickness glLineWidth ;
185
186 : scale-thickness ( m -- ) thickness> * 0.5 max set-thickness ;
187
188 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
189
190 VAR: default-values
191 VAR: model-values
192
193 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
194
195 : lparser-dialect ( -- )
196
197 [ 1 >len   45 >angle   1 >thickness   2 >color-index ] >default-values
198
199 H{ { "+" [ angle get     turn-left ] }
200    { "-" [ angle get     turn-right ] }
201    { "&" [ angle get     pitch-down ] }
202    { "^" [ angle get     pitch-up ] }
203    { "<" [ angle get     roll-left ] }
204    { ">" [ angle get     roll-right ] }
205
206    { "|" [ 180.0         rotate-y ] }
207    { "%" [ 180.0         rotate-z ] }
208    { "$" [ roll-until-horizontal ]  }
209
210    { "F" [ len get     draw-forward ] }
211    { "Z" [ len get 2 / draw-forward ] }
212    { "f" [ len get     move-forward ] }
213    { "z" [ len get 2 / move-forward ] }
214    { "g" [ len get     sneak-forward ] }
215    { "." [ polygon-vertex ] }
216
217    { "[" [ save-state ] }
218    { "]" [ restore-state ] }
219    { "{" [ start-polygon ] }
220    { "}" [ finish-polygon ] }
221
222    { "/" [ 1.1 scale-len ] } ! double quote command in lparser
223    { "'" [ 0.9 scale-len ] }
224    { ";" [ 1.1 scale-angle ] }
225    { ":" [ 0.9 scale-angle ] }
226    { "?" [ 1.4 scale-thickness ] }
227    { "!" [ 0.7 scale-thickness ] }
228
229    { "c" [ color-index> 1 + color-table get length mod set-color-index ] }
230
231 } command-table set ;
232
233 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
234
235 VAR: axiom
236 VAR: result
237
238 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
239
240 : iterate ( -- ) result> rewrite >result ;
241
242 : iterations ( n -- ) [ iterate ] times ;
243
244 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
245
246 VAR: model
247
248 : init-model ( -- ) 1 glGenLists >model ;
249
250 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
251
252 : display ( -- )
253
254 black gl-clear-color
255
256 GL_FLAT glShadeModel
257
258 GL_PROJECTION glMatrixMode
259 glLoadIdentity
260 -1 1 -1 1 1.5 200 glFrustum
261
262 GL_MODELVIEW glMatrixMode
263
264 glLoadIdentity
265
266 [ do-look-at ] camera> with-turtle
267
268 GL_COLOR_BUFFER_BIT glClear
269
270 GL_FRONT_AND_BACK GL_LINE glPolygonMode
271
272 white gl-color
273 GL_LINES glBegin { 0 0 0 } gl-vertex { 0 0 1 } gl-vertex glEnd
274
275 color-index> set-color-index
276
277 model> glCallList ;
278
279 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
280
281 : init-turtle ( -- ) <turtle> >turtle ;
282
283 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
284
285 : init-camera ( -- ) <turtle> >camera ;
286
287 : reset-camera ( -- ) [
288 reset-turtle
289 45 turn-left
290 45 pitch-up
291 5 step-turtle
292 180 turn-left
293 ] camera> with-turtle ;
294
295 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
296
297 : init-slate ( -- )
298 <camera-slate> >slate
299 namespace slate> set-slate-ns
300 slate> "L-system" open-titled-window
301 [ display ] >action ;
302
303 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
304
305 : init ( -- )
306 init-turtle
307 init-turtle-stack
308 init-camera reset-camera
309 init-model
310
311 2 >color-index
312 init-color-table
313
314 init-slate ;
315
316 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
317
318 : result>model ( -- )
319 [ model> GL_COMPILE glNewList result> interpret glEndList ] >action .slate ;
320
321 : build-model ( -- )
322 reset-state-stack
323 reset-vertices
324 reset-turtle
325 default-values> call
326 model-values> call
327 result>model
328 3000 sleep
329 [ display ] >action .slate ;
330
331 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
332 ! Examples
333 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
334
335 : koch ( -- ) lparser-dialect   [ 90 >angle ] >model-values
336
337 H{ { "K" "[[a|b] '(0.41)f'(2.439) |<(60) [a|b]]" }
338    { "k" "[ c'(0.5) K]" }
339    { "a" "[d <(120) d <(120) d ]" }
340    { "b" "e" }
341    { "e" "[^ '(.2887)f'(3.4758) &(180)      +z{.-(120)f-(120)f}]" }
342    { "d" "[^ '(.2887)f'(3.4758) &(109.5111) +zk{.-(120)f-(120)f}]" }
343 } >rules
344
345 "K" >axiom   axiom> >result ;
346
347 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
348
349 : spiral-0 ( -- ) lparser-dialect   [ 10 >angle 5 >thickness ] >model-values
350
351 "[P]|[P]" >axiom
352
353 H{ { "P" "[A]>>>>>>>>>[cB]>>>>>>>>>[ccC]>>>>>>>>>[cccD]" }
354    { "A" "F+;'A" }
355    { "B" "F!+F+;'B" }
356    { "C" "F!^+F^+;'C" }
357    { "D" "F!>^+F>^+;'D" }
358 } >rules
359
360 axiom> >result ;
361
362 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
363
364 : tree-5 ( -- ) lparser-dialect   [ 5 >angle   1 >thickness ] >model-values
365
366 "c(4)FFS" >result
367
368 H{ { "S" "FFR>(60)R>(60)R>(60)R>(60)R>(60)R>(30)S" }
369    { "R" "[Ba]" }
370    { "a" "$tF[Cx]Fb" }
371    { "b" "$tF[Dy]Fa" }
372    { "B" "&B" }
373    { "C" "+C" }
374    { "D" "-D" }
375
376    { "x" "a" }
377    { "y" "b" }
378
379    { "F" "'(1.25)F'(.8)" }
380 } >rules ;
381
382 : tree-5-scene ( -- )
383 tree-5
384 9 iterations
385 build-model
386 [ reset-turtle 90 pitch-down -70 step-turtle 50 strafe-up ] camera> with-turtle
387 .slate ;
388
389 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
390
391 : abop-1 ( -- ) lparser-dialect   [ 45 >angle   5 >thickness ] >model-values
392
393 H{ { "A" "F[&'(.8)!BL]>(137)'!(.9)A" }
394    { "B" "F[-'(.8)!(.9)$CL]'!(.9)C" }
395    { "C" "F[+'(.8)!(.9)$BL]'!(.9)B" }
396
397    { "L" "~c(8){+(30)f-(120)f-(120)f}" }
398 } >rules
399
400 "c(12)FFAL" >result ;
401
402 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
403
404 : abop-2 ( -- ) lparser-dialect   [ 30 >angle   5 >thickness ] >model-values
405
406 H{ { "A" "F[&'(.7)!BL]>(137)[&'(.6)!BL]>(137)'(.9)!(.9)A" }
407    { "B" "F[-'(.7)!(.9)$CL]'(.9)!(.9)C" }
408    { "C" "F[+'(.7)!(.9)$BL]'(.9)!(.9)B" }
409
410    { "L" "~c(8){+(45)f(.1)-(45)f(.1)-(45)f(.1)+(45)|+(45)f(.1)-(45)f(.1)-(45)f(.1)}" }
411
412 } >rules
413
414 "c(12)FAL" >result ;
415
416 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
417
418 : abop-3 ( -- ) lparser-dialect   [ 30 >angle   5 >thickness ] >model-values
419
420 H{ { "A" "!(.9)t(.4)FB>(94)B>(132)B" }
421    { "B" "[&t(.4)F$A]" }
422    { "F" "'(1.25)F'(.8)" }
423 } >rules
424
425 "c(12)FA" >result ;
426
427 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
428
429 : abop-4 ( -- ) lparser-dialect   [ 18 >angle   5 >thickness ] >model-values
430
431 H{ { "N" "FII[&(60)rY]>(90)[&(45)'(0.8)rA]>(90)[&(60)rY]>(90)[&(45)'(0.8)rD]!FIK" }
432    { "Y" "[c(4){++l.--l.--l.++|++l.--l.--l.}]" }
433    { "l" "g(.2)l" }
434    { "K" "[!c(2)FF>w>(72)w>(72)w>(72)w>(72)w]" }
435    { "w" "[c(2)^!F][c(5)&(72){-(54)f(3)+(54)f(3)|-(54)f(3)+(54)f(3)}]" }
436    { "f" "_" }
437
438    { "A" "B" }
439    { "B" "C" }
440    { "C" "D" }
441    { "D" "E" }
442    { "E" "G" }
443    { "G" "H" }
444    { "H" "N" }
445
446    { "I" "FoO" }
447    { "O" "FoP" }
448    { "P" "FoQ" }
449    { "Q" "FoR" }
450    { "R" "FoS" }
451    { "S" "FoT" }
452    { "T" "FoU" }
453    { "U" "FoV" }
454    { "V" "FoW" }
455    { "W" "FoX" }
456    { "X" "_" }
457
458    { "o" "$t(-0.03)" }
459    { "r" "~(30)" }
460 } >rules
461
462 "c(12)&(20)N" >result ;
463
464 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
465
466 : abop-5 ( -- ) lparser-dialect   [ 5 >angle   5 >thickness ] >model-values
467
468 H{ { "a" "F[+(45)l][-(45)l]^;ca" }
469
470    { "l" "j" }
471    { "j" "h" }
472    { "h" "s" }
473    { "s" "d" }
474    { "d" "x" }
475    { "x" "a" }
476
477    { "F" "'(1.17)F'(.855)" }
478 } >rules
479
480 "&(90)+(90)a" >result ;
481
482 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
483
484 : abop-6 ( -- ) lparser-dialect   [ 5 >angle   5 >thickness ] >model-values
485
486 "&(90)+(90)FFF[-(120)'(.6)x][-(60)'(.8)x][+(120)'(.6)x][+(60)'(.8)x]x" >result
487
488 H{ { "a" "F[cdx][cex]F!(.9)a" }
489    { "x" "a" }
490
491    { "d" "+d" }
492    { "e" "-e" }
493
494    { "F" "'(1.25)F'(.8)" }
495 } >rules ;
496
497 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
498
499 : airhorse ( -- ) lparser-dialect [ 10 >angle 5 >thickness ] >model-values
500
501 "C" >result
502
503 H{ { "C" "LBW" }
504
505    { "B" "[[''aH]|[g]]" }
506    { "a" "Fs+;'a" }
507    { "g" "Ft+;'g" }
508    { "s" "[::cc!!!!&&[FFcccZ]^^^^FFcccZ]" }
509    { "t" "[c!!!!&[FF]^^FF]" }
510
511    { "L" "O" }
512    { "O" "P" }
513    { "P" "Q" }
514    { "Q" "R" }
515    { "R" "U" }
516    { "U" "X" }
517    { "X" "Y" }
518    { "Y" "V" }
519    { "V" "[cc!!!&(90)[Zp]|[Zp]]" }
520    { "p" "h>(120)h>(120)h" }
521    { "h" "[+(40)!F'''p]" }
522
523    { "H" "[cccci[>(50)dcFFF][<(50)ecFFF]]" }
524    { "d" "Z!&Z!&:'d" }
525    { "e" "Z!^Z!^:'e" }
526    { "i" "-:/i" }
527
528    { "W" "[%[!!cb][<<<!!cb][>>>!!cb]]" }
529    { "b" "Fl!+Fl+;'b" }
530    { "l" "[-cc{--z++z++z--|--z++z++z}]" }
531 } >rules ;
532
533 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
534
535 ! These should be moved into a separate file. They are used to pretty
536 ! print matricies and vectors.
537
538 USING: styles prettyprint io ;
539
540 : decimal-places ( n d -- n )
541 10 swap ^ tuck * >fixnum swap /f ;
542
543 ! : .mat ( matrix -- ) [ [ 2 decimal-places ] map ] map . ;
544
545 : .mat ( matrix -- )
546 H{ { table-gap 4 } { table-border 4 } }
547 [ 2 decimal-places pprint ]
548 tabular-output ;
549
550 : .vec ( vector -- ) [ 2 decimal-places ] map . ;
551
552 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
553
554 PROVIDE: lindenmayer ;
555
556 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!