你是小黑子吗?是就画一只鸡吧!(python)

本文通过turtle库展示了如何在Python中绘制一个包含篮球、脸蛋特征的图形,涉及椭圆函数、多边形和颜色填充等技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值