Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fd2f6fb

Browse files
committedJul 12, 2017
updated minecraftstuff
1 parent 2584673 commit fd2f6fb

File tree

1 file changed

+454
-21
lines changed

1 file changed

+454
-21
lines changed
 

‎mcpi/minecraftstuff.py

+454-21
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,65 @@
1111
import block
1212
import util
1313

14-
from copy import deepcopy
1514
import time
1615
import math
1716

1817
class Points():
18+
"""
19+
Points - a collection of minecraft positions or Vec3's. Used when drawing faces ``MinecraftDrawing.drawFace()``.
20+
"""
1921
def __init__(self):
2022
self._points = []
2123

2224
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+
"""
2337
self._points.append(minecraft.Vec3(x, y, z))
2438

2539
def getVec3s(self):
40+
"""
41+
returns a list of Vec3 positions
42+
"""
2643
return self._points
2744

2845
class MinecraftDrawing:
2946
"""
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.
3151
"""
3252
def __init__(self, mc):
3353
self.mc = mc
3454

3555
def drawPoint3d(self, x, y, z, blockType, blockData=0):
3656
"""
3757
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``.
3873
"""
3974

4075
self.mc.setBlock(x,y,z,blockType,blockData)
@@ -43,6 +78,19 @@ def drawPoint3d(self, x, y, z, blockType, blockData=0):
4378
def drawFace(self, vertices, filled, blockType, blockData=0):
4479
"""
4580
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``.
4694
"""
4795

4896
# was a Points class passed? If so get the list of Vec3s.
@@ -94,20 +142,72 @@ def keyZ( point ): return point.z
94142
def drawVertices(self, vertices, blockType, blockData=0):
95143
"""
96144
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``.
97154
"""
155+
98156
for vertex in vertices:
99157
self.drawPoint3d(vertex.x, vertex.y, vertex.z, blockType, blockData)
100158

101159
def drawLine(self, x1, y1, z1, x2, y2, z2, blockType, blockData=0):
102160
"""
103161
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``.
104186
"""
105187
self.drawVertices(self.getLine(x1, y1, z1, x2, y2, z2), blockType, blockData)
106188

107189

108190
def drawSphere(self, x1, y1, z1, radius, blockType, blockData=0):
109191
"""
110192
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``.
111211
"""
112212
for x in range(radius * -1, radius):
113213
for y in range(radius * -1, radius):
@@ -117,7 +217,25 @@ def drawSphere(self, x1, y1, z1, radius, blockType, blockData=0):
117217

118218
def drawHollowSphere(self, x1, y1, z1, radius, blockType, blockData=0):
119219
"""
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``.
121239
"""
122240
for x in range(radius * -1, radius):
123241
for y in range(radius * -1, radius):
@@ -128,6 +246,24 @@ def drawHollowSphere(self, x1, y1, z1, radius, blockType, blockData=0):
128246
def drawCircle(self, x0, y0, z, radius, blockType, blockData=0):
129247
"""
130248
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``.
131267
"""
132268

133269
f = 1 - radius
@@ -161,6 +297,24 @@ def drawCircle(self, x0, y0, z, radius, blockType, blockData=0):
161297
def drawHorizontalCircle(self, x0, y, z0, radius, blockType, blockData=0):
162298
"""
163299
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``.
164318
"""
165319

166320
f = 1 - radius
@@ -195,6 +349,24 @@ def getLine(self, x1, y1, z1, x2, y2, z2):
195349
Returns all the points which would make up a line between 2 points as a list
196350
197351
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.
198370
"""
199371
# return the maximum of 2 values
200372
def MAX(a,b):
@@ -293,12 +465,25 @@ def ZSGN(a):
293465
# MinecraftShape - a class for managing shapes
294466
class MinecraftShape:
295467
"""
296-
MinecraftShape
468+
MinecraftShape - the implementation of a 'shape' in Minecraft.
297469
298-
The implementation of a 'shape' in Minecraft.
299470
Each shape consists of one or many blocks with a position relative to each other.
471+
300472
Shapes can be transformed by movement and rotation.
473+
301474
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``.
302487
"""
303488

