-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTurtle.types.ps1xml
More file actions
10115 lines (9206 loc) · 297 KB
/
Turtle.types.ps1xml
File metadata and controls
10115 lines (9206 loc) · 297 KB
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>Turtle</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Heading</Name>
<Name>Position</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
<AliasProperty>
<Name>a</Name>
<ReferencedMemberName>Arc</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>ArcL</Name>
<ReferencedMemberName>ArcLeft</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>ArcR</Name>
<ReferencedMemberName>ArcRight</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Args</Name>
<ReferencedMemberName>ArgumentList</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Argument</Name>
<ReferencedMemberName>ArgumentList</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Arguments</Name>
<ReferencedMemberName>ArgumentList</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Arm</Name>
<ReferencedMemberName>Leg</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Back</Name>
<ReferencedMemberName>Backward</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>BackgroundColour</Name>
<ReferencedMemberName>BackgroundColor</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Bezier</Name>
<ReferencedMemberName>BezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Bézier</Name>
<ReferencedMemberName>BezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>BézierCurve</Name>
<ReferencedMemberName>BezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>bk</Name>
<ReferencedMemberName>Backward</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>c</Name>
<ReferencedMemberName>CubicBezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Close</Name>
<ReferencedMemberName>ClosePath</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Cobweb</Name>
<ReferencedMemberName>Spiderweb</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Cubic</Name>
<ReferencedMemberName>CubicBezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>CubicBézierCurve</Name>
<ReferencedMemberName>CubicBezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Defs</Name>
<ReferencedMemberName>Defines</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>down</Name>
<ReferencedMemberName>PenDown</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>fd</Name>
<ReferencedMemberName>Forward</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>FillColour</Name>
<ReferencedMemberName>FillColor</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>FlowerGolden</Name>
<ReferencedMemberName>GoldenFlower</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>FlowerStar</Name>
<ReferencedMemberName>StarFlower</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>h</Name>
<ReferencedMemberName>HorizontalLine</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>HLineBy</Name>
<ReferencedMemberName>HorizontalLine</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Href</Name>
<ReferencedMemberName>Link</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Keyframes</Name>
<ReferencedMemberName>Keyframe</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>l</Name>
<ReferencedMemberName>Step</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>LineTo</Name>
<ReferencedMemberName>GoTo</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>lt</Name>
<ReferencedMemberName>Left</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>MarkerMid</Name>
<ReferencedMemberName>MarkerMiddle</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>MoveTo</Name>
<ReferencedMemberName>Teleport</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>pd</Name>
<ReferencedMemberName>PenDown</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>PenColour</Name>
<ReferencedMemberName>PenColor</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>PetalFlower</Name>
<ReferencedMemberName>FlowerPetal</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Pie</Name>
<ReferencedMemberName>PieGraph</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>pu</Name>
<ReferencedMemberName>PenUp</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>q</Name>
<ReferencedMemberName>QuadraticBezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>QuadraticBézierCurve</Name>
<ReferencedMemberName>QuadraticBezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>r</Name>
<ReferencedMemberName>Rotate</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Rhombi</Name>
<ReferencedMemberName>Rhombus</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>rt</Name>
<ReferencedMemberName>Right</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>s</Name>
<ReferencedMemberName>BezierCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>SetPos</Name>
<ReferencedMemberName>GoTo</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>SetPosition</Name>
<ReferencedMemberName>GoTo</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>SierpińskiArrowHeadCurve</Name>
<ReferencedMemberName>SierpinskiArrowHeadCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>SierpińskiCurve</Name>
<ReferencedMemberName>SierpinskiCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>SierpińskiSquareCurve</Name>
<ReferencedMemberName>SierpinskiSquareCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>SierpińskiTriangle</Name>
<ReferencedMemberName>SierpinskiTriangle</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Spoke</Name>
<ReferencedMemberName>Spokes</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Stick</Name>
<ReferencedMemberName>Sticks</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Sticks</Name>
<ReferencedMemberName>Spokes</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Styles</Name>
<ReferencedMemberName>Style</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Terdragon</Name>
<ReferencedMemberName>TerdragonCurve</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>up</Name>
<ReferencedMemberName>PenUp</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>v</Name>
<ReferencedMemberName>VerticalLine</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>VLineBy</Name>
<ReferencedMemberName>VerticalLine</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Web</Name>
<ReferencedMemberName>Spiderweb</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>xPos</Name>
<ReferencedMemberName>xcor</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>yPos</Name>
<ReferencedMemberName>ycor</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>z</Name>
<ReferencedMemberName>ClosePath</ReferencedMemberName>
</AliasProperty>
<ScriptMethod>
<Name>Arc</Name>
<Script>
<#
.SYNOPSIS
Draws an Arc
.DESCRIPTION
Draws an arc with the Turtle.
.NOTES
This method directly corresponds to the `a` instruction in an SVG Path.
.LINK
https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorials/SVG_from_scratch/Paths#arcs
#>
param(
# The X Radius of the arc.
[double]
$RadiusX = $(Get-Random -Min -42 -Max 42),
# The Y Radius of the arc.
[double]
$RadiusY = $(Get-Random -Min -42 -Max 42),
# The rotation along the x-axis.
[double]
$Rotation = 0,
# If set to 1, will draw a large arc.
# If set to 0, will draw a small arc
[ValidateSet(0,1, "Large", "Small", $true, $false)]
[PSObject]
$IsLargeArc = $(1,0 | Get-Random),
# By default, the arc will be drawn clockwise
# If this is set to 1, the arc will be drawn counterclockwise
# If set to 1, will draw an arc counterclockwise
[ValidateSet(0, 1, 'Clockwise','CounterclockWise', 'cw', 'ccw', $true, $false)]
[PSObject]
$IsCounterClockwise = $(1,0 | Get-Random),
# The deltaX
[double]
$DeltaX = $(
(Get-Random -Min 42 -Max 84) * (1,-1 | Get-Random)
),
# The deltaY
[double]
$DeltaY = $(
(Get-Random -Min 42 -Max 84) * (1,-1 | Get-Random)
)
)
if ($DeltaX -or $DeltaY) {
$this.Position = $DeltaX,$DeltaY
# If the pen is down
if ($this.IsPenDown) {
# draw the curve
$LargeArcFlag = ($IsLargeArc -in 1, 'Large',$true) -as [byte]
$SweepFlag = ($IsCounterClockwise -in 1, 'ccw','CounterClockwise', $true) -as [byte]
$this.Steps.Add("a $RadiusX $RadiusY $Rotation $LargeArcFlag $SweepFlag $DeltaX $DeltaY")
} else {
# otherwise, move to the deltaX/deltaY
$this.Steps.Add("m $deltaX $deltaY")
}
}
return $this
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>ArcFlower</Name>
<Script>
<#
.SYNOPSIS
Draws a arcflower pattern.
.DESCRIPTION
Draws a arcflower pattern in turtle graphics.
This pattern consists of a series of CircleArcs and rotations to create a flower-like design.
.EXAMPLE
turtle ArcFlower 42 6 21
.EXAMPLE
turtle ArcFlower 42 20 21 18
.EXAMPLE
turtle ArcFlower 42 20 6 18
#>
param(
# The size of the base shape
[double]$Size = (
( Get-Random -Min 21 -Max 84 ) * (1,-1 | Get-Random)
),
# The rotation after each step
[double]$Rotation = (Get-Random -Min 10 -Max 90),
# The number of sides in each shape
[double]$Angle = (
( Get-Random -Min 21 -Max 84 ) * (1,-1 | Get-Random)
),
# The number of steps in the flower.
[int]$StepCount = 0
)
if ($Rotation -eq 0) { return $this }
# If no step count was provided
if ($StepCount -eq 0) {
# pick a random number of rotations
$revolutions = (Get-Random -Minimum 1 -Max 64)
# and figure out how many steps at our angle it takes to get there.
foreach ($n in 2..$revolutions) {
$revNumber = ($revolutions * 360)/$Rotation
$StepCount = [Math]::Ceiling($revNumber)
if ([Math]::Floor($revNumber) -eq $revNumber) {
break
}
}
}
$null = foreach ($n in 1..([Math]::Abs($StepCount))) {
$this.
CircleArc($Size, $Angle).
Rotate($Rotation)
}
return $this
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>ArcLeft</Name>
<Script>
<#
.SYNOPSIS
Arcs the turtle to the left
.DESCRIPTION
Arcs the turtle to the left (counter-clockwise) a number of degrees.
For each degree, the turtle will move forward and rotate.
.NOTES
The amount moved forward will be the portion of the circumference.
#>
param(
# The radius of a the circle, were it to complete the arc.
[double]
$Radius = (Get-Random -Min 42 -Max 84),
# The angle of the arc
[double]
$Angle = (Get-Random -Min 30 -Max 90)
)
# Rather than duplicate logic, we will simply reverse the angle
$angle *= -1
# and arc to the "right".
return $this.ArcRight($Radius, $Angle)
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>ArcRight</Name>
<Script>
<#
.SYNOPSIS
Arcs the turtle to the right
.DESCRIPTION
Arcs the turtle to the right (clockwise) a number of degrees.
For each degree, the turtle will move forward and rotate.
.NOTES
The amount moved forward will be the portion of the circumference.
#>
param(
# The radius of a the circle, were it to complete the arc.
[double]
$Radius = (Get-Random -Min 42 -Max 84),
# The angle of the arc
[double]
$Angle = (Get-Random -Min 30 -Max 90),
# The number of steps. If not provided, will default to half of the angle.
[int]
$StepCount
)
# Determine the absolute angle, for this operation
$absAngle = [Math]::Abs($angle)
if ($absAngle -eq 0) { return $this }
# Determine the circumference of a circle of this radius
$Circumference = ((2 * $Radius) * [Math]::PI)
# The circumference step is the circumference times
# the number of revolutions
$revolutionCount = $angle/360
# divided by the angle
$CircumferenceStep = ($Circumference * $revolutionCount) / $Angle
# The iteration is as close to one or negative one as possible
$iteration = $angle / [Math]::Floor($absAngle)
# If we have no step count
if (-not $StepCount) {
# default to half of the angle.
$StepCount = [Math]::Round($absAngle / 2)
}
# Turn this into a ratio (by default, this ratio would be `2`).
$stepSize = $absAngle / $StepCount
# Starting at zero, keep turning until we have reached the number.
# Increase our angle by iteration * stepSize each time.
for ($angleDelta = 0; [Math]::Abs($angleDelta) -lt $absAngle; $angleDelta+=($iteration*$stepSize)) {
$this = $this. # In each step,
Forward($CircumferenceStep*$StepSize). # move forward a fraction of the circumference,
Rotate($iteration*$StepSize) # and rotate a fraction of the total angle.
}
# When we are done, return $this so we never break the chain.
return $this
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>Arcygon</Name>
<Script>
<#
.SYNOPSIS
Draws an arcygon
.DESCRIPTION
Draws an arcygon.
An arcygon is a polygon with N sides, and an arc at each corner.
To draw a closed arcygon, provide a whole number of sides.
To draw an open arcygon, provide a fractial number of sides.
To draw a negative arcygon, provide a negative angle.
.EXAMPLE
# Arcygons have a side length, radius, and number of sides.
turtle arcygon 42 21 3
.EXAMPLE
turtle arcygon 42 21 4
.EXAMPLE
turtle arcygon 21 42 4
.EXAMPLE
turtle arcygon 42 -21 4
.EXAMPLE
turtle arcygon -42 -21 4
.EXAMPLE
# we can make partial acygons
turtle arcygon 42 42 4.2
.EXAMPLE
# we can morph partial acygons
turtle arcygon 42 42 4.2 morph @(
turtle arcygon 42 42 4.2
turtle arcygon 42 42 4.999999
)
.EXAMPLE
turtle arcygon 42 42 8
.EXAMPLE
turtle arcygon 42 3.001 morph @(
turtle arcygon 42 42 3.001
turtle arcygon 42 42 3.999
turtle arcygon 42 42 3.001
)
.EXAMPLE
turtle arcygon 42 4 morph @(
turtle arcygon 42 42 4
turtle arcygon 42 -42 4
turtle arcygon 42 42 4
)
#>
param(
# The default size of each segment of the polygon
[double]$Size = $(Get-Random -Min -42 -Max 42),
[double]$Radius = $(Get-Random -Min -42 -Max 42),
# The number of sides in the polygon.
# If this is not a whole number, the polygon will not be closed.
[double]$SideCount = (Get-Random -Min 3 -Max 12)
)
# Determine the absolute side count
$absSideCount = [Math]::Abs($SideCount)
# and, for each whole number between 1 and that side count
$null = foreach ($n in 1..([Math]::Floor($absSideCount))) {
# Rotate and move forward
$this.
CircleArc($radius, (360 / $SideCount)).
Forward($Size).
Rotate(360 / $SideCount)
}
# Determine if there was a remainder
$remainder = $SideCount - [Math]::Floor($SideCount)
# If there was not, return this polygon
if (-not $remainder) { return $this }
# Otherwise, we do one more partial rotation (multiplied by the remainder)
# and draw one more line segment (multiplied by the remainder)
# (the effect will be like watching a polygon close)
$remainingAngle = (360 / $SideCount) * $remainder
return $this.
CircleArc($remainder * $Radius, $remainingAngle)
Forward($remainder * $Size).
Rotate($remainingAngle)
# @('CircleArc',$radius, $angle, 'Forward', $length, 'Rotate', $angle * $n)
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>Backward</Name>
<Script>
<#
.SYNOPSIS
Moves backwards
.DESCRIPTION
Moves the turtle backwards by a specified distance.
.EXAMPLE
turtle id 'tshape' forward 10 backward 5 rotate 90 forward 20
#>
param(
# The distance to move backwards
[double]
$Distance = (Get-Random -Min 10 -Max 100)
)
$this.Forward($Distance * -1)
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>BarGraph</Name>
<Script>
<#
.SYNOPSIS
Draws a bar graph using turtle graphics.
.DESCRIPTION
This script uses turtle graphics to draw a bar graph based on the provided data.
.EXAMPLE
turtle barGraph 100 100 5 10 15 20 15 10 5
.EXAMPLE
turtle barGraph 200 200 (
@(1..50;-1..-50) |
Get-Random -Count (Get-Random -Minimum 5 -Maximum 20)
) save ./RandomBarGraph.svg
.EXAMPLE
turtle rotate 90 barGraph 200 200 (
@(1..50;-1..-50) |
Get-Random -Count (Get-Random -Minimum 5 -Maximum 20)
) save ./RandomVerticalBarGraph.svg
.EXAMPLE
turtle rotate 45 barGraph 200 200 (
@(1..50;-1..-50) |
Get-Random -Count (Get-Random -Minimum 5 -Maximum 20)
) save ./RandomDiagonalBarGraph.svg
.EXAMPLE
$sourceData = @(1..50;-1..-50)
$itemCount = (Get-Random -Minimum 5 -Maximum 20)
$points = $sourceData | Get-Random -Count $itemCount
turtle bargraph 200 200 $points morph @(
turtle bargraph 200 200 $points
turtle bargraph 200 200 ( $sourceData | Get-Random -Count $itemCount )
turtle bargraph 200 200 $points
) save ./RandomBarGraphMorph.svg
#>
param(
# The width of the bar graph
[double]$Width,
# The height of the bar graph.
# Please note that in the case of negative values, the effective height is twice this number.
[double]$Height,
# The points in the bar graph.
# Each point will be turned into a relative number and turned into an equal-width bar.
[Parameter(ValueFromRemainingArguments)]
[double[]]$Points
)
if ($width -and -not $Height) {
$height = $width
} elseif ($height -and -not $Width) {
$width = $height
} elseif (-not $width -and -not $height) {
$width = (Get-Random -Min 10 -Max 100) * (1,-1| Get-Random)
$height = (Get-Random -Min 10 -Max 100)
}
# If there were no points, we are drawing nothing, so return ourself.
if (-not $points) {
$points = foreach ($n in 1..(Get-Random -Min 4 -Max 20)) {
Get-Random -Min 0 -Max 100
}
}
# Divide the width by the number of points to get a very snug bar graph
$barWidth = $width / $points.Length
# Find the maximum and minimum values in the points
$min, $max = 0, 0
foreach ($point in $points) {
if ($point -gt $max) { $max = $point}
if ($point -lt $min) { $min = $point}
}
# This gives us the range.
$range = $max - $min
# If the range is zero, we're drawing a flatline.
if ($range -eq 0) {
# so just draw that line and return.
return $this.Forward($width)
}
# Now that we've normalized the range, we can draw the bars.
for ($pointIndex =0 ; $pointIndex -lt $points.Length; $pointIndex++) {
# Each point is essentially telling us the height
$point = $points[$pointIndex]
# which we can turn into a relative value
$relativeHeight = (
# by subtracting the minimum and dividing by the range
(($point - $min) / $range)
) * $height
# If the point was negative, we need to flip the height
if ($point -lt 0) { $relativeHeight *= -1}
# Now we can draw the bar
$this = $this.
# Turn outward and draw the side
Rotate(-90).Forward($relativeHeight).
# Turn and draw the top
Rotate(90).Forward($barWidth).
# Turn and draw the other side
Rotate(90).Forward($relativeHeight).
# Turn back to the original direction
Rotate(-90)
}
return $this
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>BezierCurve</Name>
<Script>
<#
.SYNOPSIS
Draws a Bezier Curve
.DESCRIPTION
Draws a simple Bezier curve.
.EXAMPLE
turtle BezierCurve 0 -100 100 -100 save ./b1.svg
.EXAMPLE
turtle BezierCurve 0 -100 100 -100 BezierCurve 100 100 100 100 save ./b2.svg
.EXAMPLE
turtle @(
'BezierCurve', 0, -100, 100, -100
'BezierCurve', 100, 100, 100, 100
'BezierCurve', 0, 100, -100, 100
) save ./b3.svg
.EXAMPLE
turtle @(
'BezierCurve', 0, -100, 100, -100
'BezierCurve', 100, 100, 100, 100
'BezierCurve', 0, 100, -100, 100
'BezierCurve', -100, -100, -100, -100
) save ./b4.svg
.LINK
https://en.wikipedia.org/wiki/B%C3%A9zier_curve
#>
param(
# The X control point
[double]
$ControlX = (Get-Random -Max 42),
# The Y control point
[double]
$ControlY = (Get-Random -Max 42),
# The delta X
[double]
$DeltaX = (Get-Random -Min 0 -Max 100),
# The delta Y
[double]
$DeltaY = (Get-Random -Min 0 -Max 100)
)
if ($DeltaX -or $DeltaY) {
$this.Position = $DeltaX,$DeltaY
# If the pen is down
if ($this.IsPenDown) {
# draw the curve
$this.Steps.Add("s $controlX $controlY $deltaX $deltaY")
} else {
# otherwise, move to the deltaX/deltaY
$this.Steps.Add("m $deltaX $deltaY")
}
}
return $this
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>BinaryTree</Name>
<Script>
<#
.SYNOPSIS
Draws a binary tree
.DESCRIPTION
Draws a binary tree using an L-system.
.LINK
https://en.wikipedia.org/wiki/L-system#Example_2:_fractal_(binary)_tree
#>
param(
# The size of each segment
[double]$Size = $(Get-Random -Min 21 -Max 42),
# The order of magnitude (the number of times the L-system is expanded)
[int]$Order = (2,3,4,5,6| Get-Random),
# The angle
[double]$Angle = 45
)
return $this.Rotate(-90).LSystem('0', [Ordered]@{
'1' = '11'
'0' = '1[0]0'
}, $Order, [Ordered]@{
'[01]' = { $this.Forward($Size) }
'\[' = { $this.Push().Rotate($Angle * -1) }
'\]' = { $this.Pop().Rotate($Angle) }
})
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>BoardFractal</Name>
<Script>
<#
.SYNOPSIS
Draws a Board
.DESCRIPTION
Draws a Board, using an L-System
.LINK
https://paulbourke.net/fractals/lsys/
.EXAMPLE
turtle BoardFractal 42 1
.EXAMPLE
turtle BoardFractal 42 2
.EXAMPLE
turtle BoardFractal 42 3
.EXAMPLE
turtle BoardFractal 42 4
#>
param(
# The size of each segment
[double]$Size = (Get-Random -Min 100 -Max 200),
# The order of magnitude (the number of expansions)
[int]$Order = (2,3,4 | Get-Random),
# The default angle.
[double]$Angle = 90
)
return $this.LSystem('F+F+F+F', [Ordered]@{
F = 'FF+F+F+F+FF'
}, $Order, [Ordered]@{
'\+' = { $this.Rotate($Angle) }
'F' = { $this.Forward($Size) }
})
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>BoxFractal</Name>
<Script>
<#
.EXAMPLE
$turtle.PatternAnimation = ''
$turtle.Clear().BoxFractal().Pattern.Save("$pwd/BoxFractal.svg")
.EXAMPLE
$turtle.Clear()
$turtle.BoxFractal(10,4)
$turtle.PatternTransform = @{
'scale' = 0.9
}
$turtle.PatternAnimation = "
<animateTransform attributeName='patternTransform' attributeType='XML' type='scale' values='1;0.9;1' dur='19s' repeatCount='indefinite' additive='sum' />
<animateTransform attributeName='patternTransform' attributeType='XML' type='skewY' values='0;-30;30;-30;0' dur='67s' repeatCount='indefinite' additive='sum' />
<animateTransform attributeName='patternTransform' attributeType='XML' type='skewX' values='0;-30;30;-30;0' dur='83s' repeatCount='indefinite' additive='sum' />
"
$turtle.Pattern.Save("$pwd/BoxFractal2.svg")
#>
param(
[double]$Size = (Get-Random -Min 21 -Max 42),
[int]$Order = (2,3,4 | Get-Random),
[double]$Angle = 90
)
return $this.LSystem('F-F-F-F', [Ordered]@{
F = 'F-F+F+F-F'
}, $Order, [Ordered]@{
'\+' = { $this.Rotate($Angle) }
'-' = { $this.Rotate($Angle * -1) }
'F' = { $this.Forward($Size) }
})
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>Circle</Name>
<Script>
<#
.SYNOPSIS
Draws a circle.
.DESCRIPTION
Draws a whole or partial circle using turtle graphics.
That is, it draws a circle by moving the turtle forward and rotating it.
To draw a semicircle, use an extent of 0.5.
To draw a quarter circle, use an extent of 0.25.
To draw a half hexagon, use an extent of 0.5 and step count of 6.
.EXAMPLE
turtle circle 42 | Save-Turtle ./Circle.svg
.EXAMPLE
turtle circle 42 .5 | Save-Turtle ./HalfCircle.svg
.EXAMPLE
turtle circle 42 .25 | Save-Turtle ./QuarterCircle.svg
.EXAMPLE
turtle circle 42 | Save-Turtle ./CirclePattern.svg
.EXAMPLE
turtle start 21 21 circle 42 morph @(
turtle start 21 21 circle 42
turtle start 21 21 circle -42
turtle start 21 21 circle 42
) | Save-Turtle ./CircleMorphPattern.svg
.EXAMPLE
$turtle = New-Turtle
$turtle.Circle(10).Pattern.Save("$pwd/CirclePattern.svg")
.EXAMPLE
turtle circle 42 1 90 morph |
Save-Turtle ./CircleConstructionMorph.svg
.EXAMPLE
turtle forward 42 rotate -90 Circle 21 Circle 21 .5 rotate -90 forward 42 |
Save-Turtle ./DashDotDash.svg
.EXAMPLE
turtle @('forward', 40, 'Circle', 10, .75 * 4) |
Save-Turtle ./CommandSymbol.svg
.EXAMPLE
turtle @('forward', 40, 'Circle', 10, .75 * 4) morph |
Save-Turtle ./CommandSymbolStepMorph.svg
.EXAMPLE
turtle @('forward', 40, 'Circle', 10, .75 * 4) |
Save-Turtle ./CommandSymbolPattern.svg
#>
param(
# The radius of the circle
[double]$Radius = $(
(Get-Random -Min 21 -Max 42) * (1,-1 | Get-Random)
),
# The portion of the circle to draw.
[double]$Extent = 1,
# The number of steps.
# If this is not provided, steps will be automatically determined
# If the the extent is between `1` or `-1` and the angle is a multiple of 90,
# then the circle will be drawn in up to four steps.
# Otherwise, the step count will default to 180.
[int]$StepCount
)
if (-not $this) { return }
if ($extent -eq 0) { return $this }
# If the step count was not specified, and the `-Extent` is `1` or `-1`,
# we want to draw an optimized path around the circle.
if ((-not $StepCount) -and (
-not (($extent * 360) % 90)
) -and
$extent -le 1 -and
$extent -ge -1
) {
# First, we need to know what the center is.
# Luckily, the center is always a right triangle away
$headingToCenter = $this.Heading + 90
$circleCenter = [Numerics.Vector2]::new(
$this.X + ($radius * [math]::cos($headingToCenter * [Math]::PI / 180)),
$this.Y + ($radius * [math]::sin($headingToCenter * [Math]::PI / 180))
)
# Once we know the center, we can construct four vectors for each quadrant of the circle
$circleRight, $circleBottom, $circleLeft, $circleTop = foreach ($n in 0..3) {
$headingTo = $this.Heading + (90 * $n)
$circleCenter + [Numerics.Vector2]::new(
$radius * [math]::cos($headingTo * [Math]::PI / 180),
$radius * [math]::sin($headingTo * [Math]::PI / 180)
)
}
# and then we can draw up to four relative arcs.
# (this ensures a pure circle is smoothly drawn and the bounding box is updated accordingly)
$updated = switch ($extent * 360) {
90 {
$this.
Arc($radius, $radius, 0, $false, $true,$circleRight.X - $this.X, $circleRight.Y - $this.Y).
Rotate(90)
}
-90 {
$this.
Arc($radius, $radius, 0, $false, $false,$circleLeft.X - $this.X, $circleLeft.Y - $this.Y).
Rotate(-90)
}
180 {
$this.
Arc($radius, $radius, 0, $false, $true,$circleRight.X - $this.X, $circleRight.Y - $this.Y).
Arc($radius, $radius, 0, $false, $true,$circleBottom.X - $this.X, $circleBottom.Y - $this.Y).
Rotate(180)
}
-180 {
$this.
Arc($radius, $radius, 0, $false, $false,$circleLeft.X - $this.X, $circleLeft.Y - $this.Y).
Arc($radius, $radius, 0, $false, $false,$circleBottom.X - $this.X, $circleBottom.Y - $this.Y).
Rotate(-180)
}
270 {
$this.
Arc($radius, $radius, 0, $false, $true,$circleRight.X - $this.X, $circleRight.Y - $this.Y).
Arc($radius, $radius, 0, $false, $true,$circleBottom.X - $this.X, $circleBottom.Y - $this.Y).
Arc($radius, $radius, 0, $false, $true,$circleLeft.X - $this.X, $circleLeft.Y - $this.Y).
Rotate(270)
}