summaryrefslogtreecommitdiff
path: root/graphics/sketch/Doc/manexamples.sk
blob: 80414d6cfac3e8467b9d716eb215be6dbc6a74a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
def x000 {
  def O (0,0,0)
  def I [1,0,0]
  def J [0,1,0]
  def K [0,0,1]
  def eye (18,12,10)
  put { view( (eye) ) 
        then perspective(|(eye)-(O)|) 
        then scale(3/8) } {
  def R 3
  def N 16
  def degrees_per_seg 15
  def pitch 1/7
  def darc degrees_per_seg / 360 * 2 * 3.14159 * R
  def dy darc * pitch
  def n_segs 114
  line[linecolor=red,linewidth=2pt](0,-1,0)(0, n_segs * dy + 1, 0)
  sweep { n_segs, rotate( degrees_per_seg, (O), [J] ) then translate([0, dy, 0]) }
    put { translate([R,0,0]) then rotate(atan2(dy, darc), (O), [I]) }
      sweep[fillcolor=lightgray] { N<>, rotate(360/N, (O), [K]) } (1,0)

  }
}

def x010 {
  put { view((5,4,8)) } {
    def L 1.5
    line[arrows=<->](L,0,0)(0,0,0)(0,L,0)
    line[arrows=->](0,0,0)(0,0,L)
    special|\uput[r]#1{$x$}
            \uput[u]#2{$y$}
            \uput[l]#3{$z$}|
      (L,0,0) % 1
      (0,L,0) % 2
      (0,0,L) % 3
  }
}

def x020 {
  polygon(0,0,1)(1,0,0)(0,1,0)
  line(-1,-1,-1)(2,2,2)
  special|\psline[linecolor=lightgray]{<->}#1#2#3
         \pscircle*[linecolor=lightgray,fillcolor=lightgray]#2{2pt}
         \pscircle[linecolor=lightgray]#2{4pt}|
    [lay=under](0,2,0)(0,0,0)(2,0,0)
}

def x030 {
  polygon[fillcolor=lightgray,linewidth=3pt](0,0,1)(1,0,0)(0,1,0)
  line[linestyle=dotted](-1,-1,-1)(2,2,2)
}

def x040 {
  % vertices of the tetrahedron
  def p1 (0,0,1)
  def p2 (1,0,0)
  def p3 (0,1,0)
  def p4 (-.3,-.5,-.8)

  % faces of the tetrahedron.
  polygon(p1)(p2)(p3) % original front polygon
  polygon(p1)(p4)(p2) % bottom
  polygon(p1)(p3)(p4) % left
  polygon(p3)(p2)(p4) % rear

  % line to pierce the tetrahedron
  line[linecolor=red](-1,-1,-1)(2,2,2)
}

def x042 {
  % vertices of the tetrahedron
  def p1 (0,0,1)
  def p2 (1,0,0)
  def p3 (0,1,0)
  def p4 (-.3,-.5,-.8)

  % faces of the tetrahedron.
  polygon(p1)(p2)(p3) % original front polygon
  polygon(p1)(p4)(p2) % bottom
  polygon(p1)(p3)(p4) % left
  polygon(p3)(p2)(p4) % rear

  % line to pierce the tetrahedron
  line[linecolor=red](-1,-1,-1)(2,2,2)

  % labels
  special |\footnotesize
           \uput{2pt}[ur]#1{$P1$}\uput[r]#2{$P2$}
           \uput[u]#3{$P3$}\uput[d]#4{$P4$}|
    (p1)(p2)(p3)(p4)
}

def x045 {
  def O (0,0,0)
  def K [0,0,1]
  def n_segs 60
  def degrees_per_seg 20
  def pitch 3
  put { view((20,7,4)) then perspective(22) } {
  sweep[cull=false] { n_segs, rotate(10, (O), [K]) then translate(pitch * degrees_per_seg / 360 * [K]) } line[cull=false](-1,0)(1,0)
  put { translate([0,2.5,0]) }
    sweep[cull=true]  { n_segs, rotate(10, (O), [K]) then translate(pitch * degrees_per_seg / 360 * [K]) } line[cull=false](-1,0)(1,0)
  }
}

