1// Gate scene with dragon
2// by Jeffery P. Hansen
3//
4// For full picture use
5//  povray +SR230 +ER500 +W960 +H720 +A +D +P +i dragongate2.pov
6//
7// For foot adjustment use:
8//  povray +SR430 +ER500 +SC125 +EC350 +W960 +H720 +A +D +P +i dragongate2.pov
9//
10
11#declare showTrees = 0;
12#declare showPosts = 1;
13#declare showFence = 1;
14#declare showDragons = 1;
15#declare showSign = 1;
16#declare showCacti = 1;
17#declare DGView = 1;		/*	1 = regular view
18					2 = left dragon feet
19					3 = right dragon feet
20					4 = cactus view
21					5 = closeup?
22					6 = sign closeup
23					7 = gate closeup
24				*/
25
26#include "shapes.inc"
27#include "chars.inc"
28#include "colors.inc"
29#include "textures.inc"
30#include "woods.inc"
31#if (showTrees)
32#include "OLIVE.inc"
33#include "TOMTREE.inc"
34#end
35#include "dragon.inc"
36
37
38
39#declare cactusRand = seed(42);
40
41
42#declare PostRadius = 0.35;			// Radius of posts
43#declare AngleStart = 9;			// Start angle of TkGate text
44#declare AngleSpan = 21.0;			// Number of degrees though which to position text
45#declare AngleStep = -(AngleSpan/8.0);		// Number of degrees per letter
46
47//
48// A texture for wrought iron.
49//
50#declare Wrought_Iron =
51  texture {
52    pigment {
53      granite
54      color_map {
55        [0.0 1.0  colour red 0.2 green 0.2 blue 0.2
56                  colour red 0.0 green 0.0 blue 0.0]
57      }
58    }
59    finish { ambient 0 diffuse 0.6 metallic 1}
60    normal { wrinkles 1 scale 0.11 }
61  }
62
63#declare Cactus_Text =
64  texture {
65    pigment {
66      rgb <.1,.57,.1>
67    }
68    normal {
69      leopard 0.1
70      turbulence .1
71      scale <0.005,0.05,0.005>
72    }
73    finish { ambient 0.3 diffuse 0.6 }
74  }
75
76#declare CactusSpine_Text =
77  texture {
78    pigment {
79      rgb <.9,.9,.1>
80    }
81    finish { ambient 0.3 diffuse 0.6 }
82  }
83
84//
85// A period
86//
87#declare char_Period=
88  cylinder {<0,0.5,0>,<0,0.5,1>,0.5}
89
90
91#declare Post_Stone =
92 texture{
93   pigment{White}
94   normal{
95     granite 0.075
96     scale 0.24
97   }
98   finish{phong 0.1 phong_size 200 diffuse 0.2 ambient 0.5 }
99 }
100
101#declare Sand_Text =
102  texture {
103    pigment {
104      colour red 0.95 green 0.64 blue 0.38
105    }
106
107    normal {
108      crackle .25
109      turbulence 0.2
110      scale <1,0.05,0.1>
111      rotate 30*y
112    }
113    finish { ambient 0.7 diffuse 0.4 }
114  }
115
116//
117// The clouds
118//
119#declare GateClouds =
120  plane { y, 300.0
121    hollow on
122    pigment {
123      bozo
124      turbulence 1
125      colour_map {
126        [0.0 0.4   colour red 1.0 green 1.0 blue 1.0 filter 1.0
127                   colour red 1.0 green 1.0 blue 1.0 filter 1.0]
128        [0.4 0.8   colour red 1.0 green 1.0 blue 1.0 filter 1.0
129                   colour red 0.8 green 0.9 blue 0.9]
130        [0.8 1.001 colour red 0.9 green 0.9 blue 0.9
131                   colour red 0.8 green 0.8 blue 0.8]
132      }
133      quick_colour red 0.7 green 0.7 blue 1.0
134      scale <1000.0, 200.0, 800.0>
135    }
136    finish {
137      ambient 0.7
138      diffuse 0.0
139    }
140
141    translate -450*x
142    rotate 6*y
143  }
144
145
146//
147// The ground
148//
149#declare SandDunes =
150  intersection {
151    plane { z, 0 }
152    height_field {
153      png "hills.png"
154      smooth
155      translate <-0.5,0,-0.85>
156      scale <40,0.5,40>
157    }
158
159    hollow on
160    texture { Sand_Text }
161  }
162
163#declare GrassTexture =
164  texture {
165      pigment {
166	waves
167	turbulence 0.01
168        colour_map{
169             [0.0 colour rgb <0.2,0.4,0.1>]
170             [0.98 colour rgb <0.28,0.49,0.17>]
171             [1.0 colour rgb <0.38,0.39,0.11>]
172        }
173      }
174      scale <0.001,0.0001,.15>
175      finish{ ambient 0.2 diffuse 0.6 }
176  }
177
178#declare OldGrassTexture =
179  texture {
180      pigment {
181	bozo
182	turbulence 0.1
183	colour_map {
184          [0.0 1.0   colour red 0.2 green 1.0 blue 0.2 filter 0
185                     colour red 0.2 green 0.8 blue 0.2 filter 0]
186 	}
187      }
188      normal{
189   	wrinkles 0.1
190	scale 0.24
191      }
192
193
194      finish { ambient 0.2 diffuse 0.2 }
195    }
196
197#declare GrassHill =
198  intersection {
199    plane { z, .1 inverse }
200    height_field {
201      png "hills.png"
202      smooth
203      translate -0.5*x
204      scale <40,3,40>
205    }
206    hollow on
207    texture { GrassTexture }
208  }
209
210#declare XGrassHill =
211  union {
212//    height_field {
213//      png "hills2.png"
214//      smooth
215//      translate -0.5*x
216//      translate 5*z
217//      scale <200,50,200>
218//    }
219    height_field {
220      png "hills2.png"
221      smooth
222      translate -0.5*x
223      scale <50,3,50>
224    }
225    intersection {
226      plane { y, 0 }
227      plane { z, 0 inverse }
228    }
229
230    hollow on
231//    texture { GrassTexture }
232    texture { pigment { checker color Red, color Green } }
233  }
234
235
236#declare GateGround =
237  union {
238    object { SandDunes }
239    object { GrassHill }
240  }
241
242#declare CowOrFlat=0.5;
243#declare CowHeight=1.1;
244#declare CowThickness = 0.5;
245#declare CowLegLength = 0.5;
246#declare CowLegThickness = 0.1;
247
248#declare Cow_Texture =
249texture {
250    pigment {
251	bozo
252	frequency 0.9
253	scale .15
254        color_map {
255         [0.1 colour rgb <0,0,0> ]
256         [0.2 colour rgb <1,1,1> ]
257        }
258    }
259    finish { ambient 0.2 }
260}
261
262#declare CowLeg =
263  union {
264    cylinder { 0*y, CowLegLength*y, CowLegThickness }
265    object { sphere { <0,CowLegLength,0>, CowLegThickness } }
266  }
267
268
269#declare AndGateCow =
270   union {
271     union {
272       box { <0.0,0.0,0.0>, <0.8,1.1,CowThickness> }
273       object { cylinder { 0.0*z, CowThickness*z, 0.55 }  translate <0.8,0.55,0.0>  }
274       translate CowLegLength*y
275     }
276
277     object { CowLeg }
278     object { CowLeg translate <0.75,0,0> }
279     object { CowLeg translate <0,0,CowThickness> }
280     object { CowLeg translate <0.75,0,CowThickness> }
281
282     texture { Cow_Texture }
283   }
284
285
286//
287// Basic arc (actually a ring) that is used as parts of the OR gate.
288//
289#declare GateArc=
290  difference {
291    object { cylinder { 0.0*z, 0.1*z, 0.5 }  }
292    object { cylinder { z, -z, 0.4 }  }
293  }
294
295//
296// Back arc of an OR gate
297//
298#declare OrBack =
299  intersection {
300    object { GateArc }
301    plane {x, 0 inverse }
302    plane {y, -0.3 inverse }
303    plane {y, 0.3  }
304
305    translate <-0.4,0.3,0.0>
306  }
307
308
309#declare OrGateCow =
310   union {
311     intersection {
312       box { <0.0,0.0,0.0>, <CowOrFlat,CowHeight,CowThickness> }
313       object { cylinder { -2*z, 2*z, CowHeight inverse } translate <-CowHeight*0.85,CowHeight/2,0> }
314       translate CowLegLength*y
315     }
316
317     intersection {
318       object { cylinder { 0*z, CowThickness*z, CowHeight } translate <CowOrFlat,0,0> }
319       object { cylinder { -2*z, 2*z, CowHeight } translate <CowOrFlat,CowHeight,0> }
320       plane { x, 0.5 inverse }
321       translate CowLegLength*y
322     }
323
324     object { CowLeg }
325     object { CowLeg translate <0.75,0,0> }
326     object { CowLeg translate <0,0,CowThickness> }
327     object { CowLeg translate <0.75,0,CowThickness> }
328
329     texture { Cow_Texture translate 10*x }
330   }
331
332//
333// Define the posts that go on the sides of the gate.
334//
335#declare Post =
336  union {
337//    cylinder { 0*y, 4.25*y, PostRadius }
338    intersection {
339      object { box { <-PostRadius,0, -PostRadius>, <PostRadius, 4.25, PostRadius> }  }
340      object { box { <-PostRadius,0, -PostRadius>, <PostRadius, 4.25, PostRadius> } rotate 45*y  }
341    }
342
343    object { sphere { <0,0,0>, PostRadius }  translate 4.25*y }
344    object { sphere { <0,0,0>, PostRadius }  translate 4.75*y }
345//    texture { White_Marble }
346    texture { Post_Stone }
347//    texture { PinkAlabaster }
348  }
349
350//
351// A spike within the gate.  D is the distance from the center and is used both
352// to place the spike and to compute its height.
353//
354#macro Spike(D)
355   #local H = sin(acos(D/8.3))*8.3 - 5;
356   union {
357     object { cylinder { 0.2*y, H*y, 0.05 } }
358     merge {
359       object { Sphere scale <0.05, 0.05, 0.05>  translate 0.1*y }
360       object { Cone_Y scale <0.05, 0.1, 0.05>  translate 0.2*y }
361       object { Cone_Y scale <0.05, 0.05, 0.05>  translate 0.025*y }
362       translate H*y
363     }
364     translate D*x
365   }
366#end
367
368//
369// A spike on the fence
370//
371#declare FenceSpike =
372  union {
373    object { cylinder { 0.2*y, 4.0*y, 0.05 } }
374    merge {
375      object { Sphere scale <0.05, 0.05, 0.05>  translate 0.1*y }
376      object { Cone_Y scale <0.05, 0.1, 0.05>  translate 0.2*y }
377      object { Cone_Y scale <0.05, 0.05, 0.05>  translate 0.025*y }
378      translate 4.0*y
379    }
380  }
381
382//
383// Basic OR gate.
384//
385#declare OrGate =
386  union {
387    box { <0.0,0.5,0.0>, <0.25,0.6,0.1> }
388    box { <0.0,0.0,0.0>, <0.25,0.1,0.1> }
389
390    //
391    // The back of the OR gate
392    //
393    object { OrBack }
394
395    //
396    // Top-half of OR curve.
397    //
398    intersection {
399      intersection {
400	object { GateArc  }
401        plane {x, 0 inverse }
402        translate <0.25,0.1,0.0>
403      }
404      plane {y, 0.3 inverse }
405    }
406
407    //
408    // Bottom-half of OR curve.
409    //
410    intersection {
411      intersection {
412	object { GateArc  }
413        plane {x, 0 inverse }
414        translate <0.25,0.5,0.0>
415      }
416      plane {y,0.3 }
417    }
418  }
419
420//
421// Cut out of NOR gate.
422//
423#declare UnNOrGate =
424  union {
425    intersection {
426      box { <-0.001,0.1,0>, <0.25,0.5,0.1> }
427      object { cylinder { -0.1*z, 0.2*z, 0.5 } translate <-0.4,0.3, 0.0> inverse}
428    }
429    intersection {
430      object { cylinder { -0.001*z, 0.2*z, 0.4 } translate <0.25,0.5, 0> }
431      object { cylinder { -0.1*z, 0.2*z, 0.4 } translate <0.25,0.1, 0> }
432      plane {x, 0.25 inverse }
433    }
434    object { cylinder { -0.001*z, 0.1*z, 0.05 } translate <0.75, 0.3, 0> }
435  }
436
437
438#declare NOrGate =
439  union {
440    box { <0,0,0>, <0.1,0.05,0.05> translate <0.9,0.275,0>}
441    box { <0,0,0>, <0.1,0.05,0.05> translate <-0.1,0.45,0>}
442    box { <0,0,0>, <0.1,0.05,0.05> translate <-0.1,0.1,0>}
443
444    object { OrGate }
445      difference {
446        object { cylinder { 0.0*z, 0.1*z, 0.15 }  }
447        object { cylinder { z, -z, 0.05 }  }
448	translate <0.75, 0.3, 0>
449    }
450  }
451
452
453#declare DoorBase =
454  union {
455    Spike(1.7)
456    Spike(1.4)
457    Spike(1.1)
458    Spike(0.8)
459    Spike(0.5)
460    Spike(0.2)
461  }
462
463#declare Fence =
464  union {
465    //
466    // Fence cross beams
467    //
468    box { <2.0,0.5,-0.05>, <50.0,0.55,0.05> }
469    object { box { <2.0,0.5,-0.05>, <50.0,0.55,0.05> } translate 3.3*y }
470
471    //
472    // Fence
473    //
474    #local i = 0;
475    #while (i < 60)
476      object { FenceSpike translate (2.6+0.4*i)*x }
477      #local i = i + 1;
478    #end
479  }
480
481#macro Wire(X1,Y1,X2,Y2)
482  #local D = sqrt((X1-X2)*(X1-X2) + (Y1-Y2)*(Y1-Y2));
483  #local R = 90-atan2((X2-X1),(Y2-Y1))*180/3.1415926;
484  object {
485    box { <0,0,0>, <D,0.05,0.1> }
486    rotate R*z
487    translate <X1,Y1,0>
488  }
489#end
490
491//
492// Left half of the master/slave flip-flop circuit
493//
494#declare FlipFlopLeft =
495  union {
496    object { NOrGate translate < -1.2,2.3,0> }
497    object { NOrGate translate < -1.2,0.4,0> }
498
499    Wire(-1.875,0.5,   -1.175,0.5)				// Lower-left input B
500    Wire(-1.875,2.75,  -1.175 ,2.75)				// Upper-left input A
501
502    Wire(-0.4,2.575,  -0.025,2.575)				// Upper stage connect
503
504    Wire(-0.4,0.675,  -0.025,0.675)				// Lower stage connect
505
506
507    //
508    // UL to LL feedback path
509    //
510    Wire(-0.1,2.575,    -0.1,2.075)				// out/down from UL
511    Wire(-0.08,2.125,    -1.575,1.25)				// Diagonal
512    Wire(-1.575,1.25,   -1.575,0.85)				// Lower-left input A vertical
513    Wire(-1.575,0.85,   -1.175,0.85)				// Lower-left input A
514
515    //
516    // LL to UL feedback path
517    //
518    union {
519      Wire(-0.1,2.575,    -0.1,2.075)				// out/down from UL
520      Wire(-0.08,2.125,    -1.575,1.25)				// Diagonal
521      Wire(-1.575,1.25,   -1.575,0.85)				// Lower-left input A vertical
522      Wire(-1.575,0.85,   -1.175,0.85)				// Lower-left input A
523      scale <1,-1,1>
524      translate 3.3*y
525    }
526  }
527
528//
529// Right half of the master/slave flip-flop circuit
530//
531#declare FlipFlopRight =
532  union {
533    object { NOrGate translate < 0.4,2.125,0> }
534    object { NOrGate translate < 0.4,0.575,0> }
535
536    Wire(1.3,2.4,  1.875,2.4)					// Upper-right output
537    Wire(1.3,0.85,   1.875,0.85)				// Lower-right output
538
539    Wire(0.025,2.575,  0.45,2.575)				// Upper stage connect
540
541    Wire(0.025,0.675,  0.45,0.675)				// Lower stage connect
542
543
544    // UR to LR feedback
545    Wire(1.525,2.4,  1.525,2.125)				// UR
546    Wire(1.545,2.155, 0.025,1.25)  				// diagonal
547    Wire(0.025,1.25,  0.025,1.025)				// LR vertical
548    Wire(0.025,1.025,  0.45,1.025)				// LR in
549
550    union {
551      Wire(1.525,2.4,  1.525,2.125)				// UR
552      Wire(1.545,2.155, 0.025,1.25)  				// diagonal
553      Wire(0.025,1.25,  0.025,1.025)				// LR vertical
554      Wire(0.025,1.025,  0.45,1.025)				// LR in
555      scale <1,-1,1>
556      translate 3.3*y
557    }
558  }
559
560#declare FlipFlopCutOutLeft =
561  union {
562    object { UnNOrGate translate < -1.2,2.3,0> }
563    object { UnNOrGate translate < -1.2,0.4,0> }
564  }
565
566#declare FlipFlopCutOutRight =
567  union {
568    object { UnNOrGate translate < 0.4,2.125,0> }
569    object { UnNOrGate translate < 0.4,0.575,0> }
570  }
571
572//
573// This is the lettering in the logo.
574//
575#declare Lettering =
576  intersection {
577    union {
578      union {
579        object { char_T translate -2*x translate 88*y rotate (AngleStart+0*AngleStep)*z }
580        object { char_K translate -2*x translate 88*y rotate (AngleStart+1*AngleStep)*z }
581        object { char_G translate -2*x translate 88*y rotate (AngleStart+2*AngleStep)*z }
582        object { char_A translate -2*x translate 88*y rotate (AngleStart+3*AngleStep)*z }
583        object { char_T translate -2*x translate 88*y rotate (AngleStart+4*AngleStep)*z }
584        object { char_E translate -2*x translate 88*y rotate (AngleStart+5*AngleStep)*z }
585        object { char_2 translate -2*x translate 88*y rotate (AngleStart+6.5*AngleStep)*z }
586        object { char_Period translate -2*x translate 88*y rotate (AngleStart+7.25*AngleStep)*z }
587        object { char_0 translate -2*x translate 88*y rotate (AngleStart+8*AngleStep)*z }
588	scale <1.0,1.0,0.5>
589      }
590
591      intersection {
592        cylinder { 0*z, 0.05*z, 88 }
593        cylinder { -.01*z, 0.06*z, 87 inverse }
594      }
595      intersection {
596        cylinder { 0*z, 0.05*z, 94 }
597        cylinder { -.01*z, 0.06*z, 93 inverse }
598      }
599
600      translate -90*y
601      scale 0.1
602    }
603    plane { x, -2 inverse }
604    plane { x, 2 }
605  }
606
607
608#declare LeftDoor =
609  union {
610    intersection {
611      object { DoorBase scale <-1,1,1> }
612      object { FlipFlopCutOutLeft translate <0,0,-0.05> inverse }
613    }
614    object { FlipFlopLeft translate <0,0,-0.05> }
615
616    translate 1.9*x
617  }
618
619#declare RightDoor =
620  union {
621    intersection {
622      object { DoorBase }
623      object { FlipFlopCutOutRight translate <0,0,-0.05> inverse }
624    }
625    object { FlipFlopRight translate <0,0,-0.05> }
626
627    translate -1.9*x
628  }
629
630#declare Brackets =
631  union {
632    box { <0,0,0>, <0.3,0.05,0.1> translate <-2.125,2.8,0> }	// Upper-left bracket
633    box { <0,0,0>, <0.3,0.05,0.1> translate <-2.125,0.45,0> }	// Lower-left bracket
634    box { <0,0,0>, <0.3,0.05,0.1> translate <1.825,2.45> }	// Upper-right bracket
635    box { <0,0,0>, <0.3,0.05,0.1> translate <1.825,0.8,0> }	// Lower-right bracket
636  }
637
638//
639// This is all the ironwork in the gate
640//
641#declare IronWork =
642  union {
643    object { Lettering translate <0,4,-0.05> }
644    object { Fence }
645    object { Fence scale <-1,1,1> }
646
647    object { Brackets translate -0.05*z }
648
649    object { LeftDoor rotate -0*y translate -1.9*x }
650    object { RightDoor rotate 0*y translate 1.9*x }
651
652    texture { Wrought_Iron }
653  }
654
655   fog {
656    distance 1500
657    color rgb<0.3, 0.4, 1.0>
658    fog_type 2
659    fog_offset 100
660    fog_alt 1
661    turbulence 0.1
662    turb_depth 0.2
663  }
664
665
666  sky_sphere {
667    pigment {
668      gradient y
669      colour_map {
670//        [0.0 1.0  colour red 0.1 green 0.3 blue 1.0
671//                  colour red 0.1 green 0.6 blue 1.0]
672
673//        [0.0 1.0  colour red 0.4 green 0.4 blue 1.0
674//                  colour red 0.6 green 0.7 blue 1.0]
675
676        [0.0 1.0
677		  colour red 0.3 green 0.5 blue 0.6
678                  colour red 0.3 green 0.4 blue 1.0
679	]
680
681
682//        [0.0 1.0  colour red 0.0 green 0.0 blue 0.0
683//                  colour red 0.0 green 0.0 blue 1.0]
684      }
685      scale 0.5
686    }
687  }
688
689
690#declare BoardWidth=2.8;
691#declare BoardHeight=0.5;
692#declare BoardGap = 0.025;
693
694#declare Board =
695  difference {
696    box { <0,0,0>, <BoardWidth,BoardHeight,0.1> }
697  }
698
699#declare SignBase =
700  union {
701    object { Board translate (1.5+0*(BoardHeight+BoardGap))*y }
702    object { Board translate (1.5+1*(BoardHeight+BoardGap))*y }
703    object { Board translate (1.5+2*(BoardHeight+BoardGap))*y }
704
705    box { <0.0,0,0.12>, <0.1,1.5+3*BoardHeight+2*BoardGap,0.22> }
706    box { <BoardWidth-0.1,0,0.12>, <BoardWidth,1.5+3.1*BoardHeight,0.22> }
707
708    translate -BoardWidth/2*x
709
710    //Other possible woods: 18, 19, 20, 29, 30, 31
711    texture { T_Wood31 scale 0.5 }
712  }
713
714#declare CP_X = -BoardWidth/2+0.2;
715#declare CP_Y = 2.7;
716
717#macro newline()
718  #declare CP_X = -BoardWidth/2+0.2;
719  #declare CP_Y = CP_Y - (BoardHeight+BoardGap);
720#end
721
722#macro kern(C)
723  #declare CP_X = CP_X + 0.22*C;
724#end
725
726#macro putchar(C)
727    object {
728	C scale <0.05,0.05,0.05>
729	translate <CP_X,CP_Y,-.01>
730	texture { T_Wood4 }
731    }
732
733  #declare CP_X = CP_X + 0.22;
734#end
735
736#macro putschar(C)
737    object {
738	C scale <0.04,0.04,0.04>
739	translate <CP_X,CP_Y,-.01>
740	texture { T_Wood4 }
741    }
742
743  #declare CP_X = CP_X + 0.22*0.04/0.05;
744#end
745
746/////////////////////////////////////////////////////////////////////////////
747//
748// Put up the sign base and subtract out all of the letters.
749//
750/////////////////////////////////////////////////////////////////////////////
751#declare Sign =
752  difference {
753    object { SignBase }
754
755//Opening Gates to
756//Digital Circuit
757//Simulation
758
759    putchar(char_T)
760    putschar(char_H)
761    putschar(char_E)
762    kern(0.8)
763    putchar(char_G)
764    putschar(char_A)
765    putschar(char_T)
766    putschar(char_E)
767    putschar(char_W)
768    putschar(char_A)
769    putschar(char_Y)
770    kern(0.8)
771    putchar(char_T)
772    putschar(char_O)
773
774    newline()
775
776    putchar(char_D)
777    kern(-.15)
778    putschar(char_I)
779    kern(-.15)
780    putschar(char_G)
781    kern(-.15)
782    putschar(char_I)
783    kern(-.15)
784    putschar(char_T)
785    putschar(char_A)
786    putschar(char_L)
787    kern(0.8)
788    putchar(char_C)
789    kern(-.15)
790    putschar(char_I)
791    kern(-.15)
792    putschar(char_R)
793    putschar(char_C)
794    putschar(char_U)
795    kern(-.15)
796    putschar(char_I)
797    kern(-.15)
798    putschar(char_T)
799    newline()
800
801    putchar(char_S)
802    kern(-.15)
803    putschar(char_I)
804    kern(-.15)
805    putschar(char_M)
806    putschar(char_U)
807    putschar(char_L)
808    putschar(char_A)
809    putschar(char_T)
810    kern(-.15)
811    putschar(char_I)
812    kern(-.15)
813    putschar(char_O)
814    putschar(char_N)
815  }
816
817#declare SpineSet =
818  union {
819    #local SpineR = 0.005;
820    #local SpineLen = 0.1;
821
822    object { cone { <0,0,0>, SpineR, <SpineLen,0,0>, 0.0 } rotate 20*z }
823    object { cone { <0,0,0>, SpineR, <SpineLen,0,0>, 0.0 } rotate -20*z rotate 20*y }
824    object { cone { <0,0,0>, SpineR, <SpineLen,0,0>, 0.0 } rotate -20*z rotate -20*y }
825    texture { CactusSpine_Text }
826  }
827
828#macro SpineRow(X1,X2,Y)
829  union {
830    #local X = X1;
831    #while (X <= X2)
832      object { SpineSet rotate 90*y translate X*x }
833      #local X = X + 0.05;
834    #end
835    translate Y*y
836  }
837#end
838
839#declare CactusAndLeaf =
840  union {
841    #local TT = 0.05;
842    union {
843      box { <-0.35,-0.25,-TT>, <0,0.25,TT> }
844      cylinder { -TT*z, TT*z, 0.25 }
845      translate <-0.25,0,0>
846    }
847
848    object { SpineRow(-0.55,-0.1,0) translate -TT*z }
849    object { SpineRow(-0.55,-0.1,0.1) translate -TT*z }
850    object { SpineRow(-0.55,-0.1,-0.1) translate -TT*z }
851    object { SpineRow(-0.55,-0.15,0.2) translate -TT*z }
852    object { SpineRow(-0.55,-0.15,-0.2) translate -TT*z }
853    union {
854      object { SpineRow(-0.55,-0.1,0) translate -TT*z }
855      object { SpineRow(-0.55,-0.1,0.1) translate -TT*z }
856      object { SpineRow(-0.55,-0.1,-0.1) translate -TT*z }
857      object { SpineRow(-0.55,-0.15,0.2) translate -TT*z }
858      object { SpineRow(-0.55,-0.15,-0.2) translate -TT*z }
859      scale <1,1,-1>
860    }
861
862    scale 0.9
863  }
864
865#declare CactusOrLeaf =
866  union {
867    #local TT = 0.05;
868    intersection {
869
870      union {
871        box { <0,0,-TT>, <0.25,0.5,TT> }
872        intersection {
873	  box { <0,0,-TT>, <0.7,0.5,TT> }
874	  object { cylinder { -1*z, 1*z, 0.5 } translate <0.25,0,0> }
875	  object { cylinder { -1*z, 1*z, 0.5 } translate <0.25,0.5,0> }
876        }
877      }
878      object { cylinder { -1*z, 1*z, 0.5 } inverse translate <-0.4,0.25,0> }
879      translate <-.7,-.25,0>
880    }
881
882    object { SpineRow(-0.55,-0.1,0) translate -TT*z }
883    object { SpineRow(-0.55,-0.15,0.1) translate -TT*z }
884    object { SpineRow(-0.55,-0.15,-0.1) translate -TT*z }
885    object { SpineRow(-0.6,-0.3,0.2) translate -TT*z }
886    object { SpineRow(-0.6,-0.3,-0.2) translate -TT*z }
887    union {
888      object { SpineRow(-0.55,-0.1,0) translate -TT*z }
889      object { SpineRow(-0.55,-0.15,0.1) translate -TT*z }
890      object { SpineRow(-0.55,-0.15,-0.1) translate -TT*z }
891      object { SpineRow(-0.6,-0.3,0.2) translate -TT*z }
892      object { SpineRow(-0.6,-0.3,-0.2) translate -TT*z }
893      scale <1,1,-1>
894    }
895
896    scale 0.9
897  }
898
899#macro Cactus()
900  union {
901    #local CW = 0.2;
902    #local CH = 0.4;
903
904    sphere { <0,0,0>, CW scale <1,CH/CW,1> }
905
906    #local RZ1 = 20*(rand(cactusRand)-1)-5;
907    #local RZ2 = 20*(rand(cactusRand)-0);
908    #local RX1 = 20*(rand(cactusRand)-0.5);
909    #local RX2 = 20*(rand(cactusRand)-0.5);
910    #local RY = 60*(rand(cactusRand)-0.5);
911    #local L1 = rand(cactusRand);
912    #local L2 = rand(cactusRand);
913
914    #if (L1 < 0.5)
915      object { CactusOrLeaf rotate 30*x rotate RX1*z rotate RZ1*z translate <-0.15,-0.1,0> }
916    #else
917      object { CactusAndLeaf rotate 30*x rotate RX1*z rotate RZ1*z translate <-0.18,-0.1,0> }
918    #end
919
920    #if (L2 < 0.5)
921      object { CactusOrLeaf rotate 180*z rotate RX2*x rotate RZ2*z translate <0.15,0.1,0> }
922    #else
923      object { CactusAndLeaf rotate 180*z rotate RX2*x rotate RZ2*z translate <0.18,0.1,0> }
924    #end
925
926    #local A = 0;
927    #while (A < 360)
928
929
930	#local B = -30;
931	#while (B < 60)
932	  #local DX = CW*cos(B*Pi/180);
933	  #local DY = CH*sin(B*Pi/180);
934
935
936 	  object { SpineSet
937	    rotate B*z
938	    translate <DX,DY,0>
939	    rotate A*y }
940
941	  #local B = B + 10;
942        #end
943
944	#local A = A + 30;
945    #end
946
947    rotate RY*y
948    texture { Cactus_Text }
949  }
950#end
951
952#declare Cacti =
953  union {
954    object { Cactus() translate <-5,.45,-8> }
955    object { Cactus() translate <-8.9,.7,-4.7> } // Wing reflecting
956    object { Cactus() translate <5.5,.4,-7> }
957    object { Cactus() translate <2,.42,-8> }
958    object { Cactus() translate <8,.45,-6> }
959
960  }
961
962//
963// Put it all together here.
964//
965object { GateGround }					// The ground
966object { GateClouds }					// The clouds
967#if (showPosts)
968  object { Post translate -(1.95+PostRadius)*x }	// The left gate post
969  object { Post translate (1.95+PostRadius)*x }		// The right gate post
970#end
971#if (showFence)
972  object { IronWork }					// The iron work
973#end
974#if (showDragons)
975  #if (DGView = 7)
976    object { Dragon(3) rotate 0*y scale 0.4 translate <2,11,20> }
977  #else
978    object { Dragon(1) rotate 30*y scale 0.4 translate <-4.5,2.3,-4> }
979    object { Dragon(2) rotate 30*y scale <-0.4,0.4,0.4> translate <4.3,2.1,-4> }
980  #end
981#end
982#if (showSign)
983  object { Sign rotate -40*y translate <-3.8,0,-10> }
984#end
985#if (showCacti)
986  object { Cacti }
987#end
988#if (showTrees)
989  object { TREE scale 6 translate <-11,0.2,5>  }
990  object { TREE scale 6 translate <-4,0.8,7> }
991  object { TREE scale 6 translate <10,1.3,7> }
992#end
993
994//
995// Where are we anyway?
996//
997camera {
998  #switch (DGView)
999  #case (1)
1000    location  <6.0, 7.25, -20>		// Full view
1001    look_at <0,2.25,0>
1002  #break
1003  #case (2)
1004    location  <-4.5, 2, -8>		// left dragon feet
1005    look_at <-4.5,0,-4>
1006  #break
1007  #case (3)
1008    location  <4.3, 2, -8>		// left dragon feet
1009    look_at <4.4,0,-4>
1010  #break
1011  #case (4)
1012    location  <-5, 0.6, -9.5>		// Cactus view
1013    look_at <-5,.6,-8>
1014  #break
1015  #case (5)
1016    location  <0.0, 2.25, -8>		// Closeup
1017    look_at <0,2.25,0>
1018  #break
1019  #case (6)				// Sign closeup
1020    location <-3,2,-13>
1021    look_at <-3.8,2,-10>
1022    up <0,1,0>
1023  #break
1024  #case (7)				// Gate closeup
1025    location <0,2.5,-6>
1026    look_at <0,2.5,0>
1027    up <0,1,0>
1028  #end
1029}
1030
1031//light_source { <50.0, 40.0, -20.0> colour White *2 }
1032//light_source { <-99.0, 79.0, 20.0> colour White *1 }
1033//light_source { <0, 5.0, -20.0> colour White *1 }
1034//light_source { <0, 20.0, 20.0> colour White *1 }
1035
1036
1037//
1038// Let there be light!
1039//
1040#if (DGView = 7)
1041light_source {
1042  <200.0, 250.0, -250>
1043  colour White *3
1044  shadowless
1045}
1046
1047light_source {
1048  <-50.0, 90.0, -30>
1049  colour White*0.1
1050  shadowless
1051}
1052#else
1053light_source {
1054  <200.0, 250.0, -250>
1055  colour White *3
1056}
1057
1058light_source {
1059  <-50.0, 90.0, -30>
1060  colour White*0.1
1061  shadowless
1062}
1063#end
1064
1065