Updating examples to new organization of namespaces
[shapes.git] / examples / applications / doughnut.shape
blobfea5320382f72a28486f79b36493aaba19f02924
1 /** This file is part of Shapes.
2  **
3  ** Shapes is free software: you can redistribute it and/or modify
4  ** it under the terms of the GNU General Public License as published by
5  ** the Free Software Foundation, either version 3 of the License, or
6  ** any later version.
7  **
8  ** Shapes is distributed in the hope that it will be useful,
9  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  ** GNU General Public License for more details.
12  **
13  ** You should have received a copy of the GNU General Public License
14  ** along with Shapes.  If not, see <http://www.gnu.org/licenses/>.
15  **
16  ** Copyright 2008, 2014 Henrik Tidefelt
17  **/
19 ##needs ..Shapes..Graphics3D / revolutionbody
21 ##lookin ..Shapes
23 doughnutProfile:
24 [Geometry..circle 1.5cm]
25   >> [shift (3cm,0cm)] >> immerse >> [rotate3D dir:(1,0,0) angle:~90°]
27 square: \ x → x * x
29 doubleDoughnutProfile:
30 ( @defaultunit:1%C
31   |
32   [[range 0° 359° 10°].foldl
33     \ p e →
34     {
35       p--(^)<((0.5cm+1cm*[square [abs [cos e]]])*[dir e])>(^)
36     }
37     emptypath]--cycle
39   >> [shift (3cm,0cm)] >> immerse >> [rotate3D dir:(1,0,0) angle:~90°]
41 doughnut:
42     @nonstroking:[gray 0.8]
43   & @width:0.01bp            |** used to fill in object edges
44   & @stroking:[gray 0.8]    |** used to fill in object edges
45   & @join:JOIN_ROUND
46   & @reflections:0.7*[phong 25] + 0.3*[phong 0.5]
47   & @autointensity:[gray 0.3]
48   & @autoscattering:[phong 0.2]
49   & @facetresolution:1cm
50   & @shadeorder:'0          |** use '2 when targeting Adobe Reader or other viewers that can deal with gradient fills.
51   |
52 |**  [revolutionBody doughnutProfile phiSteps:'25 thetaSteps:'37]
53   [revolutionBody doubleDoughnutProfile phiSteps:'36 thetaSteps:'37]
55 lights: ( newLights << [shift (6cm,8cm,10cm)] [] [specular_light [gray 0.9]]
56 |**                    << [ambient_light [gray 0.3]]
57                     )
58 •world: newZSorter
59 •world << lights
60        << [rotate3D dir:(1,0,0) angle:~70°] [] doughnut
61 world: •world;
63 •page << @nonstroking:GRAY_BLACK | [fill [rectangle (~5cm,~4cm) (5cm,4cm)]]
64 •page << view [] world