Improvements to namespaces and file inclusion
[shapes.git] / examples / doc / tutorial-one-segment.shape
blobcc128cb9448d4b9c00d4ddf82a34d71cf622a43c
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 ##lookin ..Shapes
21 pathStyle: @width: 1bp
22 controlStyle: @width: 0.3bp & @dash:[dashpattern 2mm 2mm] & @stroking:[gray 0.5]
23 onPathMark: @nonstroking:RGB_RED | [fill [circle 1mm]]
24 controlHead: \ p → (> cut:0bp
25                        picture: @width:1bp & @stroking:RGB_RED & @dash:[dashpattern] | ([shift p.begin.p]*[rotate [angle p.begin.T]])[][stroke (~1.5mm,~1.5mm)--(1.5mm,1.5mm) & (~1.5mm,1.5mm)--(1.5mm,~1.5mm)]
26                     <)
28 twoHandlesHelper: \ p0 p1 p2 p3 →
30   [[shift p0] onPathMark]
31   &
32   [[shift p3] onPathMark]
33   &
34   ( controlStyle | [stroke p0--p1 head:controlHead] )
35   &
36   ( controlStyle | [stroke p3--p2 head:controlHead] )
37   &
38   ( pathStyle | [stroke p0>p1--p2<p3] )
41 frontHandlesHelper: \ p0 p1 p3 →
43   [[shift p0] onPathMark]
44   &
45   [[shift p3] onPathMark]
46   &
47   ( controlStyle | [stroke p0--p1 head:controlHead] )
48   &
49   ( pathStyle | [stroke p0>p1--p3] )
52 rearHandlesHelper: \ p0 p2 p3 →
54   [[shift p0] onPathMark]
55   &
56   [[shift p3] onPathMark]
57   &
58   ( controlStyle | [stroke p3--p2 head:controlHead] )
59   &
60   ( pathStyle | [stroke p0--p2<p3] )
63 noHandlesHelper: \ p0 p3 →
65   [[shift p0] onPathMark]
66   &
67   [[shift p3] onPathMark]
68   &
69   ( pathStyle | [stroke p0--p3] )
72 twoHandles: \ s1 s2 →
74   p0: (0cm,0cm)
75   p3: (6cm,1cm)
76   p1: p0+s1*1.5cm*[dir 60°]
77   p2: p3+s2*3cm*[dir ~165°]
78   [if s1 = 0
79       [if s2 = 0
80           [noHandlesHelper p0 p3]
81           [rearHandlesHelper p0 p2 p3]]
82       [if s2 = 0
83           [frontHandlesHelper p0 p1 p3]
84           [twoHandlesHelper p0 p1 p2 p3]]]
87 ##unit dy = 1cm
88 ##unit dx = 7cm
90 •page << [shift (0dx,0dy)] [] [twoHandles 1 1]
91       << [shift (0dx,~1dy)] [] [twoHandles 1 1/2]
92       << [shift (0dx,~2dy)] [] [twoHandles 1 1/4]
93       << [shift (0dx,~3dy)] [] [twoHandles 1 0.001]
94       << [shift (0dx,~4dy)] [] [twoHandles 1 0]
96       << [shift (1dx,~4dy)] [] [twoHandles 1/2 0]
97       << [shift (2dx,~4dy)] [] [twoHandles 1/4 0]
98       << [shift (3dx,~4dy)] [] [twoHandles 0.001 0]
99       << [shift (4dx,~4dy)] [] [twoHandles 0 0]
101       << [shift (1dx,0dy)] [] [twoHandles 1/2 1]
102       << [shift (2dx,0dy)] [] [twoHandles 1/4 1]
103       << [shift (3dx,0dy)] [] [twoHandles 0.001 1]
104       << [shift (4dx,0dy)] [] [twoHandles 0 1]
106       << [shift (4dx,~1dy)] [] [twoHandles 0 1/2]
107       << [shift (4dx,~2dy)] [] [twoHandles 0 1/4]
108       << [shift (4dx,~3dy)] [] [twoHandles 0 0.001]