Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This demo draws the Spiral of Theodorus (see the Wikipedia entry)
- # This version fills the triangles with a gradually changing colour.
- # It uses the colorchooser dialog from the tkinter module to allow the
- # user to specify the starting and ending colours.
- import turtle
- import math
- import tkinter.colorchooser
- def main() :
- numSlices = 16
- startColour = tkinter.colorchooser.askcolor(title="Starting Shade")[0]
- startRed = int(startColour[0])
- startGreen = int(startColour[1])
- startBlue = int(startColour[2])
- finishColour = tkinter.colorchooser.askcolor(title="Ending Shade")[0]
- finishRed = int(finishColour[0])
- finishGreen = int(finishColour[1])
- finishBlue = int(finishColour[2])
- redIncr = (startRed - finishRed) / numSlices
- greenIncr = (startGreen - finishGreen) / numSlices
- blueIncr = (startBlue - finishBlue) / numSlices
- turtle.shape("turtle")
- turtle.pensize(1)
- turtle.speed(10)
- turtle.colormode(255)
- turtle.pencolor("blue")
- size = 80
- count = 1
- angle = 0
- turtle.fillcolor((startRed, startGreen, startBlue))
- turtle.begin_fill()
- turtle.forward(size)
- while count < 17 :
- turtle.left(90)
- turtle.forward(size)
- xPos, yPos = turtle.position()
- turtle.home()
- turtle.end_fill()
- angle = angle + math.degrees(math.atan(1 / math.sqrt(count)))
- turtle.left(angle)
- red = finishRed + (numSlices - count) * redIncr
- green = finishGreen + (numSlices - count) * greenIncr
- blue = finishBlue + (numSlices - count) * blueIncr
- turtle.fillcolor((red, green, blue))
- turtle.begin_fill()
- turtle.setposition(xPos, yPos)
- count = count + 1
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement