Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Draw the Google G logo
- import turtle
- # A function to turn left by a right angle, then go forward
- def leftfwd(n):
- t.left(90)
- t.forward(n)
- # define a function that draws and fills in a coloured segment of the G
- def segment(col, arc):
- t.color(col)
- t.begin_fill()
- t.circle(150, arc) # draw outer edge, going anti-clockwise
- np = t.pos() # remember current position
- nh = t.heading() # remember current direction
- leftfwd(50) # turn inwards, go forward 50
- t.left(90)
- t.circle(-100, arc) # draw inner edge, going clockwise
- t.end_fill() # color fill the segment
- t.penup()
- t.setheading(nh)
- t.goto(np) # go to remembered position and direction
- t.pendown()
- t = turtle.Turtle()
- t.penup()
- t.pensize(1)
- t.speed(3)
- t.goto(100, 100)
- t.left(135)
- t.pendown()
- segment('red', 100) # draw a red segment of 100 degrees
- segment('orange', 70) # draw an orange segment of 70 degrees
- segment('green', 100) # draw a green segment of 100 degrees
- segment('blue', 45) # draw a blue segment of 45 degrees
- # Draw the rest of the blue shape
- t.begin_fill()
- leftfwd(90)
- leftfwd(40)
- leftfwd(60)
- t.end_fill()
- turtle.exitonclick()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement