Advertisement
acclivity

pyGoogleG-WithTurtle

Dec 22nd, 2021 (edited)
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. # Draw the Google G logo
  2. import turtle
  3.  
  4. # A function to turn left by a right angle, then go forward
  5. def leftfwd(n):
  6.     t.left(90)
  7.     t.forward(n)
  8.  
  9. # define a function that draws and fills in a coloured segment of the G
  10. def segment(col, arc):
  11.     t.color(col)
  12.     t.begin_fill()
  13.     t.circle(150, arc)      # draw outer edge, going anti-clockwise
  14.     np = t.pos()            # remember current position
  15.     nh = t.heading()        # remember current direction
  16.     leftfwd(50)             # turn inwards, go forward 50
  17.     t.left(90)
  18.     t.circle(-100, arc)     # draw inner edge, going clockwise
  19.     t.end_fill()            # color fill the segment
  20.     t.penup()
  21.     t.setheading(nh)
  22.     t.goto(np)              # go to remembered position and direction
  23.     t.pendown()
  24.  
  25. t = turtle.Turtle()
  26. t.penup()
  27. t.pensize(1)
  28. t.speed(3)
  29. t.goto(100, 100)
  30. t.left(135)
  31. t.pendown()
  32.  
  33. segment('red', 100)             # draw a red segment of 100 degrees
  34.  
  35. segment('orange', 70)           # draw an orange segment of 70 degrees
  36.  
  37. segment('green', 100)           # draw a green segment of 100 degrees
  38.  
  39. segment('blue', 45)             # draw a blue segment of 45 degrees
  40.  
  41. # Draw the rest of the blue shape
  42. t.begin_fill()
  43. leftfwd(90)
  44. leftfwd(40)
  45. leftfwd(60)
  46. t.end_fill()
  47. turtle.exitonclick()
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement