在线时间120 小时
UID3332856
注册时间2016-11-28
NXP金币60
TA的每日心情 | 擦汗 2024-11-7 09:48 |
|---|
签到天数: 1 天 连续签到: 1 天 [LV.1]初来乍到
金牌会员
 
- 积分
- 1377
- 最后登录
- 2026-4-4
|
发表于 2026-2-11 18:22:06
|
显示全部楼层
我参与马年代码
效果还好,不过有些抽象。这个是独角兽小马吗
- import turtle
- # 设置绘图窗口
- screen = turtle.Screen()
- screen.title("马年小马图案")
- screen.bgcolor("#f8f9fa")
- # 创建画笔
- pony = turtle.Turtle()
- pony.speed(3) # 绘图速度(1最慢,10最快)
- pony.pensize(2)
- # 定义颜色
- body_color = "#8B4513" # 棕色(身体)
- face_color = "#F5DEB3" # 小麦色(脸部)
- eye_color = "black" # 黑色(眼睛)
- nose_color = "#CD853F" # 秘鲁色(鼻子)
- # 绘制小马头部
- def draw_head():
- pony.penup()
- pony.goto(0, 50)
- pony.pendown()
- pony.fillcolor(face_color)
- pony.begin_fill()
- # 头部轮廓
- pony.circle(50)
- pony.end_fill()
- # 绘制小马耳朵
- def draw_ears():
- # 左耳
- pony.penup()
- pony.goto(-40, 90)
- pony.pendown()
- pony.fillcolor(body_color)
- pony.begin_fill()
- pony.goto(-60, 120)
- pony.goto(-30, 100)
- pony.goto(-40, 90)
- pony.end_fill()
- # 右耳
- pony.penup()
- pony.goto(40, 90)
- pony.pendown()
- pony.begin_fill()
- pony.goto(60, 120)
- pony.goto(30, 100)
- pony.goto(40, 90)
- pony.end_fill()
- # 绘制小马眼睛
- def draw_eyes():
- # 左眼
- pony.penup()
- pony.goto(-20, 70)
- pony.pendown()
- pony.fillcolor(eye_color)
- pony.begin_fill()
- pony.circle(5)
- pony.end_fill()
- # 右眼
- pony.penup()
- pony.goto(20, 70)
- pony.pendown()
- pony.begin_fill()
- pony.circle(5)
- pony.end_fill()
- # 绘制小马鼻子
- def draw_nose():
- pony.penup()
- pony.goto(0, 40)
- pony.pendown()
- pony.fillcolor(nose_color)
- pony.begin_fill()
- pony.circle(10)
- pony.end_fill()
- # 绘制小马身体
- def draw_body():
- pony.penup()
- pony.goto(0, 0)
- pony.pendown()
- pony.fillcolor(body_color)
- pony.begin_fill()
- # 身体轮廓(椭圆)
- pony.goto(80, -20)
- pony.goto(100, -60)
- pony.goto(60, -100)
- pony.goto(-60, -100)
- pony.goto(-80, -60)
- pony.goto(-50, -20)
- pony.goto(0, 0)
- pony.end_fill()
- # 绘制小马腿
- def draw_legs():
- # 左前腿
- pony.penup()
- pony.goto(-30, -100)
- pony.pendown()
- pony.goto(-30, -150)
- # 右前腿
- pony.penup()
- pony.goto(30, -100)
- pony.pendown()
- pony.goto(30, -150)
- # 左后腿
- pony.penup()
- pony.goto(-60, -100)
- pony.pendown()
- pony.goto(-60, -140)
- # 右后腿
- pony.penup()
- pony.goto(60, -100)
- pony.pendown()
- pony.goto(60, -140)
- # 绘制小马尾巴
- def draw_tail():
- pony.penup()
- pony.goto(-80, -60)
- pony.pendown()
- pony.fillcolor(body_color)
- pony.begin_fill()
- for i in range(5):
- pony.forward(20)
- pony.left(30)
- pony.end_fill()
- # 绘制小马鬃毛
- def draw_mane():
- pony.penup()
- pony.goto(-20, 100)
- pony.pendown()
- pony.fillcolor(body_color)
- pony.begin_fill()
- pony.goto(-40, 110)
- pony.goto(-10, 120)
- pony.goto(10, 115)
- pony.goto(30, 105)
- pony.goto(20, 95)
- pony.goto(-20, 100)
- pony.end_fill()
- # 绘制文字
- def draw_text():
- pony.penup()
- pony.goto(0, -180)
- pony.pendown()
- pony.color("red")
- pony.write("马年大吉 小马奔腾", align="center", font=("Arial", 16, "bold"))
- # 依次调用绘图函数
- draw_head()
- draw_ears()
- draw_eyes()
- draw_nose()
- draw_body()
- draw_legs()
- draw_tail()
- draw_mane()
- draw_text()
- # 隐藏画笔
- pony.hideturtle()
- # 保持窗口显示
- turtle.done()
复制代码
|
|