Update suitable examples and tests to use blank mode
[shapes.git] / examples / doc / tutorial-bezier-connected.shape
blobc789bf1a12741b62aac6195dffdd498f7fb1506c
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, 2010, 2014 Henrik Tidefelt
17  **/
19 ##needs ..Applications..Blockdraw
21 ##preamble \usepackage[squaren]{SIunits}
22 ##preamble \usepackage{url}
24 ##lookin ..Shapes
25 ##lookin ..Shapes..Geometry
26 ##lookin ..Applications..Blockdraw
28 pathStyle: Traits..@width: 1bp
29 controlStyle: Traits..@width: 0.3bp & Traits..@dash:[Traits..dashpattern 2mm 2mm] & Traits..@stroking:[Traits..gray 0.5]
30 labelStyle: Traits..@width: 0.3bp & Traits..@stroking:[Traits..gray 0.5]
31 onPathMark: Traits..@nonstroking:Traits..RGB..RED | [Graphics..fill [Geometry..circle 1mm]]
32 controlHead: \ p → (> cut:0bp
33                        picture: Traits..@width:1bp & Traits..@stroking:Traits..RGB..RED & Traits..@dash:[Traits..dashpattern] | ([shift p.begin.p]*[rotate [angle p.begin.T]])[][Graphics..stroke (~1.5mm,~1.5mm)--(1.5mm,1.5mm) & (~1.5mm,1.5mm)--(1.5mm,~1.5mm)]
34                     <)
35 arcHead: [Graphics..ShapesArrow width:2mm ...]
37 coordsHelper: \ src base offset →
39   p: (base--offset).end.p
40   [Graphics..TeX
41  { tmp: ( String..newString << `\url{´
42                 << src
43                 << `} $\Rightarrow (\unit{´
44                 << [String..sprintf `%.1f´ p.x/1cm]
45                 << `}{\centi\metre},\unit{´
46                 << [String..sprintf `%.1f´ p.y/1cm]
47                 << `}{\centi\metre})$´
48     ) [Debug..log_before tmp tmp] }
49   ]
52 arc: \ p0 p1 a → ( Geometry..@defaultunit:1%C | p0>(^[angle p1-p0]+a)--(^[angle p0-p1]-a)<p1 )
54 p0: [Debug..locate (5cm,4cm)]
55 p0r: [Debug..locate (+(~1cm,~1cm))]
56 p0f: [Debug..locate (+(2cm,8mm))]
58 p1: [Debug..locate (+(6cm,~2cm))]
59 p1r: [Debug..locate (+(~1cm,2cm))]
60 p1f: [Debug..locate (15cm,(+~3cm))]
62 p2: [Debug..locate ((+5cm),3cm)]
64 pth: p0r<p0>p0f--p1r<p1>p1f--p2
66 Traits..@width: 0.5bp
69   xMax: 18.9cm
70   yMax: 6.9cm
71   IO..•page << [Graphics..stroke (~1.5cm,0cm)--(xMax,0cm) head:[Graphics..ShapesArrow width:3.5mm ...]]
72         << [[Data..range 1cm xMax 1cm].foldl
73             \ p e → ( p & [Graphics..stroke (e,0cm)--(+(0cm,~[if [Numeric..Math..abs [Numeric..Math..mod e 5cm]]<0.1mm 2.5mm 1mm]))] )
74             Graphics..null]
75         << [putlabelBelow [Graphics..TeX `$\unit{5}{\centi\metre}$´] (5cm,~3mm) 0]
76   IO..•page << [Graphics..stroke (0cm,~1.5cm)--(0cm,yMax) head:[Graphics..ShapesArrow width:3.5mm ...]]
77         << [[Data..range 1cm yMax 1cm].foldl
78             \ p e → ( p & [Graphics..stroke (0cm,e)--(+(~[if [Numeric..Math..abs [Numeric..Math..mod e 5cm]]<0.1mm 2.5mm 1mm],0cm))] )
79             Graphics..null]
80         << [putlabelLeft [Graphics..TeX `$\unit{5}{\centi\metre}$´] (~3mm,5cm) ~0.5]
83 IO..•page << [[Data..range '0 [Geometry..duration pth]].foldl \ p e → p & [[shift [pth e*1].p] onPathMark]  Graphics..null]
84       << pathStyle | [Graphics..stroke pth]
87   pa: (0cm,0cm)
88   pb: p0
89   pTo: (pa--pb).end.p
90   pLbl: pTo + (~2cm,1.5cm)
91   IO..•page << [putlabelAbove [coordsHelper [Debug..sourceof pb] pa pb] pLbl 0]
92         << labelStyle | [Graphics..stroke pLbl--pTo]
93         << labelStyle | [Graphics..stroke [arc pTo pa ~30°] head:arcHead]
96   pa: [pth 0].p
97   pb: p0r
98   pTo: (pa--pb).end.p
99   pLbl: pTo + (0.5cm,~1cm)
100   IO..•page << controlStyle | [Graphics..stroke pa--pTo head:controlHead]
101         << [putlabelBelow [coordsHelper [Debug..sourceof pb] pa pb] pLbl 0]
102         << labelStyle | [Graphics..stroke pLbl--pTo]
103         << labelStyle | [Graphics..stroke [arc pTo pa ~40°] head:arcHead]
106   pa: [pth 0].p
107   pb: p0f
108   pTo: (pa--pb).end.p
109   pLbl: pTo + (0.5cm,1.5cm)
110   IO..•page << controlStyle | [Graphics..stroke pa--pTo head:controlHead]
111         << [putlabelAbove [coordsHelper [Debug..sourceof pb] pa pb] pLbl 0]
112         << labelStyle | [Graphics..stroke pLbl--pTo]
113         << labelStyle | [Graphics..stroke [arc pTo pa ~40°] head:arcHead]
117   pa: [pth 0].p
118   pb: p1
119   pTo: (pa--pb).end.p
120   pLbl: pTo + (~2.5cm,~1cm)
121   IO..•page << [putlabelBelow [coordsHelper [Debug..sourceof pb] pa pb] pLbl 0]
122         << labelStyle | [Graphics..stroke pLbl--pTo]
123         << labelStyle | [Graphics..stroke [arc pTo pa 20°] head:arcHead]
126   pa: [pth 1].p
127   pb: p1r
128   pTo: (pa--pb).end.p
129   pLbl: pTo + (1cm,1.5cm)
130   IO..•page << controlStyle | [Graphics..stroke pa--pTo head:controlHead]
131         << [putlabelAbove [coordsHelper [Debug..sourceof pb] pa pb] pLbl 0]
132         << labelStyle | [Graphics..stroke pLbl--pTo]
133         << labelStyle | [Graphics..stroke [arc pTo pa 40°] head:arcHead]
136   pa: [pth 1].p
137   pb: p1f
138   pTo: (pa--pb).end.p
139   pLbl: pTo + (2cm,1.3cm)
140   IO..•page << controlStyle | [Graphics..stroke pa--pTo head:controlHead]
141         << [putlabelAbove [coordsHelper [Debug..sourceof pb] pa pb] pLbl 0]
142         << labelStyle | [Graphics..stroke pLbl--pTo]
143         << labelStyle | [Graphics..stroke [arc pTo pa 40°] head:arcHead]
147   pa: [pth 1].p
148   pb: p2
149   pTo: (pa--pb).end.p
150   pLbl: pTo + (~1cm,1cm)
151   IO..•page << [putlabelAbove [coordsHelper [Debug..sourceof pb] pa pb] pLbl 0]
152         << labelStyle | [Graphics..stroke pLbl--pTo]
153         << labelStyle | [Graphics..stroke [arc pTo pa ~20°] head:arcHead]