Introducing a logo for Shapes.
[shapes.git] / examples / applications / ghfrontpic.shape
blob3520054f64103470b70179b64256e024bff6fcf6
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 Henrik Tidefelt
17  **/
19 |** This is an attempt to create a very dense 3D plot for the cover of Gustaf's thesis.
20 |** The plot combines a plot of a 2D density function (with density on the third axis) with
21 |** a cloud of samples from the distribution scattered on the ground below the density function.
23 ##needs centering
25 ##unit u = 1cm
27 |** For efficiency reasons, we would like the scatter points to be drawn as lines of zero length.
28 |** Then, the tiebreaker feature of surfaces cannot be used, and hence we must manually sort the
29 |** graphics such that the scatter points appear on top of the table.  This in turn, means that
30 |** the density function must be manually placed on top of the scatter points.
32 |** To use the same lightening on the table and on the surface, the lights are grouped in a single object:
33 lights: ( newLights << [shift (0cm,8cm,10cm)] [] [specular_light [gray 0.9]]
34                     << [ambient_light [gray 0.3]] )
36 |** The table works as a background for the plot.
37 •table: newZSorter
38 •table << lights
39        <<
40     @nonstroking:[gray 0.8]
41   & @width:0.01u            |** used to fill in object edges
42   & @stroking:[gray 0.8]    |** used to fill in object edges
43   & @reflections:0.7*[phong 25] + 0.3*[phong 0.5]
44   & @facetresolution:0.5u
45   & @shadeorder:'0          |** use '2 when targeting Adobe Reader or other viewers that can deal with gradient fills.
46   | [facet [immerse [rectangle (~2u,~2u) (2u,2u)]]]
47 table: •table;
49 colorScale: \ z .> [rgb 0.3+0.7*z 0 0]
51 surfacePoly4: \ c00 c11 z00 z01 z10 z11 .>
53   p00: [immerse c00*1u]
54   p11: [immerse c11*1u]
55         zHat: (0u,0u,1u)
56   [facet (p00+z00*zHat)--(p00.x,p11.y,z01*1u)--(p11.x,p00.y,z10*1u)--cycle]
57         &
58   [facet (p11+z11*zHat)--(p00.x,p11.y,z01*1u)--(p11.x,p00.y,z10*1u)--cycle]
60 surfacePoly3: \ c0 c1 c2 z0 z1 z2 .>
62         zHat: (0u,0u,1u)
63   [facet ([immerse c0*1u]+z0*zHat)--([immerse c1*1u]+z1*zHat)--([immerse c2*1u]+z2*zHat)--cycle]
65 •densitysurface: newZSorter
66 •densitysurface << lights
68     @nonstroking:[gray 0.8]
69   & @width:0.01u            |** used to fill in object edges
70   & @stroking:[gray 0.8]    |** used to fill in object edges
71   & @reflections:0.3*[phong 25] + 0.7*[phong 0.5]
72   & @facetresolution:0.5u
73   & @shadeorder:'0          |** use '2 when targeting Adobe Reader or other viewers that can deal with gradient fills.
74   |
76   •densitysurface
77    << [surfacePoly4 (0,0) (0.2,0.2) 1 2 2 1.5]
78    << [surfacePoly3 (0.2,0.2) (0.2,0.4) (0.1,0.5) 0.1 1 0.5]
80 densitysurface: •densitysurface;
82 scatterPoint: \ p .> [stroke [immerse p]--[immerse p]]
83 •scatterpoints: newGroup3D
84   @stroking: [gray 0.9]
85 & @width:0.03u
86 & @cap:CAP_ROUND
89   •scatterpoints
90          << [scatterPoint (0u,0u)]
91          << [scatterPoint (0.5u,0.7u)]
92          << [scatterPoint (0.5u,0.9u)]
93          << [scatterPoint (0.8u,0.7u)]
94          << [scatterPoint (~0.8u,~0.7u)]
96 scatterpoints: •scatterpoints;
99 •world: newGroup3D
100 •world
101  << table
102  << scatterpoints
103  << densitysurface
105 •page << [view [[rotate3D dir:(1,0,0) angle:~70°]*[rotate3D dir:(0,0,1) angle:20°] (•world)]]