Merge branch 'ht/graphs'
[shapes.git] / examples / features / arrowdemo.shape
blobdb1bd81bd4ab48b2c041a2d6cc328853a93a9c78
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 2009, 2014, 2015 Henrik Tidefelt
17  **/
19 ##lookin ..Shapes
20 ##lookin ..Shapes..Geometry
21 ##lookin ..Shapes..Graphics
23 /** First, the use of <rearAngle> is shown, and the ShapesArrow arrowhead is shown on strokes of varying
24  ** widths, both for straight and curved paths.
25  ** For comparison, the previously so heavily used MetaPostArrow is also drawn in blue.
26  **/
28 ##unit dy = 25mm
30 dynamic @demoArrows identity
31   dynamic (
32      [Graphics..stroke (0cm,1dy)--(+(5cm,0cm)) head:[Graphics..ShapesArrow rearAngle:240° ...]]
33    & [Graphics..stroke (0cm,0cm)--(+(5cm,0cm)) head:Graphics..ShapesArrow]
34    & [Graphics..stroke (0cm,~1dy)--(+(5cm,0cm)) head:[Graphics..ShapesArrow rearAngle:180° ...]]
35    & [Graphics..stroke [shift (0cm,~1dy)][]{c: [Geometry..circle 3cm] [c 2.4]--[c 3.5]} head:[Graphics..ShapesArrow rearAngle:240° ...]]
36    & [Graphics..stroke [shift (0cm,~2dy)][]{c: [Geometry..circle 3cm] [c 2.4]--[c 3.5]} head:Graphics..ShapesArrow]
37    & ( Traits..@stroking:Traits..RGB..BLUE | [Graphics..stroke [shift (5cm,~2dy)][]{c: [Geometry..circle 3cm] [c 2.4]--[c 3.5]} head:MetaPostArrow] )
38    & [Graphics..stroke [shift (0cm,~3dy)][]{c: [Geometry..circle 3cm] [c 2.4]--[c 3.5]} head:[Graphics..ShapesArrow rearAngle:180° ...]]
39   )
41 IO..•page << Traits..@width:10bp | @demoArrows
42 IO..•page << Traits..@width:3bp | [[shift (0m,~0.4dy)] @demoArrows]
43 IO..•page << Traits..@width:1bp | [[shift (0m,~0.6dy)] @demoArrows]
44 IO..•page << Traits..@width:0.3bp | [[shift (0m,~0.7dy)] @demoArrows]
47 /** This example ends with a demonstration of how dynamic definitions of an arrowhead allows the width
48  ** to be defined as any function of Traits..@width.
49  **/
51 dynamic @myHead identity dynamic [Graphics..ShapesArrow width:Traits..@width*(1.5+4.5bp/(1bp+Traits..@width)) ...]
53 IO..•page <<
54   [[Data..range 5° 350° 20°].foldl
55    \ p e →
56     ( p & ( Traits..@width:10bp*e/360° | [Graphics..stroke (12cm,~2cm)--(+[dir e]*4cm) head:@myHead]) )
57    null]