11
11
import block
12
12
import util
13
13
14
- from copy import deepcopy
15
14
import time
16
15
import math
17
16
18
17
class Points ():
18
+ """
19
+ Points - a collection of minecraft positions or Vec3's. Used when drawing faces ``MinecraftDrawing.drawFace()``.
20
+ """
19
21
def __init__ (self ):
20
22
self ._points = []
21
23
22
24
def add (self , x , y , z ):
25
+ """
26
+ add a single position to the list of points.
27
+
28
+ :param int x:
29
+ The x position.
30
+
31
+ :param int y:
32
+ The y position.
33
+
34
+ :param int z:
35
+ The z position.
36
+ """
23
37
self ._points .append (minecraft .Vec3 (x , y , z ))
24
38
25
39
def getVec3s (self ):
40
+ """
41
+ returns a list of Vec3 positions
42
+ """
26
43
return self ._points
27
44
28
45
class MinecraftDrawing :
29
46
"""
30
- MinecraftDrawing - a class of 'useful' drawing functions
47
+ MinecraftDrawing - a class of useful drawing functions
48
+
49
+ :param mcpi.minecraft.Minecraft mc:
50
+ A Minecraft object which is connected to a world.
31
51
"""
32
52
def __init__ (self , mc ):
33
53
self .mc = mc
34
54
35
55
def drawPoint3d (self , x , y , z , blockType , blockData = 0 ):
36
56
"""
37
57
draws a single point in Minecraft, i.e. 1 block
58
+
59
+ :param int x:
60
+ The x position.
61
+
62
+ :param int y:
63
+ The y position.
64
+
65
+ :param int z:
66
+ The z position.
67
+
68
+ :param int blockType:
69
+ The block id.
70
+
71
+ :param int blockData:
72
+ The block data value, defaults to ``0``.
38
73
"""
39
74
40
75
self .mc .setBlock (x ,y ,z ,blockType ,blockData )
@@ -43,6 +78,19 @@ def drawPoint3d(self, x, y, z, blockType, blockData=0):
43
78
def drawFace (self , vertices , filled , blockType , blockData = 0 ):
44
79
"""
45
80
draws a face, when passed a collection of vertices which make up a polyhedron
81
+
82
+ :param list vertices:
83
+ The a list of points, passed as either a ``minecraftstuff.Points`` object
84
+ or as a list of ``mcpi.minecraft.Vec3`` objects.
85
+
86
+ :param boolean filled:
87
+ If ``True`` fills the face with blocks.
88
+
89
+ :param int blockType:
90
+ The block id.
91
+
92
+ :param int blockData:
93
+ The block data value, defaults to ``0``.
46
94
"""
47
95
48
96
# was a Points class passed? If so get the list of Vec3s.
@@ -94,20 +142,72 @@ def keyZ( point ): return point.z
94
142
def drawVertices (self , vertices , blockType , blockData = 0 ):
95
143
"""
96
144
draws all the points in a collection of vertices with a block
145
+
146
+ :param list vertices:
147
+ A list of ``mcpi.minecraft.Vec3`` objects.
148
+
149
+ :param int blockType:
150
+ The block id.
151
+
152
+ :param int blockData:
153
+ The block data value, defaults to ``0``.
97
154
"""
155
+
98
156
for vertex in vertices :
99
157
self .drawPoint3d (vertex .x , vertex .y , vertex .z , blockType , blockData )
100
158
101
159
def drawLine (self , x1 , y1 , z1 , x2 , y2 , z2 , blockType , blockData = 0 ):
102
160
"""
103
161
draws a line between 2 points
162
+
163
+ :param int x1:
164
+ The x position of the first point.
165
+
166
+ :param int y1:
167
+ The y position of the first point.
168
+
169
+ :param int z1:
170
+ The z position of the first point.
171
+
172
+ :param int x2:
173
+ The x position of the second point.
174
+
175
+ :param int y2:
176
+ The y position of the second point.
177
+
178
+ :param int z2:
179
+ The z position of the second point.
180
+
181
+ :param int blockType:
182
+ The block id.
183
+
184
+ :param int blockData:
185
+ The block data value, defaults to ``0``.
104
186
"""
105
187
self .drawVertices (self .getLine (x1 , y1 , z1 , x2 , y2 , z2 ), blockType , blockData )
106
188
107
189
108
190
def drawSphere (self , x1 , y1 , z1 , radius , blockType , blockData = 0 ):
109
191
"""
110
192
draws a sphere around a point to a radius
193
+
194
+ :param int x1:
195
+ The x position of the centre of the sphere.
196
+
197
+ :param int y1:
198
+ The y position of the centre of the sphere.
199
+
200
+ :param int z1:
201
+ The z position of the centre of the sphere.
202
+
203
+ :param int radius:
204
+ The radius of the sphere.
205
+
206
+ :param int blockType:
207
+ The block id.
208
+
209
+ :param int blockData:
210
+ The block data value, defaults to ``0``.
111
211
"""
112
212
for x in range (radius * - 1 , radius ):
113
213
for y in range (radius * - 1 , radius ):
@@ -117,7 +217,25 @@ def drawSphere(self, x1, y1, z1, radius, blockType, blockData=0):
117
217
118
218
def drawHollowSphere (self , x1 , y1 , z1 , radius , blockType , blockData = 0 ):
119
219
"""
120
- draws a hollow sphere around a point to a radius, sphere has to bigger enough to be hollow!
220
+ draws a hollow sphere around a point to a radius, sphere has to big enough to be hollow!
221
+
222
+ :param int x1:
223
+ The x position of the centre of the sphere.
224
+
225
+ :param int y1:
226
+ The y position of the centre of the sphere.
227
+
228
+ :param int z1:
229
+ The z position of the centre of the sphere.
230
+
231
+ :param int radius:
232
+ The radius of the sphere.
233
+
234
+ :param int blockType:
235
+ The block id.
236
+
237
+ :param int blockData:
238
+ The block data value, defaults to ``0``.
121
239
"""
122
240
for x in range (radius * - 1 , radius ):
123
241
for y in range (radius * - 1 , radius ):
@@ -128,6 +246,24 @@ def drawHollowSphere(self, x1, y1, z1, radius, blockType, blockData=0):
128
246
def drawCircle (self , x0 , y0 , z , radius , blockType , blockData = 0 ):
129
247
"""
130
248
draws a circle in the Y plane (i.e. vertically)
249
+
250
+ :param int x0:
251
+ The x position of the centre of the circle.
252
+
253
+ :param int y0:
254
+ The y position of the centre of the circle.
255
+
256
+ :param int z:
257
+ The z position of the centre of the circle.
258
+
259
+ :param int radius:
260
+ The radius of the sphere.
261
+
262
+ :param int blockType:
263
+ The block id.
264
+
265
+ :param int blockData:
266
+ The block data value, defaults to ``0``.
131
267
"""
132
268
133
269
f = 1 - radius
@@ -161,6 +297,24 @@ def drawCircle(self, x0, y0, z, radius, blockType, blockData=0):
161
297
def drawHorizontalCircle (self , x0 , y , z0 , radius , blockType , blockData = 0 ):
162
298
"""
163
299
draws a circle in the X plane (i.e. horizontally)
300
+
301
+ :param int x0:
302
+ The x position of the centre of the circle.
303
+
304
+ :param int y:
305
+ The y position of the centre of the circle.
306
+
307
+ :param int z0:
308
+ The z position of the centre of the circle.
309
+
310
+ :param int radius:
311
+ The radius of the circle.
312
+
313
+ :param int blockType:
314
+ The block id.
315
+
316
+ :param int blockData:
317
+ The block data value, defaults to ``0``.
164
318
"""
165
319
166
320
f = 1 - radius
@@ -195,6 +349,24 @@ def getLine(self, x1, y1, z1, x2, y2, z2):
195
349
Returns all the points which would make up a line between 2 points as a list
196
350
197
351
3d implementation of bresenham line algorithm
352
+
353
+ :param int x1:
354
+ The x position of the first point.
355
+
356
+ :param int y1:
357
+ The y position of the first point.
358
+
359
+ :param int z1:
360
+ The z position of the first point.
361
+
362
+ :param int x2:
363
+ The x position of the second point.
364
+
365
+ :param int y2:
366
+ The y position of the second point.
367
+
368
+ :param int z2:
369
+ The z position of the second point.
198
370
"""
199
371
# return the maximum of 2 values
200
372
def MAX (a ,b ):
@@ -293,12 +465,25 @@ def ZSGN(a):
293
465
# MinecraftShape - a class for managing shapes
294
466
class MinecraftShape :
295
467
"""
296
- MinecraftShape
468
+ MinecraftShape - the implementation of a 'shape' in Minecraft.
297
469
298
- The implementation of a 'shape' in Minecraft.
299
470
Each shape consists of one or many blocks with a position relative to each other.
471
+
300
472
Shapes can be transformed by movement and rotation.
473
+
301
474
When a shape is changed and redrawn in Minecraft only the blocks which have changed are updated.
475
+
476
+ :param mcpi.minecraft.Minecraft mc:
477
+ A Minecraft object which is connected to a world.
478
+
479
+ :param mcpi.minecraft.Vec3 position:
480
+ The position where the shape should be created
481
+
482
+ :param list shapeBlocks:
483
+ A list of ShapeBlocks which make up the shape. This defaults to ``None``.
484
+
485
+ :param bool visible:
486
+ Where the shape should be visible. This defaults to ``True``.
302
487
"""
303
488
304
489
def __init__ (self , mc , position , shapeBlocks = None , visible = True ):
@@ -327,8 +512,8 @@ def __init__(self, mc, position, shapeBlocks = None, visible = True):
327
512
328
513
def draw (self ):
329
514
"""
330
- draws the shape in Minecraft
331
- taking into account where it was last drawn and only updates the blocks which have changed
515
+ draws the shape in Minecraft, taking into account where it was last drawn,
516
+ only updating the blocks which have changed
332
517
"""
333
518
334
519
#create 2 sets only of the blocks which are drawn and one of the shapeBlocks
@@ -347,12 +532,12 @@ def draw(self):
347
532
self .mc .setBlock (blockToDraw .actualPos .x , blockToDraw .actualPos .y , blockToDraw .actualPos .z , blockToDraw .blockType , blockToDraw .blockData )
348
533
349
534
#update the blocks which have been drawn
350
- self .drawnShapeBlocks = deepcopy (self .shapeBlocks )
535
+ self .drawnShapeBlocks = self . _copyBlocks (self .shapeBlocks )
351
536
self .visible = True
352
537
353
538
def redraw (self ):
354
539
"""
355
- draws the shape in Minecraft, by clearing all the blocks and redrawing them
540
+ redraws the shape in Minecraft, by clearing all the blocks and redrawing them
356
541
"""
357
542
if self .drawnShapeBlocks != None :
358
543
for blockToClear in self .drawnShapeBlocks :
@@ -362,7 +547,7 @@ def redraw(self):
362
547
self .mc .setBlock (blockToDraw .actualPos .x , blockToDraw .actualPos .y , blockToDraw .actualPos .z , blockToDraw .blockType , blockToDraw .blockData )
363
548
364
549
#update the blocks which have been drawn
365
- self .drawnShapeBlocks = deepcopy (self .shapeBlocks )
550
+ self .drawnShapeBlocks = self . _copyBlocks (self .shapeBlocks )
366
551
self .visible = True
367
552
368
553
def clear (self ):
@@ -390,12 +575,31 @@ def reset(self):
390
575
def moveBy (self , x , y , z ):
391
576
"""
392
577
moves the position of the shape by x,y,z
578
+
579
+ :param int x:
580
+ The number of blocks to move in x.
581
+
582
+ :param int y:
583
+ The number of blocks to move in y.
584
+
585
+ :param int z:
586
+ The number of blocks to move in z.
587
+
393
588
"""
394
589
return self ._move (self .position .x + x , self .position .y + y , self .position .z + z )
395
590
396
591
def move (self , x , y , z ):
397
592
"""
398
593
moves the position of the shape to x,y,z
594
+
595
+ :param int x:
596
+ The x position.
597
+
598
+ :param int y:
599
+ The y position.
600
+
601
+ :param int z:
602
+ The z position.
399
603
"""
400
604
#is the position different
401
605
if self .position .x != x or self .position .y != y or self .position .z != z :
@@ -426,17 +630,30 @@ def _move(self, x, y, z):
426
630
427
631
if self .visible :
428
632
self .draw ()
633
+
634
+ def _copyBlocks (self , shapeBlocks ):
635
+ """
636
+ Internal. copy a list of shapeBlocks to new objects, item level, as
637
+ opposed to the expensive copy.deepcopy() or copy.copy()
638
+ """
639
+ newShapeBlocks = []
640
+ for shapeBlock in shapeBlocks :
641
+ newShapeBlock = ShapeBlock (shapeBlock .actualPos .x , shapeBlock .actualPos .y , shapeBlock .actualPos .z , shapeBlock .blockType , shapeBlock .blockData , shapeBlock .tag )
642
+ newShapeBlock .originalPos = minecraft .Vec3 (shapeBlock .originalPos .x , shapeBlock .originalPos .y , shapeBlock .originalPos .z )
643
+ newShapeBlock .relativePos = minecraft .Vec3 (shapeBlock .relativePos .x , shapeBlock .relativePos .y , shapeBlock .relativePos .z )
644
+ newShapeBlocks .append (newShapeBlock )
645
+ return newShapeBlocks
429
646
430
647
def _recalcBlocks (self ):
431
648
"""
432
- recalculate the position of all of the blocks in a shape
649
+ Internal. recalculate the position of all of the blocks in a shape
433
650
"""
434
651
for shapeBlock in self .shapeBlocks :
435
652
self ._recalcBlock (shapeBlock )
436
653
437
654
def _recalcBlock (self , shapeBlock ):
438
655
"""
439
- recalulate the shapeBlock's position based on its relative position,
656
+ Internal. recalulate the shapeBlock's position based on its relative position,
440
657
its actual position in the world and its rotation
441
658
"""
442
659
#reset the block's position before recalcing it
@@ -451,6 +668,15 @@ def _recalcBlock(self, shapeBlock):
451
668
def rotate (self , yaw , pitch , roll ):
452
669
"""
453
670
sets the rotation of a shape by yaw, pitch and roll
671
+
672
+ :param float yaw:
673
+ The yaw rotation in degrees.
674
+
675
+ :param float pitch:
676
+ The pitch rotation in degrees.
677
+
678
+ :param float roll:
679
+ The roll rotation in degrees.
454
680
"""
455
681
#is the rotation different?
456
682
if yaw != self .yaw or pitch != self .pitch or roll != self .roll :
@@ -474,20 +700,29 @@ def rotate(self, yaw, pitch, roll):
474
700
def rotateBy (self , yaw , pitch , roll ):
475
701
"""
476
702
increments the rotation of a shape by yaw, pitch and roll
703
+
704
+ :param float yaw:
705
+ The yaw rotation in degrees.
706
+
707
+ :param float pitch:
708
+ The pitch rotation in degrees.
709
+
710
+ :param float roll:
711
+ The roll rotation in degrees.
477
712
"""
478
713
return self .rotate (self .yaw + yaw , self .pitch + pitch , self .roll + roll )
479
714
480
715
def _moveShapeBlock (self , shapeBlock , x , y , z ):
481
716
"""
482
- offset the position of the block by the position
717
+ Internal. offset the position of the block by the position
483
718
"""
484
719
shapeBlock .actualPos .x = shapeBlock .relativePos .x + x
485
720
shapeBlock .actualPos .y = shapeBlock .relativePos .y + y
486
721
shapeBlock .actualPos .z = shapeBlock .relativePos .z + z
487
722
488
723
def _rotateShapeBlock (self , shapeBlock , yaw , pitch , roll ):
489
724
"""
490
- rotate the block
725
+ Internal. rotate the block
491
726
"""
492
727
self ._rotateShapeBlockY (shapeBlock , yaw )
493
728
self ._rotateShapeBlockZ (shapeBlock , roll )
@@ -496,7 +731,7 @@ def _rotateShapeBlock(self, shapeBlock, yaw, pitch, roll):
496
731
497
732
def _rotateShapeBlockY (self , shapeBlock , theta ):
498
733
"""
499
- rotate y = yaw (direction)
734
+ Internal. rotate y = yaw (direction)
500
735
"""
501
736
if theta != 0 :
502
737
sin_t = math .sin (math .radians (theta ))
@@ -508,7 +743,7 @@ def _rotateShapeBlockY(self, shapeBlock, theta):
508
743
509
744
def _rotateShapeBlockZ (self , shapeBlock , theta ):
510
745
"""
511
- rotate z = roll
746
+ Internal. rotate z = roll
512
747
"""
513
748
if theta != 0 :
514
749
sin_t = math .sin (math .radians (theta ))
@@ -520,7 +755,7 @@ def _rotateShapeBlockZ(self, shapeBlock, theta):
520
755
521
756
def _rotateShapeBlockX (self , shapeBlock , theta ):
522
757
"""
523
- rotate x = pitch
758
+ Internal. rotate x = pitch
524
759
"""
525
760
if theta != 0 :
526
761
sin_t = math .sin (math .radians (theta ))
@@ -532,7 +767,28 @@ def _rotateShapeBlockX(self, shapeBlock, theta):
532
767
533
768
def setBlock (self , x , y , z , blockType , blockData = 0 , tag = "" ):
534
769
"""
535
- sets one block in the shape and redraws it
770
+ sets one block in the shape and redraws it
771
+
772
+ draws a single point in Minecraft, i.e. 1 block
773
+
774
+ :param int x:
775
+ The x position.
776
+
777
+ :param int y:
778
+ The y position.
779
+
780
+ :param int z:
781
+ The z position.
782
+
783
+ :param int blockType:
784
+ The block id.
785
+
786
+ :param int blockData:
787
+ The block data value, defaults to ``0``.
788
+
789
+ :param string tag:
790
+ A tag for the block, this is useful for grouping blocks together and keeping
791
+ track of them as the position of blocks can change, defaults to ``""``.
536
792
"""
537
793
self ._setBlock (x , y , z , blockType , blockData , tag )
538
794
@@ -561,6 +817,34 @@ def _setBlock(self, x, y, z, blockType, blockData, tag):
561
817
def setBlocks (self , x1 , y1 , z1 , x2 , y2 , z2 , blockType , blockData = 0 , tag = "" ):
562
818
"""
563
819
creates a cuboid of blocks in the shape and redraws it
820
+
821
+ :param int x1:
822
+ The x position of the first point.
823
+
824
+ :param int y1:
825
+ The y position of the first point.
826
+
827
+ :param int z1:
828
+ The z position of the first point.
829
+
830
+ :param int x2:
831
+ The x position of the second point.
832
+
833
+ :param int y2:
834
+ The y position of the second point.
835
+
836
+ :param int z2:
837
+ The z position of the second point.
838
+
839
+ :param int blockType:
840
+ The block id.
841
+
842
+ :param int blockData:
843
+ The block data value, defaults to ``0``.
844
+
845
+ :param string tag:
846
+ A tag for the block, this is useful for grouping blocks together and keeping
847
+ track of them as the position of blocks can change, defaults to ``""``.
564
848
"""
565
849
#order x, y, z's
566
850
if x1 > x2 : x1 , x2 = x2 , x1
@@ -579,7 +863,16 @@ def setBlocks(self, x1, y1, z1, x2, y2, z2, blockType, blockData = 0, tag = ""):
579
863
580
864
def getShapeBlock (self , x , y , z ):
581
865
"""
582
- returns the shape block for an 'actual position'
866
+ returns the ShapeBlock for an 'actual position'
867
+
868
+ :param int x:
869
+ The x position.
870
+
871
+ :param int y:
872
+ The y position.
873
+
874
+ :param int z:
875
+ The z position.
583
876
"""
584
877
#does the block exist?
585
878
for shapeBlock in self .shapeBlocks :
@@ -592,8 +885,26 @@ def getShapeBlock(self, x, y, z):
592
885
# a class created to manage a block within a shape
593
886
class ShapeBlock ():
594
887
"""
595
- ShapeBlock
596
- a class to hold one block within a shape
888
+ ShapeBlock - a class to hold one block within a shape
889
+
890
+ :param int x:
891
+ The x position.
892
+
893
+ :param int y:
894
+ The y position.
895
+
896
+ :param int z:
897
+ The z position.
898
+
899
+ :param int blockType:
900
+ The block id.
901
+
902
+ :param int blockData:
903
+ The block data value, defaults to ``0``.
904
+
905
+ :param string tag:
906
+ A tag for the block, this is useful for grouping blocks together and keeping
907
+ track of them as the position of blocks can change, defaults to ``""``.
597
908
"""
598
909
def __init__ (self , x , y , z , blockType , blockData = 0 , tag = "" ):
599
910
#persist data
@@ -631,6 +942,16 @@ def __eq__(self, other):
631
942
return (self .actualPos .x , self .actualPos .y , self .actualPos .z , self .blockType , self .blockData ) == (other .actualPos .x , other .actualPos .y , other .actualPos .z , other .blockType , other .blockData )
632
943
633
944
class MinecraftTurtle :
945
+ """
946
+ MinecraftTurle - a graphics turtle, which can be used to create 'things' in Minecraft by
947
+ controlling its position, angles and direction
948
+
949
+ :param mcpi.minecraft.Minecraft mc:
950
+ A Minecraft object which is connected to a world.
951
+
952
+ :param mcpi.minecraft.Vec3 position:
953
+ The position where the shape should be created, defaults to ``0,0,0``.
954
+ """
634
955
635
956
SPEEDTIMES = {0 : 0 , 10 : 0.1 , 9 : 0.2 , 8 : 0.3 , 7 : 0.4 , 6 : 0.5 , 5 : 0.6 , 4 : 0.7 , 3 : 0.8 , 2 : 0.9 , 1 : 1 }
636
957
@@ -662,13 +983,25 @@ def __init__(self, mc, position=minecraft.Vec3(0, 0, 0)):
662
983
self ._drawTurtle (int (self .position .x ), int (self .position .y ), int (self .position .y ))
663
984
664
985
def forward (self , distance ):
986
+ """
987
+ move the turtle forward
988
+
989
+ :param int distance:
990
+ the number of blocks to move.
991
+ """
665
992
# get end of line
666
993
# x,y,z = self._findTargetBlock(self.position.x, self.position.y, self.position.z, self.heading, self.verticalheading, distance)
667
994
x , y , z = self ._findPointOnSphere (self .position .x , self .position .y , self .position .z , self .heading , self .verticalheading , distance )
668
995
# move turtle forward
669
996
self ._moveTurtle (x , y , z )
670
997
671
998
def backward (self , distance ):
999
+ """
1000
+ move the turtle backward
1001
+
1002
+ :param int distance:
1003
+ the number of blocks to move.
1004
+ """
672
1005
# move turtle backward
673
1006
# get end of line
674
1007
# x,y,z = self._findTargetBlock(self.position.x, self.position.y, self.position.z, self.heading, self.verticalheading - 180, distance)
@@ -719,18 +1052,36 @@ def _moveTurtle(self, x, y, z):
719
1052
self ._drawTurtle (targetX , targetY , targetZ )
720
1053
721
1054
def right (self , angle ):
1055
+ """
1056
+ rotate the turtle right
1057
+
1058
+ :param float angle:
1059
+ the angle in degrees to rotate.
1060
+ """
722
1061
# rotate turtle angle to the right
723
1062
self .heading = self .heading + angle
724
1063
if self .heading > 360 :
725
1064
self .heading = self .heading - 360
726
1065
727
1066
def left (self , angle ):
1067
+ """
1068
+ rotate the turtle left
1069
+
1070
+ :param float angle:
1071
+ the angle in degrees to rotate.
1072
+ """
728
1073
# rotate turtle angle to the left
729
1074
self .heading = self .heading - angle
730
1075
if self .heading < 0 :
731
1076
self .heading = self .heading + 360
732
1077
733
1078
def up (self , angle ):
1079
+ """
1080
+ rotate the turtle up
1081
+
1082
+ :param float angle:
1083
+ the angle in degrees to rotate.
1084
+ """
734
1085
# rotate turtle angle up
735
1086
self .verticalheading = self .verticalheading + angle
736
1087
if self .verticalheading > 360 :
@@ -740,6 +1091,12 @@ def up(self, angle):
740
1091
self .flying = True
741
1092
742
1093
def down (self , angle ):
1094
+ """
1095
+ rotate the turtle down
1096
+
1097
+ :param float angle:
1098
+ the angle in degrees to rotate.
1099
+ """
743
1100
# rotate turtle angle down
744
1101
self .verticalheading = self .verticalheading - angle
745
1102
if self .verticalheading < 0 :
@@ -749,15 +1106,45 @@ def down(self, angle):
749
1106
self .flying = True
750
1107
751
1108
def setx (self , x ):
1109
+ """
1110
+ set the turtle's x position
1111
+
1112
+ :param int x:
1113
+ the x position.
1114
+ """
752
1115
self .setposition (x , self .position .y , self .position .z )
753
1116
754
1117
def sety (self , y ):
1118
+ """
1119
+ set the turtle's y position
1120
+
1121
+ :param int y:
1122
+ the y position.
1123
+ """
755
1124
self .setposition (self .position .x , y , self .position .z )
756
1125
757
1126
def setz (self , z ):
1127
+ """
1128
+ set the turtle's z position
1129
+
1130
+ :param int z:
1131
+ the z position.
1132
+ """
758
1133
self .setposition (self .position .x , self .position .y , z )
759
1134
760
1135
def setposition (self , x , y , z ):
1136
+ """
1137
+ set the turtle's position
1138
+
1139
+ :param int x:
1140
+ the x position.
1141
+
1142
+ :param int y:
1143
+ the y position.
1144
+
1145
+ :param int z:
1146
+ the z position.
1147
+ """
761
1148
# clear the turtle
762
1149
if self .showturtle :
763
1150
self ._clearTurtle (self .position .x , self .position .y , self .position .z )
@@ -770,39 +1157,85 @@ def setposition(self, x, y, z):
770
1157
self ._drawTurtle (self .position .x , self .position .y , self .position .z )
771
1158
772
1159
def setheading (self , angle ):
1160
+ """
1161
+ set the turtle's horizontal heading
1162
+
1163
+ :param float angle:
1164
+ the angle in degrees.
1165
+ """
773
1166
self .heading = angle
774
1167
775
1168
def setverticalheading (self , angle ):
1169
+ """
1170
+ set the turtle's verticle heading
1171
+
1172
+ :param float angle:
1173
+ the angle in degrees.
1174
+ """
776
1175
self .verticalheading = angle
777
1176
# turn flying on
778
1177
if not self .flying :
779
1178
self .flying = True
780
1179
781
1180
def home (self ):
1181
+ """
1182
+ reset the turtle's position
1183
+ """
782
1184
self .position .x = self .startposition .x
783
1185
self .position .y = self .startposition .y
784
1186
self .position .z = self .startposition .z
785
1187
786
1188
def pendown (self ):
1189
+ """
1190
+ put the turtles pen down, show it will draw
1191
+ """
787
1192
self ._pendown = True
788
1193
789
1194
def penup (self ):
1195
+ """
1196
+ put the turtles pen up, show it wont draw
1197
+ """
790
1198
self ._pendown = False
791
1199
792
1200
def isdown (self ):
1201
+ """
1202
+ returns ``True`` if the pen is down
1203
+ """
793
1204
return self .pendown
794
1205
795
1206
def fly (self ):
1207
+ """
1208
+ sets the turtle to 'fly', i.e. not have to move along the ground.
1209
+ """
796
1210
self .flying = True
797
1211
798
1212
def walk (self ):
1213
+ """
1214
+ sets the turtle to 'walk', i.e. it has to move along the ground.
1215
+ """
799
1216
self .flying = False
800
1217
self .verticalheading = 0
801
1218
802
1219
def penblock (self , blockId , blockData = 0 ):
1220
+ """
1221
+ set the block the turtle uses as its pen.
1222
+
1223
+ :param int blockType:
1224
+ The block id.
1225
+
1226
+ :param int blockData:
1227
+ The block data value, defaults to ``0``.
1228
+ """
803
1229
self ._penblock = block .Block (blockId , blockData )
804
1230
805
1231
def speed (self , turtlespeed ):
1232
+ """
1233
+ set the turtle's speed.
1234
+
1235
+ :param int turtlespeed:
1236
+ ``1`` - ``10``, 1 being the slowest, 10 being the fastest, defaults to ``6``.
1237
+ When set to ``0`` the turtle draws instantaneously.
1238
+ """
806
1239
self .turtlespeed = turtlespeed
807
1240
808
1241
def _drawTurtle (self , x , y , z ):
0 commit comments