304489
def __init__(self, mc, position, shapeBlocks = None, visible = True):
@@ -327,8 +512,8 @@ def __init__(self, mc, position, shapeBlocks = None, visible = True):
327512

328513
def draw(self):
329514
"""
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
332517
"""
333518

334519
#create 2 sets only of the blocks which are drawn and one of the shapeBlocks
@@ -347,12 +532,12 @@ def draw(self):
347532
self.mc.setBlock(blockToDraw.actualPos.x, blockToDraw.actualPos.y, blockToDraw.actualPos.z, blockToDraw.blockType, blockToDraw.blockData)
348533

349534
#update the blocks which have been drawn
350-
self.drawnShapeBlocks = deepcopy(self.shapeBlocks)
535+
self.drawnShapeBlocks = self._copyBlocks(self.shapeBlocks)
351536
self.visible = True
352537

353538
def redraw(self):
354539
"""
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
356541
"""
357542
if self.drawnShapeBlocks != None:
358543
for blockToClear in self.drawnShapeBlocks:
@@ -362,7 +547,7 @@ def redraw(self):
362547
self.mc.setBlock(blockToDraw.actualPos.x, blockToDraw.actualPos.y, blockToDraw.actualPos.z, blockToDraw.blockType, blockToDraw.blockData)
363548

364549
#update the blocks which have been drawn
365-
self.drawnShapeBlocks = deepcopy(self.shapeBlocks)
550+
self.drawnShapeBlocks = self._copyBlocks(self.shapeBlocks)
366551
self.visible = True
367552

368553
def clear(self):
@@ -390,12 +575,31 @@ def reset(self):
390575
def moveBy(self, x, y, z):
391576
"""
392577
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+
393588
"""
394589
return self._move(self.position.x + x, self.position.y + y, self.position.z + z)
395590

396591
def move(self, x, y, z):
397592
"""
398593
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.
399603
"""
400604
#is the position different
401605
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):
426630

427631
if self.visible:
428632
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
429646

430647
def _recalcBlocks(self):
431648
"""
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
433650
"""
434651
for shapeBlock in self.shapeBlocks:
435652
self._recalcBlock(shapeBlock)
436653

437654
def _recalcBlock(self, shapeBlock):
438655
"""
439-
recalulate the shapeBlock's position based on its relative position,
656+
Internal. recalulate the shapeBlock's position based on its relative position,
440657
its actual position in the world and its rotation
441658
"""
442659
#reset the block's position before recalcing it
@@ -451,6 +668,15 @@ def _recalcBlock(self, shapeBlock):
451668
def rotate(self, yaw, pitch, roll):
452669
"""
453670
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.
454680
"""
455681
#is the rotation different?
456682
if yaw != self.yaw or pitch != self.pitch or roll != self.roll:
@@ -474,20 +700,29 @@ def rotate(self, yaw, pitch, roll):
474700
def rotateBy(self, yaw, pitch, roll):
475701
"""
476702
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.
477712
"""
478713
return self.rotate(self.yaw + yaw, self.pitch + pitch, self.roll + roll)
479714

480715
def _moveShapeBlock(self, shapeBlock, x, y, z):
481716
"""
482-
offset the position of the block by the position
717+
Internal. offset the position of the block by the position
483718
"""
484719
shapeBlock.actualPos.x = shapeBlock.relativePos.x + x
485720
shapeBlock.actualPos.y = shapeBlock.relativePos.y + y
486721
shapeBlock.actualPos.z = shapeBlock.relativePos.z + z
487722

488723
def _rotateShapeBlock(self, shapeBlock, yaw, pitch, roll):
489724
"""
490-
rotate the block
725+
Internal. rotate the block
491726
"""
492727
self._rotateShapeBlockY(shapeBlock, yaw)
493728
self._rotateShapeBlockZ(shapeBlock, roll)
@@ -496,7 +731,7 @@ def _rotateShapeBlock(self, shapeBlock, yaw, pitch, roll):
496731

