Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. # This demo draws the Spiral of Theodorus (see the Wikipedia entry)
  2. # This version fills the triangles with a gradually changing colour.
  3. # It uses the colorchooser dialog from the tkinter module to allow the
  4. # user to specify the starting and ending colours.
  5.  
  6. import turtle
  7. import math
  8. import tkinter.colorchooser
  9.  
  10. def main() :
  11. numSlices = 16
  12. startColour = tkinter.colorchooser.askcolor(title="Starting Shade")[0]
  13. startRed = int(startColour[0])
  14. startGreen = int(startColour[1])
  15. startBlue = int(startColour[2])
  16. finishColour = tkinter.colorchooser.askcolor(title="Ending Shade")[0]
  17. finishRed = int(finishColour[0])
  18. finishGreen = int(finishColour[1])
  19. finishBlue = int(finishColour[2])
  20. redIncr = (startRed - finishRed) / numSlices
  21. greenIncr = (startGreen - finishGreen) / numSlices
  22. blueIncr = (startBlue - finishBlue) / numSlices
  23. turtle.shape("turtle")
  24. turtle.pensize(1)
  25. turtle.speed(10)
  26. turtle.colormode(255)
  27. turtle.pencolor("blue")
  28. size = 80
  29. count = 1
  30. angle = 0
  31. turtle.fillcolor((startRed, startGreen, startBlue))
  32. turtle.begin_fill()
  33. turtle.forward(size)
  34. while count < 17 :
  35. turtle.left(90)
  36. turtle.forward(size)
  37. xPos, yPos = turtle.position()
  38. turtle.home()
  39. turtle.end_fill()
  40. angle = angle + math.degrees(math.atan(1 / math.sqrt(count)))
  41. turtle.left(angle)
  42. red = finishRed + (numSlices - count) * redIncr
  43. green = finishGreen + (numSlices - count) * greenIncr
  44. blue = finishBlue + (numSlices - count) * blueIncr
  45. turtle.fillcolor((red, green, blue))
  46. turtle.begin_fill()
  47. turtle.setposition(xPos, yPos)
  48. count = count + 1
  49.  
  50. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement