import turtle # Create a window object window = turtle.Screen() window.title("Drawing Pretty shapes") window.bgcolor("lightgreen") # create an animal object tess = turtle.Turtle() tess.color("blue") tess.speed(0) tess.pensize(3) def draw_spiral (size, angle, turns): """ Draw a spiral knowing its innermost side lenght 'size', the angle of turning 'angle' and the number of turns 'turns' """ tess.right(90) # Initially rotate tess to face downwards factor = size # factor is the const by which the side length is increment # This code will solve the first drawing for the exercise # number 4.9-5 but not the second one for the python book # thinkcspy3.pdf april-2018 edition page 77 located @ # https://media.readthedocs.org/pdf/howtothink/latest/howtothink.pdf # I need a generalized code to solve both shapes. for _ in range(5*turns): tess.forward(size) tess.right(90) size = size + factor tess.right(angle) draw_spiral(4, 90, 10) window.mainloop()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question