问题
How do you draw an ellipse/oval in turtle graphics (python)? I want to be able to draw an ellipse and part of an ellipse using the circle() function or similar. I can stamp one using #turtlesize(stretch_wid=None, stretch_len=10, outline=None). But I don't want it to be color filled.
回答1:
You can use shapesize() function of turtle to make an ellipse.
shape("circle")
shapesize(5,4,1)
fillcolor("white")
回答2:
I made my own function for drawing ovals that I personally think is very useful:
def talloval(r): # Verticle Oval
turtle.left(45)
for loop in range(2): # Draws 2 halves of ellipse
turtle.circle(r,90) # Long curved part
turtle.circle(r/2,90) # Short curved part
def flatoval(r): # Horizontal Oval
turtle.right(45)
for loop in range(2):
turtle.circle(r,90)
turtle.circle(r/2,90)
The r
is the radius of the circle and it controls how big the ellipse is. The reason for the turn left/right is because without it, the ellipse is diagonal.
回答3:
#you can create circle or ellipse by changing value of parameter of oval=canvas.create_oval(10,15,200,150)
from Tkinter import *
top=Tk()`
canvas=Canvas(top,width=200,height=200)
canvas.pack()
oval=canvas.create_oval(10,15,200,150)
top.mainloop()
来源:https://stackoverflow.com/questions/29465666/how-do-you-draw-an-ellipse-oval-in-turtle-graphics-python