497732
def _rotateShapeBlockY(self, shapeBlock, theta):
498733
"""
499-
rotate y = yaw (direction)
734+
Internal. rotate y = yaw (direction)
500735
"""
501736
if theta != 0:
502737
sin_t = math.sin(math.radians(theta))
@@ -508,7 +743,7 @@ def _rotateShapeBlockY(self, shapeBlock, theta):
508743

509744
def _rotateShapeBlockZ(self, shapeBlock, theta):
510745
"""
511-
rotate z = roll
746+
Internal. rotate z = roll
512747
"""
513748
if theta != 0:
514749
sin_t = math.sin(math.radians(theta))
@@ -520,7 +755,7 @@ def _rotateShapeBlockZ(self, shapeBlock, theta):
520755

521756
def _rotateShapeBlockX(self, shapeBlock, theta):
522757
"""
523-
rotate x = pitch
758+
Internal. rotate x = pitch
524759
"""
525760
if theta != 0:
526761
sin_t = math.sin(math.radians(theta))
@@ -532,7 +767,28 @@ def _rotateShapeBlockX(self, shapeBlock, theta):
532767

533768
def setBlock(self, x, y, z, blockType, blockData = 0, tag = ""):
534769
"""
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 ``""``.
536792
"""
537793
self._setBlock(x, y, z, blockType, blockData, tag)
538794

@@ -561,6 +817,34 @@ def _setBlock(self, x, y, z, blockType, blockData, tag):
561817
def setBlocks(self, x1, y1, z1, x2, y2, z2, blockType, blockData = 0, tag = ""):
562818
"""
563819
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 ``""``.
564848
"""
565849
#order x, y, z's
566850
if x1 > x2: x1, x2 = x2, x1
@@ -579,7 +863,16 @@ def setBlocks(self, x1, y1, z1, x2, y2, z2, blockType, blockData = 0, tag = ""):
579863

580864
def getShapeBlock(self, x, y, z):
581865
"""
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.
583876
"""
584877
#does the block exist?
585878
for shapeBlock in self.shapeBlocks:
@@ -592,8 +885,26 @@ def getShapeBlock(self, x, y, z):
592885
# a class created to manage a block within a shape
593886
class ShapeBlock():
594887
"""
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 ``""``.
597908
"""
598909
def __init__(self, x, y, z, blockType, blockData = 0, tag = ""):
599910
#persist data
@@ -631,6 +942,16 @@ def __eq__(self, other):
631942
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)
632943

