"""
python海龟画斜着的椭圆.py
"""
import math
from turtle import *
def draw_oval2(a,b=None,width=5,fill=''):
"""以海龟为中心点画椭圆,这个方法会根据角色的方向对椭圆进行倾斜,所以速度慢
a:长半轴,b:短半轴,
width:边框像素值
fill:填充颜色,如果为空字符串,则无颜色
"""
if b == None : b = a
cx,cy = tom.pos() # 中心点坐标
cors = [] # 多边形坐标点
k = math.radians(tom.heading()) # 椭圆的倾斜角度
for t in range(361):
j= math.radians(t)
x = cx + a*math.cos(j)*math.cos(k)-b*math.sin(j)*math.sin(k)
y = cy + a*math.cos(j)*math.sin(k)+b*math.sin(j)*math.cos(k)
cors.append(x)
cors.append(-y)
item = screen.cv.create_polygon(cors, fill=fill,width=width,outline='black')
def draw_oval(a,b=None,width=5,fill=''):
""" 以海龟为中心点画椭圆,这个方法不会根据角色的方向对椭圆进行倾斜,所以速度快.
a:长半轴,b:短半轴,
width:边框像素值
fill:填充颜色,
outline:边框颜色
"""
if b == None : b = a
x,y = tom.pos()
x0,y0 = x-a,-y-b
x1,y1 = x+a,b-y
item = screen.cv.create_oval(x0,y0,x1,y1,fill=fill,width=width)
tom = Turtle()
screen = tom.getscreen()
tom.pensize(10)
tom.left(45)
draw_oval2(100,50)
screen.mainloop()
-
- 2026 年 1 月
- 2025 年 12 月
- 2025 年 11 月
- 2025 年 10 月
- 2025 年 9 月
- 2025 年 6 月
- 2025 年 5 月
- 2025 年 3 月
- 2025 年 2 月
- 2025 年 1 月
- 2024 年 12 月
- 2024 年 8 月
- 2024 年 6 月
- 2024 年 5 月
- 2024 年 4 月
- 2024 年 3 月
- 2024 年 2 月
- 2023 年 11 月
- 2023 年 9 月
- 2023 年 6 月
- 2023 年 5 月
- 2023 年 4 月
- 2023 年 3 月
- 2023 年 2 月
- 2023 年 1 月
- 2022 年 12 月
- 2022 年 11 月
- 2022 年 10 月
- 2022 年 9 月
- 2022 年 8 月
- 2022 年 7 月
- 2022 年 6 月
- 2022 年 5 月
- 2022 年 4 月
- 2022 年 3 月
- 2022 年 2 月
- 2022 年 1 月
- 2021 年 12 月
- 2021 年 11 月
- 2021 年 10 月
- 2021 年 9 月
- 2021 年 8 月
- 2021 年 7 月
- 2021 年 6 月
- 2021 年 5 月
- 2021 年 4 月
- 2021 年 3 月
- 2021 年 2 月
- 2021 年 1 月
- 2020 年 12 月
- 2020 年 11 月
- 2020 年 10 月
- 2020 年 9 月
- 2020 年 8 月
- 2020 年 7 月
- 2020 年 6 月
- 2020 年 5 月
- 2020 年 4 月
- 2020 年 3 月
- 2020 年 2 月
- 2020 年 1 月
- 2019 年 12 月
- 2019 年 11 月
- 2019 年 10 月
- 2019 年 9 月
- 2019 年 8 月
- 2019 年 7 月
- 2019 年 6 月
- 2019 年 5 月
- 2019 年 4 月
- 2019 年 3 月
- 2019 年 2 月
- 2018 年 3 月
- 2018 年 1 月
- 2017 年 9 月
- 2017 年 5 月
- 2017 年 1 月

