from turtle import *
penup()
goto(0, -100)
pendown()
y = 100
list1 = ['red', 'blue']
for k in list1:
color(k)
begin_fill()
circle(y)
penup()
goto(0, -85)
pendown()
y -= 15
end_fill()
hideturtle()
penup()
goto(0, 70)
pendown()
color('gold', 'orange')
begin_fill()
goto(-40, -60)
goto(0, -20)
goto(40, -60)
goto(0, 70)
end_fill()
penup()
goto(-20, -60)
write("CASC", font=("English", 15, "normal"))
import turtle, math
p = turtle.Turtle()
def new_ellipse(a, b, n=500, right=0, up=0, alpha=360):
"""
将椭圆旋转和左右移动
:param a:长半轴长度
:param b:短半轴长度
:param n:边的数目 -- n越大,越趋近于椭圆
:param right:椭圆往右移动的距离 -- 大于0:实际往右移动,小于0:实际往左移动
:param up:椭圆往上移动的距离 -- 大于0:实际往上移动,小于0:实际往下移动
:param alpha:椭圆旋转的角度
:return:
"""
alpha = (2 * math.pi / 360) * alpha
theta = 0
start_point = (a * math.cos(theta) * math.cos(alpha) - b * math.sin(theta) * math.sin(alpha) + right,
a * math.cos(theta) * math.sin(alpha) + b * math.sin(theta) * math.cos(alpha) + up)
p.penup()
p.setpos(start_point)
p.pendown()
for i in range(n):
radian = 2 * math.pi / n
theta = (i + 1) * radian
next_point = (a * math.cos(theta) * math.cos(alpha) - b * math.sin(theta) * math.sin(alpha) + right,
a * math.cos(theta) * math.sin(alpha) + b * math.sin(theta) * math.cos(alpha) + up)
p.setpos(next_point)
new_ellipse(150, 60, right=1, up=1, alpha=150)
p.hideturtle()
turtle.mainloop()
椭圆1
仅仅以幕布为中心 仅可修改a b
import turtle, math
p = turtle.Turtle()
def ellipse(a, b, n=500):
"""
绘制椭圆函数
:param a: 长半轴长度
:param b: 短半轴长度
:param n: 边的数目 -- n越大,越趋近于椭圆
:return:
"""
p.penup()
p.setpos(a, 0)
p.pendown()
for i in range(n):
radian = 2 * math.pi / n
theta = (i+1)*radian
next_point = (a*math.cos(theta), b*math.sin(theta))
p.setpos(next_point)
ellipse(100, 50)
p.hideturtle()
turtle.mainloop()
椭圆
可修改位置和角度
import turtle, math
p = turtle.Turtle()
def new_ellipse(a, b, n=500, right=0, up=0, alpha=360):
"""
将椭圆旋转和左右移动
:param a:长半轴长度
:param b:短半轴长度
:param n:边的数目 -- n越大,越趋近于椭圆
:param right:椭圆往右移动的距离 -- 大于0:实际往右移动,小于0:实际往左移动
:param up:椭圆往上移动的距离 -- 大于0:实际往上移动,小于0:实际往下移动
:param alpha:椭圆旋转的角度
:return:
"""
alpha = (2*math.pi/360)*alpha
theta = 0
start_point = (a * math.cos(theta)*math.cos(alpha) - b * math.sin(theta)*math.sin(alpha) + right,
a * math.cos(theta)*math.sin(alpha) + b * math.sin(theta)*math.cos(alpha) + up)
p.penup()
p.setpos(start_point)
p.pendown()
for i in range(n):
radian = 2 * math.pi / n
theta = (i + 1) * radian
next_point = (a * math.cos(theta)*math.cos(alpha) - b * math.sin(theta)*math.sin(alpha) + right,
a * math.cos(theta)*math.sin(alpha) + b * math.sin(theta)*math.cos(alpha) + up)
p.setpos(next_point)
new_ellipse(100, 50, right=100, up=100)
p.hideturtle()
turtle.mainloop()
|