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 A B C # circle.py from turtle import * # Draw a circle with radius of 50pixels circle(50) # Draw a semicircle with a radius 100pixels circle(100, extent=180) # Draw a triangle which fits in a circle with a radius of 100pixels circle(100, steps=3) # Draw a pentagon which fits in a circle with a radius of 50pixels circle(50, steps=5) # Tell Python to stop waiting for turtle instructions done() #### 0003, Code Box 2.3 # colourful_circle.py from turtle import * pencolor("red") fillcolor("violet") begin_fill() circle(100) end_fill() pencolor("black") circle(50) # Tell Python to stop waiting for turtle instructions done() #### 0008, Code Box 2.4 # square.py from turtle import * # set up some variables side_length=50 n=0 2
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 A B C t.circle(size) t.penup() # move start position t.forward(distance) t.left(angle) n=n+1 # move turtle t.setposition(22,144) t.color("red") # end t.done() #### 0004, Code Box 3.3 # flower.py # this is a really cool little program slightly adapted from: # http://docs.python.org/3.3/library/turtle.html import turtle t=turtle t.speed(8) # set the colour and fill values in one go t.color("green", "purple") # draw the star t.begin_fill() while True : t.forward(150) t.left(170) if t.distance(0,0)<1: break t.end_fill() # hide the turtle when it has finished drawing t.hideturtle() # end t.done() 6