def x050 {

  def pierced_tetrahedron {
    def p1 (0,0,1) def p2 (1,0,0)
    def p3 (0,1,0) def p4 (-.3,-.5,-.8)
    % faces of the tetrahedron.
    polygon(p1)(p2)(p3)                      % original
    polygon(p1)(p4)(p2)                      % bottom
    polygon(p1)(p3)(p4)                      % left
    polygon[fillcolor=lightgray](p3)(p2)(p4) % rear
    line[linecolor=red](-1,-1,-1)(2,2,2)
  }

  {pierced_tetrahedron}  % tetrahedron in original position

  put { rotate(90, (0,0,0), [1,0,0]) % copy in new position
        then translate([2.5,0,0]) } {pierced_tetrahedron}
}

def x060 {
  
  def pierced_tetrahedron {
    def p1 (0,0,1) def p2 (1,0,0)
    def p3 (0,1,0) def p4 (-.3,-.5,-.8)
    % faces of the tetrahedron.
    polygon(p1)(p2)(p3)                      % original
    polygon(p1)(p4)(p2)                      % bottom
    polygon(p1)(p3)(p4)                      % left
    polygon[fillcolor=lightgray](p3)(p2)(p4) % rear
    line[linecolor=red](-1,-1,-1)(2,2,2)
  }

  repeat { 7, rotate(15, (0,0,0), [1,0,0]) % copy in new position
              then translate([1.8,0,0]) } {pierced_tetrahedron}
}

def x070 {
  def n_segs 8
  sweep { n_segs, rotate(180 / n_segs, [0,0,1]) } (1,0,0)
}

def x080 {
  def n_segs 8
  sweep { n_segs<>, rotate(180 / n_segs, [0,0,1]) } (1,0,0)
}

% toroid
def x090 {
  put { view((4,5,10)) } {
    def n_toroid_segs 20
    def n_circle_segs 16
    def r_minor 1
    def r_major 1.5
    sweep { n_toroid_segs, rotate(360 / n_toroid_segs, [0,1,0]) }
      sweep { n_circle_segs, rotate(360 / n_circle_segs, (r_major,0,0)) } 
        (r_major + r_minor, 0)
    def al 1.5
    line[linecolor=red,arrows=->](0,0,0)(r_major + r_minor + al,0,0)
    line[linecolor=red,arrows=->](0,0,0)(0,r_minor + al,0)
    line[linecolor=red,arrows=->](0,0,0)(0,0,r_major + r_minor + al)
    special|\uput[r]#1{$x$}
            \uput[u]#2{$y$}
            \uput[dl]#3{$z$}|(r_major + r_minor + al,0,0)(0,r_minor + al,0)(0,0,r_major + r_minor + al)
  }
}

% triangle with normal
def x100 {
  def p1 (1,0,0)
  def p2 (0,0.5,0)
  def p3 (-0.5,-1,2)
  def O (0,0,0)
  def N unit( ((p3) - (p2)) * ((p1) - (p2)) )
  def n1 ((p1) - (O) + (p2) - (O) + (p3) - (O)) / 3 + (O)
  def n2 (n1)+[N]
  polygon(p1)(p2)(p3)
  line[arrows=*->](n1)(n2)
}

% views of cylinder
def x110 {
  def n_cyl_segs 20
  def n_views 5
  def I [1,0,0]
  repeat { n_views, rotate(180/n_views, [I]) then translate([I] * 2.1) } 
    sweep[fillcolor=lightgray]{ n_cyl_segs<>, rotate(360/n_cyl_segs, [0,1,0]) } 
      line[fillcolor=white](1,-1)(1,1)
}

% mobius strip
def x120 {
  put { view ((3,5,10)) } {

  def R 4
  def N 64
  def T .3
  sweep[cull=false] { 
    N, 
    rotate(180/N, (R,0,0)), 
    rotate(360/N, [0,1,0])
  } line(R - 1,-T)(R + 1,-T)(R + 1,T)(R - 1,T)(R - 1,-T)

  }
}

