import turtle as t
import math
t.setup(1000, 750) #设置窗口大小
t.setworldcoordinates(-800,-600,800,600) #设置坐标系
t.title('I am ikun!!')
t.width(8)
t.speed(0)
t.pencolor('black')
#以圆心和半径画圆
def my_circle(rad,c_x,c_y,color=None):
if color is not None:
t.fillcolor(color)
t.begin_fill()
t.penup()
t.setheading(0)
t.goto(c_x,c_y-rad)
t.pendown()
t.circle(rad)
if color is not None:
t.end_fill()
#求θ角度方向上椭圆的坐标
def get_ellipse_xy(a,b,theta):
if theta < 0:theta=theta+math.pi*2
x = a * b / math.sqrt(b * b + a * a * math.tan(theta) * math.tan(theta))
if theta < math.pi/2:
return {'x':x,'y':x*math.tan(theta)}
elif theta < math.pi:
return {'x':x*(-1),'y':x*(-1)*math.tan(theta)}
elif theta < math.pi*3/2:
return {'x':x*(-1),'y':x*(-1)*math.tan(theta)}
else:
return {'x': x, 'y': x*math.tan(theta)}
# 画一个椭圆,shape为椭圆形状参数,start_ang、end_ang为起始角度(相对于椭圆中心)
# shape = {"X0": 0,"Y0": 0,"a": 200,"b": 100,"angle": math.pi/3}
def draw_ellipse(shape, start_ang, end_ang, color=None):
if color is not None:
t.fillcol
你是小黑子吗?是就画一只鸡吧!(python)
最新推荐文章于 2024-11-22 18:18:27 发布