@@ -31,10 +31,14 @@ class Color:
31
31
WHITE = 0xFFFFFF
32
32
BLACK = 0x0000
33
33
RED = 0xFF0000
34
+ ORANGE = 0xFFA500
35
+ YELLOW = 0xFFFF00
34
36
GREEN = 0x00FF00
35
37
BLUE = 0x0000FF
38
+ PURPLE = 0x800080
39
+ PINK = 0xFFC0CB
36
40
37
- colors = (WHITE , BLACK , RED , GREEN , BLUE )
41
+ colors = (WHITE , BLACK , RED , ORANGE , YELLOW , GREEN , BLUE , PURPLE , PINK )
38
42
39
43
class Vec2D (tuple ):
40
44
"""A 2 dimensional vector class, used as a helper class
@@ -136,8 +140,8 @@ def __init__(self, display=board.DISPLAY):
136
140
self ._display .wait_for_frame ()
137
141
138
142
def _drawturtle (self ):
139
- self ._turtle_sprite .x = self ._x - 4
140
- self ._turtle_sprite .y = self ._y - 4
143
+ self ._turtle_sprite .x = int ( self ._x - 4 )
144
+ self ._turtle_sprite .y = int ( self ._y - 4 )
141
145
#print("pos (%d, %d)" % (self._x, self._y))
142
146
143
147
# Turtle motion
@@ -196,13 +200,13 @@ def goto(self, x1, y1=None):
196
200
197
201
while (not rev and x0 <= x1 ) or (rev and x1 <= x0 ):
198
202
if steep :
199
- self ._fg_bitmap [y0 , x0 ] = self ._pencolor
203
+ self ._fg_bitmap [int ( y0 ), int ( x0 ) ] = self ._pencolor
200
204
self ._x = y0
201
205
self ._y = x0
202
206
self ._drawturtle ()
203
207
time .sleep (0.003 )
204
208
else :
205
- self ._fg_bitmap [x0 , y0 ] = self ._pencolor
209
+ self ._fg_bitmap [int ( x0 ), int ( y0 ) ] = self ._pencolor
206
210
self ._x = x0
207
211
self ._y = y0
208
212
self ._drawturtle ()
@@ -232,13 +236,61 @@ def home(self):
232
236
self .setheading (90 )
233
237
self .goto (0 ,0 )
234
238
235
- def circle (radius , extent = None , steps = None ):
239
+ def circle (self , radius , extent = None , steps = None ):
236
240
raise NotImplementedError
237
241
238
- def dot (size = None , * color ):
242
+ def dot (self , size = None , * color ):
239
243
raise NotImplementedError
240
244
245
+ def stamp (self ):
246
+ raise NotImplementedError
247
+
248
+ def clearstamp (self ):
249
+ raise NotImplementedError
250
+
251
+ def clearstamps (self ):
252
+ raise NotImplementedError
253
+
254
+ def undo (self ):
255
+ raise NotImplementedError
256
+
257
+ def speed (self , speed = None ):
258
+ raise NotImplementedError
259
+
260
+
241
261
####################
262
+ # Tell turtle's state
263
+ def pos (self ):
264
+ return Vec2D (self ._x - self ._w // 2 , self ._h // 2 - self ._y )
265
+ position = pos
266
+
267
+
268
+
269
+
270
+ def heading (self ):
271
+ return self ._heading
272
+
273
+
274
+ # Pen control
275
+ def pendown (self ):
276
+ self ._penstate = True
277
+ pd = pendown
278
+ down = pendown
279
+
280
+ def penup (self ):
281
+ self ._penstate = False
282
+ pu = penup
283
+ up = penup
284
+
285
+ def isdown (self ):
286
+ return self ._penstate
287
+
288
+ def pencolor (self , c ):
289
+ if not c in Color .colors :
290
+ raise RuntimeError ("Color must be one of the 'color' class items" )
291
+ self ._pencolor = 1 + Color .colors .index (c )
292
+
293
+
242
294
243
295
def mode (self , mode = None ):
244
296
if mode == "standard" :
@@ -258,38 +310,3 @@ def _turn(self, angle):
258
310
else :
259
311
self ._heading += angle
260
312
self ._heading %= 360 # wrap around
261
-
262
-
263
-
264
-
265
- def heading (self ):
266
- return self ._heading
267
-
268
- def pencolor (self , c ):
269
- if not c in Color .colors :
270
- raise RuntimeError ("Color must be one of the 'color' class items" )
271
- #print(self._fg_palette[0])
272
- self ._pencolor = 1 + Color .colors .index (c )
273
-
274
- # Tell turtle's state
275
- def pos (self ):
276
- return Vec2D (self ._x - self ._w // 2 , self ._h // 2 - self ._y )
277
- def position (self ):
278
- return self .pos ()
279
-
280
- # Pen control
281
- def pendown (self ):
282
- self ._penstate = True
283
- def pd (self ):
284
- self .pendown ()
285
- def down (self ):
286
- self .pendown ()
287
- def isdown (self ):
288
- return self ._penstate
289
-
290
- def penup (self ):
291
- self ._penstate = False
292
- def pu (self ):
293
- self .penup ()
294
- def up (self ):
295
- self .penup ()
0 commit comments