Instrumenting extensions with GPL and copyright notes.
[shapes.git] / resources / extensions / arrowheads.shext
blob6c17b884f855daf092f92c3f226d76471768cb55
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 MetaPostArrow: \ p ahLength:void ahAngle:30° fillAsStroking:true .>
20  (@blend:BLEND_NORMAL
21   |
22   { z: [p 0].p
23     theLength: [if [typeof ahLength]==§Void @width*6 ahLength]
24     l: [min theLength 0.9*[abs p]]
25     e: [p 0]--[p l]
26     (>
27       picture: @nonstroking:[if fillAsStroking @stroking @nonstroking]
28                |
29                [fill [[shift z]*[rotate ahAngle*0.5]*[shift ~z] e]--[reverse [[shift z]*[rotate ~ahAngle*0.5]*[shift ~z] e]]--cycle]
30       cut: 2*@width
31     <)
32   }
33  )
35 triangleArrow: \ p ahLength:void ahAngle:30° fillAsStroking:true .>
36  (@blend:BLEND_NORMAL
37   |
38   { sl: [p 0]
39     z: sl.p
40     d: [angle sl.T]
41     theLength: [if [typeof ahLength]==§Void @width*6 ahLength]
42     (>
43       picture: @nonstroking:[if fillAsStroking @stroking @nonstroking]
44                |
45                [fill (z+[dir d - ahAngle/2]*theLength)--z--(z+[dir d + ahAngle/2]*theLength)--cycle]
46       cut: 2*@width
47     <)
48   }
49  )
51 ##needs circle
53 twoCircles3DArrow:
55   ztf: \ z0 .>
56   {
57     z: [normalized z0]
58     x: [orthogonal z]
59     y: [cross z x]
60     [affinetransform3D x y z (0cm,0cm,0cm)]
61   }
63   \ p ahLength:void ahAngle:30° .>
64     { z: [p 0]
65       theLength: [if [typeof ahLength]==§Void @width*6 ahLength]
66       l: [min theLength*[cos ahAngle] 0.9*[abs p]]
67       e: [p 0]--[p l]
68       (>
69         picture: [stroke [[shift [p 0.5*theLength*[cos ahAngle]].p]*[ztf [p 0.5*theLength*[cos ahAngle]].T] [immerse [circle 0.5*theLength*[sin ahAngle]]]]]
70                  &
71                  [stroke [[shift [p theLength*[cos ahAngle]].p]*[ztf [p theLength*[cos ahAngle]].T] [immerse [circle theLength*[sin ahAngle]]]]]
72         cut: 0mm
73       <)
74     }
77 MetaPostArrow3D: \ normal p ahLength:void ahAngle:30° .>
78   { z: [p 0].p
79     theLength: [if [typeof ahLength]==§Void @width*6 ahLength]
80     l: [min theLength 0.9*[abs p]]
81     e: [p 0]--[p l]
82     rev: [reverse [[shift z]*[rotate3D dir:normal angle: ~ahAngle*0.5]*[shift ~z] e]]
83     (>
84       picture: [fill [[shift z]*[rotate3D dir:normal angle:ahAngle*0.5]*[shift ~z] e]--rev--cycle]
85                &
86                [fill [[shift z]*[rotate3D dir:normal angle:ahAngle*0.5]*[shift ~z] e]--[reverse [[shift z]*[rotate3D dir:normal angle: ~ahAngle*0.5]*[shift ~z] e]]--cycle]
87       cut: 0.8*[cos ahAngle*0.5]*theLength
88     <)
89   }
91 triangleArrow3D: \ p normal:(0,0,1) ahLength:void ahAngle:30° .>
92   { sl: [p 0]
93     z: sl.p
94     l: [if [typeof ahLength]==§Void @width*6 ahLength]
95     rotDir1: [cross sl.T [orthogonal sl.T]]
96     (>
97       picture:
98         { rotDir: rotDir1
99           fill [] [shift z] [] ( (0m,0m,0m)--([rotate3D dir:rotDir angle:ahAngle*0.5][](l*sl.T))--([rotate3D dir:rotDir angle:~ahAngle*0.5][](l*sl.T))--cycle ) }
100         &
101         { rotDir: [cross sl.T rotDir1]
102           fill [] [shift z] [] ( (0m,0m,0m)--([rotate3D dir:rotDir angle:ahAngle*0.5][](l*sl.T))--([rotate3D dir:rotDir angle:~ahAngle*0.5][](l*sl.T))--cycle ) }
103       cut: 2*@width
104     <)
105   }