633944
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+
"""
634955

635956
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}
636957

@@ -662,13 +983,25 @@ def __init__(self, mc, position=minecraft.Vec3(0, 0, 0)):
662983
self._drawTurtle(int(self.position.x), int(self.position.y), int(self.position.y))
663984

664985
def forward(self, distance):
986+
"""
987+
move the turtle forward
988+
989+
:param int distance:
990+
the number of blocks to move.
991+
"""
665992
# get end of line
666993
# x,y,z = self._findTargetBlock(self.position.x, self.position.y, self.position.z, self.heading, self.verticalheading, distance)
667994
x, y, z = self._findPointOnSphere(self.position.x, self.position.y, self.position.z, self.heading, self.verticalheading, distance)
668995
# move turtle forward
669996
self._moveTurtle(x, y, z)
670997

671998
def backward(self, distance):
999+
"""
1000+
move the turtle backward
1001+
1002+
:param int distance:
1003+
the number of blocks to move.
1004+
"""
6721005
# move turtle backward
6731006
# get end of line
6741007
# 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):
7191052
self._drawTurtle(targetX, targetY, targetZ)
7201053

7211054
def right(self, angle):
1055+
"""
1056+
rotate the turtle right
1057+
1058+
:param float angle:
1059+
the angle in degrees to rotate.
1060+
"""
7221061
# rotate turtle angle to the right
7231062
self.heading = self.heading + angle
7241063
if self.heading > 360:
7251064
self.heading = self.heading - 360
7261065

7271066
def left(self, angle):
1067+
"""
1068+
rotate the turtle left
1069+
1070+
:param float angle:
1071+
the angle in degrees to rotate.
1072+
"""
7281073
# rotate turtle angle to the left
7291074
self.heading = self.heading - angle
7301075
if self.heading < 0:
7311076
self.heading = self.heading + 360
7321077

7331078
def up(self, angle):
1079+
"""
1080+
rotate the turtle up
1081+
1082+
:param float angle:
1083+
the angle in degrees to rotate.
1084+
"""
7341085
# rotate turtle angle up
7351086
self.verticalheading = self.verticalheading + angle
7361087
if self.verticalheading > 360:
@@ -740,6 +1091,12 @@ def up(self, angle):
7401091
self.flying = True
7411092

7421093
def down(self, angle):
1094+
"""
1095+
rotate the turtle down
1096+
1097+
:param float angle:
1098+
the angle in degrees to rotate.
1099+
"""
7431100
# rotate turtle angle down
7441101
self.verticalheading = self.verticalheading - angle
7451102
if self.verticalheading < 0:
@@ -749,15 +1106,45 @@ def down(self, angle):
7491106
self.flying = True
7501107

7511108
def setx(self, x):
1109+
"""
1110+
set the turtle's x position
1111+
1112+
:param int x:
1113+
the x position.
1114+
"""
7521115
self.setposition(x, self.position.y, self.position.z)
7531116

7541117
def sety(self, y):
1118+
"""
1119+
set the turtle's y position
1120+
1121+
:param int y:
1122+
the y position.
1123+
"""
7551124
self.setposition(self.position.x, y, self.position.z)
7561125

7571126
def setz(self, z):
1127+
"""
1128+
set the turtle's z position
1129+
1130+
:param int z:
1131+
the z position.
1132+
"""
7581133
self.setposition(self.position.x, self.position.y, z)
7591134

7601135
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+
"""
7611148
# clear the turtle
7621149
if self.showturtle:
7631150
self._clearTurtle(self.position.x, self.position.y, self.position.z)
@@ -770,39 +1157,85 @@ def setposition(self, x, y, z):
7701157
self._drawTurtle(self.position.x, self.position.y, self.position.z)
7711158

7721159
def setheading(self, angle):
1160+
"""
1161+
set the turtle's horizontal heading
1162+
1163+
:param float angle:
1164+
the angle in degrees.
1165+
"""
7731166
self.heading = angle
7741167

7751168
def setverticalheading(self, angle):
1169+
"""
1170+
set the turtle's verticle heading
1171+
1172+
:param float angle:
1173+
the angle in degrees.
1174+
"""
7761175
self.verticalheading = angle
7771176
# turn flying on
7781177
if not self.flying:
7791178
self.flying = True
7801179

7811180
def home(self):
1181+
"""
1182+
reset the turtle's position
1183+
"""
7821184
self.position.x = self.startposition.x
7831185
self.position.y = self.startposition.y
7841186
self.position.z = self.startposition.z
7851187

7861188
def pendown(self):
1189+
"""
1190+
put the turtles pen down, show it will draw
1191+
"""
7871192
self._pendown = True
7881193

7891194
def penup(self):
1195+
"""
1196+
put the turtles pen up, show it wont draw
1197+
"""
7901198
self._pendown = False
7911199

7921200
def isdown(self):
1201+
"""
1202+
returns ``True`` if the pen is down
1203+
"""
7931204
return self.pendown
7941205

7951206
def fly(self):
1207+
"""
1208+
sets the turtle to 'fly', i.e. not have to move along the ground.
1209+
"""
7961210
self.flying = True
7971211

7981212
def walk(self):
1213+
"""
1214+
sets the turtle to 'walk', i.e. it has to move along the ground.
1215+
"""
7991216
self.flying = False
8001217
self.verticalheading = 0
8011218

8021219
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+
"""
8031229
self._penblock = block.Block(blockId, blockData)
8041230

8051231
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+
"""
8061239
self.turtlespeed = turtlespeed
8071240

8081241
def _drawTurtle(self, x, y, z):

0 commit comments

Comments
 (0)
Please sign in to comment.