1 /** This file is part of Shapes.
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
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.
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/>.
16 ** Copyright 2009, 2014, 2015 Henrik Tidefelt
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.
30 dynamic @demoArrows identity
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 & ( @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° ...]]
41 IO..•page << @width:10bp | @demoArrows
42 IO..•page << @width:3bp | [[shift (0m,~0.4dy)] @demoArrows]
43 IO..•page << @width:1bp | [[shift (0m,~0.6dy)] @demoArrows]
44 IO..•page << @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 @width.
51 dynamic @myHead identity dynamic [Graphics..ShapesArrow width:@width*(1.5+4.5bp/(1bp+@width)) ...]
54 [[Data..range 5° 350° 20°].foldl
56 ( p & ( @width:10bp*e/360° | [Graphics..stroke (12cm,~2cm)--(+[dir e]*4cm) head:@myHead]) )