How do you draw an ellipse/oval in turtle graphics (python)?

孤街醉人 提交于 2020-01-05 04:54:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!