def x130_200 {
  % useful common defs
  def O (0,0,0)

  % right side (outside to right)
  def ht 2 % height of peak of house
  def R1 (1,1,1) def R2 (1,-1,1) def R3 (1,-1,-1) def R4 (1,1,-1)
  def R5 (1,ht,0) 

  % left side (outside to right--backward)
  def W  [2,0,0]
  def L1 (R1)-[W] def L2 (R2)-[W] def L3 (R3)-[W] def L4 (R4)-[W]
  def L5 (R5)-[W]

  % door
  def e .01
  def D1 (0,-1,1+e) def D2 (.5,-1,1+e) def D3 (.5,0,1+e) def D4 (0,0,1+e)

  def hp <ex130> scale(1)
         <ex140> scale(1)
         <> rotate(-40, [0,1,0]) then translate([0,0,-12]) % house positioner
  def pR1 [[hp]]*(R1) def pR2 [[hp]]*(R2) def pR3 [[hp]]*(R3)
  def pR4 [[hp]]*(R4) def pR5 [[hp]]*(R5)
  def pL1 [[hp]]*(L1) def pL2 [[hp]]*(L2) def pL3 [[hp]]*(L3)
  def pL4 [[hp]]*(L4) def pL5 [[hp]]*(L5)
  def pD1 [[hp]]*(D1) def pD2 [[hp]]*(D2) def pD3 [[hp]]*(D3)
  def pD4 [[hp]]*(D4) 

  % house
  def rgt polygon (pR1)(pR2)(pR3)(pR4)(pR5)
  def lft polygon (pL5)(pL4)(pL3)(pL2)(pL1)
  def frt polygon (pR2)(pR1)(pL1)(pL2)
  def bck polygon (pR4)(pR3)(pL3)(pL4)
  def tfr polygon (pR1)(pR5)(pL5)(pL1)
  def tbk polygon (pR5)(pR4)(pL4)(pL5)
  def bot polygon (pR2)(pL2)(pL3)(pR3)
  def door polygon[fillcolor=brown] (pD1)(pD2)(pD3)(pD4)
  def house { {rgt}{lft}{frt}{bck}{tfr}{tbk}{bot}{door} }

  % perspective system
  def axes {
    def sz 1
    line [arrows=<->] (sz,0,0)(O)(0,sz,0)
    line [arrows=->]  (O)(0,0,sz)
    line [linewidth=.2pt,linecolor=blue,linestyle=dashed] (O)(0,0,-12)
    special |\uput[r]#1{$x$}\uput[u]#2{$y$}\uput[l]#3{$z$}|
      (sz,0,0)(0,sz,0)(0,0,sz)
  }
  def p 5 % projection distance (plane at z=-p)
  def projection_plane {
    def sz 1.5
    polygon (-sz,-sz,-p)(sz,-sz,-p)(sz,sz,-p)(-sz,sz,-p)
    special |\rput[b]#1-2#3{\footnotesize\sf projection plane}|
      [lay=over](-sz,-sz,-p)(sz,-sz,-p)(0,-sz+.1,-p)
  }
  def projection_rays {
    def ray [linewidth=.3pt,linecolor=lightgray]
    % right
    line [ray](O)(pR1) line [ray](O)(pR2) line[ray](O)(pR3)
    line [ray](O)(pR4) line [ray](O)(pR5)
    % left
    line [ray](O)(pL1) line [ray](O)(pL2) line[ray](O)(pL5)
    %door
    line [ray](O)(pD1) line [ray](O)(pD2) 
    line [ray](O)(pD3) line [ray](O)(pD4)
  }
  def projection {
    put { project(p) then translate([0,0,e])   } {house}
    put { project(p) then translate([0,0,2*e]) } {door}
  }
  def eye (5,2,2.5)
  def look_at (0,0,-5)
  def all 
    <ex130> 
      {house}
    <ex140>
        put { scale(.3) } repeat { 13, rotate(30, [1,2,3]), translate([3,0,0]) } {house}
    <ex150> 
      put { view((eye), (look_at)) } {
        {house}
        {axes}
      }
    <ex160> 
      put { view((eye), (look_at)) } {
        {house}
        {axes}
        {projection_plane}
      }
    <ex170> 
      put { view((eye), (look_at)) } {
        {house}
        {axes}
        {projection_plane}
        {projection_rays}
      }
    <ex180> 
      put { view((eye), (look_at)) } {
        {house}
        {axes}
        {projection_plane}
        {projection_rays}
        {projection}
      }
    <ex190> 
      put { view((eye), (look_at)) then perspective(9)} {
        {house}
        {axes}
        {projection_plane}
        {projection_rays}
        {projection}
      }
    <> {house}
  {all}
}

def x210 { input {hand.sk} }
def x220 { def fist <> input {hand.sk} }
def x230 { def ok <> input {hand.sk} }
def x240 { def spread <> input {hand.sk} }
def x250 { input {truncatedcone.sk} }
def x260 { def labeled <> input {truncatedcone.sk} }

def tomake 
  input{tags.sk}
  <> special|No case was selected!|

{tomake}

global {
  set [linewidth=.3pt]
}