20211321 李心怡《Python程序设计》实验四 Python综合实践实验报告

课程 《python程序设计》
班级 2113
姓名 李心怡
学号 20211321
实验教师 王志强
实验日期 2021/5/28
必修/选修 公选课

Python海龟库的使用

使用python画了一个倒立的小鸟

开始是因为觉得微信表情包里的小鸟很可爱,在听到有python 大作业,了解到有Python海龟库画图之后,决定用Python编出一个小鸟的图案(虽然不是很像哈哈哈哈)

自己的图画

附上代码


import turtle as t
t.setup(800, 850)

t.speed(0)#速度

#地板
t.penup()
t.goto(-250, -200)
t.pencolor("black")
t.pensize(3)
t.pendown()
t.setheading(0)
t.forward(500)


#身子
t.penup()
t.goto(116, -168)
t.pensize(2)
t.fillcolor("gold")
t.begin_fill()
t.pendown()
t.setheading(40)
t.circle(250, 120)
t.circle(200, 30)
t.circle(235,150)
t.end_fill()


#脑袋
t.penup()
t.goto(135, -200)
t.pencolor("black")
t.fillcolor("gold")
t.pensize(2)
t.begin_fill()
t.pendown()
t.setheading(90)
t.circle(100, 40)
t.circle(150, 100)
t.circle(100, 40)
t.end_fill()

#左眼
t.penup()
t.goto(-90, -168)
t.pencolor("black")
t.fillcolor("white")
t.pensize(1)
t.begin_fill()
t.pendown()
t.circle(32,360)
t.end_fill()

#右眼
t.penup()
t.goto(26, -168)
t.pencolor("black")
t.fillcolor("white")
t.pensize(1)
t.begin_fill()
t.pendown()
t.circle(32, 360)
t.end_fill()


#左眼珠
t.penup()
t.goto(-80, -168)
t.pencolor("black")
t.fillcolor("black")
t.pensize(1)
t.begin_fill()
t.pendown()
t.circle(22, 360)
t.end_fill()

#右眼珠

t.penup()
t.goto(36, -168)
t.pencolor("black")
t.fillcolor("black")
t.pensize(1)
t.begin_fill()
t.pendown()
t.circle(22, 360)
t.end_fill()


#下嘴
t.penup()
t.goto(-27, -140)
t.pensize(3)
t.fillcolor("saddle brown")
t.begin_fill()
t.pendown()
t.setheading(285)
t.forward(100)
t.setheading(77)
t.forward(100)
t.end_fill()

#嘴
t.penup()
t.goto(0, -110)
t.pencolor("black")
t.pensize(3)
t.fillcolor("saddle brown")
t.begin_fill()
t.pendown()
t.setheading(-50)
t.forward(40)
t.setheading(230)
t.forward(40)
t.setheading(130)
t.forward(40)
t.setheading(50)
t.forward(40)
t.end_fill()


#尾巴
t.penup()
t.goto(-45, 180)
t.pensize(3)
t.fillcolor("DarkOrange3")
t.begin_fill()
t.pendown()
t.setheading(60)
t.forward(270)
t.setheading(263)
t.forward(250)
t.end_fill()


#肚饥
t.penup()
t.goto(-50, 180)
t.pendown()
t.setheading(20)
t.circle(-75, 70)

#肚子上的叉叉
t.penup()
t.pensize(3)
t.goto(10, 165)
t.pendown()
t.setheading(-130)
t.circle(-35, 80)
t.penup()
t.goto(-20, 175)
t.setheading(-75)
t.pendown()
t.circle(35, 80)


#左腿
t.penup()
t.fillcolor("gold")
t.begin_fill()
t.goto(-70, -75)
t.pendown()
t.goto(-75, -90)
t.penup()
t.goto(-85, -85)
t.pendown()
t.goto(-80, -90)
t.goto(-63, -100)
t.pendown()
t.goto(-190, -200)
t.goto(-200, -110)
t.end_fill()

#右腿
t.penup()
t.fillcolor("gold")
t.begin_fill()
t.goto(100,-90)
t.pendown()
t.goto(140, -200)
t.goto(183,-75)
t.end_fill()

# 羽毛
t.penup()
t.fillcolor("gold")
t.begin_fill()
t.goto(-205, 180)
t.pendown()
t.setheading(-90)
t.circle(-200, 40)
t.goto(-220, 90)
t.setheading(60)
t.circle(-20, 180)
t.setheading(250)
t.circle(-200, 40)
t.setheading(20)
t.circle(-270, 20)
t.circle(-20, 120)
t.circle(-200, 20)
t.goto(-195, -155)

#左翅膀
t.penup()
t.goto(-205, 180)
t.pendown()
t.goto(-230, 230)
t.setheading(90)
t.circle(30,145)
t.circle(350, 30)
t.circle(220, 78)
t.goto(-195, -155)
t.end_fill()

#右翅膀
t.penup()
t.goto(150, 170)
t.fillcolor("gold")
t.begin_fill()
t.pendown()
t.goto(220, 240)
t.setheading(20)
t.circle(-30, 80)
t.setheading(-90)
t.circle(-200, 50)
t.setheading(40)
t.circle(-150, 35)
t.circle(-20, 110)
t.circle(-200, 45)
t.setheading(10)
t.circle(-200, 10)
t.circle(-15, 140)
t.circle(-200, 23)
t.end_fill()
t.setheading(60)
t.circle(250, 70)

# 脚
t.penup()
t.goto(-190, -200)
t.pendown()
t.goto(-240, -205)
t.penup()
t.goto(-190, -200)
t.pendown()
t.goto(-160, -203)
t.penup()
t.goto(140, -200)
t.pendown()
t.goto(180, -204)


t.mainloop()
t.down()

由于画得熟练了,就拿小猪佩奇再一次试手

小猪佩奇

附上代码

import turtle as t
t.pensize(4)
t.hideturtle()
t.colormode(255)
t.color((255, 155, 192), "pink")
t.setup(840, 500)
t.speed(20)
# 鼻子
t.pu()
t.goto(-100, 100)
t.pd()
t.seth(-30)
t.begin_fill()
a = 0.4
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()
t.pu()
t.seth(90)
t.fd(25)
t.seth(0)
t.fd(10)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
t.pu()
t.seth(0)
t.fd(20)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
# 头
t.color((255, 155, 192), "pink")
t.pu()
t.seth(90)
t.fd(41)
t.seth(0)
t.fd(0)
t.pd()
t.begin_fill()
t.seth(180)
t.circle(300, -30)
t.circle(100, -60)
t.circle(80, -100)
t.circle(150, -20)
t.circle(60, -95)
t.seth(161)
t.circle(-300, 15)
t.pu()
t.goto(-100, 100)
t.pd()
t.seth(-30)
a = 0.4
for i in range(60):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()
# 耳朵
t.color((255, 155, 192), "pink")
t.pu()
t.seth(90)
t.fd(-7)
t.seth(0)
t.fd(70)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50, 50)
t.circle(-10, 120)
t.circle(-50, 54)
t.end_fill()
t.pu()
t.seth(90)
t.fd(-12)
t.seth(0)
t.fd(30)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50, 50)
t.circle(-10, 120)
t.circle(-50, 56)
t.end_fill()
# 眼睛
t.color((255, 155, 192), "white")
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-95)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
t.color((255, 155, 192), "white")
t.pu()
t.seth(90)
t.fd(-25)
t.seth(0)
t.fd(40)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
# 腮
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(-95)
t.seth(0)
t.fd(65)
t.pd()
t.begin_fill()
t.circle(30)
t.end_fill()
# 嘴
t.color(239, 69, 19)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(-100)
t.pd()
t.seth(-80)
t.circle(30, 40)
t.circle(40, 80)
# 身体
t.color("red", (255, 99, 71))
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-78)
t.pd()
t.begin_fill()
t.seth(-130)
t.circle(100, 10)
t.circle(300, 30)
t.seth(0)
t.fd(230)
t.seth(90)
t.circle(300, 30)
t.circle(100, 3)
t.color((255, 155, 192), (255, 100, 100))
t.seth(-135)
t.circle(-80, 63)
t.circle(-150, 24)
t.end_fill()
# 手
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(-40)
t.seth(0)
t.fd(-27)
t.pd()
t.seth(-160)
t.circle(300, 15)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-10)
t.circle(-20, 90)
t.pu()
t.seth(90)
t.fd(30)
t.seth(0)
t.fd(237)
t.pd()
t.seth(-20)
t.circle(-300, 15)
t.pu()
t.seth(90)
t.fd(20)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-170)
t.circle(20, 90)
# 脚
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(-75)
t.seth(0)
t.fd(-180)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(40)
t.seth(0)
t.fd(90)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
# 尾巴
t.pensize(4)
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(70)
t.seth(0)
t.fd(95)
t.pd()
t.seth(0)
t.circle(70, 20)
t.circle(10, 330)
t.circle(70, 30)
t.exitonclick()

本次的实验总结

  • 实验所学习的函数:

(1)画笔运动命令:
turtle. forward(distance):向当前画笔方向移动distance像素长
turtle. backward(distance):向当前画笔相反方向移动distance像素长度
turtle. right(degree):顺时针移动degree"
turtle. left(degree):逆时针移动degree"
turtle. pendown():移动时绘制图形,缺省时也为绘制
turtle. goto(x,y):将画笔移动到坐标为x,y的位置
turtle. penup[b:移动时不绘制图形,提起笔,用于另起一个地方绘制时用
turtle. speed(speed):画笔绘制的速度范围[0,10]整数
turtle. circle():画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆
setx():将当前x轴移动到指定位置
sety():将当前y轴移动到指定位置
setheading (angle):设置当前朝向为angle角度
home():设置当前画笔位置为原点,朝向东。

(2)画笔控制命令:
turtle. pensize(width):绘制图形时的宽度
turtle. pencolor():画笔颜色
turtle:fillcolor( colorstring ):绘制图形的填充颜色
turtle color(color),color 2):同时设置pencolor=color 1,fillColor=color2
turtle,filling():返回当前是否在填充状态
turtle. begin fill():准备开始填充图形
turtle. end fill():填充完成;
turtle.  hideturtle ():隐藏箭头显示;
turtle.  showturtle ():与 hideturtle ()函数对应

(3)全局控制命令
turtle. clear()清空turtle窗口,但是turtle的位置和状态不会改变
turtle. reset()清空窗口,重置turtle状态为起始状态
turtle. undo()撤销上一个turtle动作
turtle. isvisible()返回当前turtle是否可见,
stamp()复制当前图形

实验分析

  • 实验分析:
    本实验使用了python 的库turtle,。
  • 设计:
    开始看到用python可以实现画画, 便想要自己实践一下。看到微信上的表情包很可爱,便想通过python 实现绘画表情包。
  • 实现过程:
    我先在网上搜索了Python的turtle库的用法。了解到它有turtle.fillcolor, turtle.circle()等用法,便开始着手开画。
  • 问题:
    • 找点很困难。
      每一次在电脑上找点是一件困难的事,我便先手动画下这图案,然后再在电脑上去找点。找点的时候也是找不到自己想要的点,后来通过查找发现原点在正中央。
    • 线条很单一。
      python画图只有直线和圆这两个图案,如何画出椭圆和其它的圆滑的线条呢?通过网上查找,我发现可以使用多个不同半径的圆连在一起来实现画出椭圆,在直线的末端使用圆便可以画出光滑的曲线。
    • 填充色彩会出线条。
      当我用不同颜色的时候,有时候便会出现颜色填充很溢出的现象。我通过两个多小时的实验,终于弄明白了,当有圆存在的时候,便是填充圆的圆心那一半的颜色。如果自己的图案没有封闭,颜色填充变会溢出。解决办法便是将始末的点都设为一个。

通过我的艰难努力,终于实现了第一个倒立的鸟的简化版。想要使我的python绘画技术熟练,我又画了一个小猪佩奇。

python 课程的知识点总结




课程体会和建议

因为上学期在娄老师的课上,我曾对python有一定的了解,这次的选修课让我对它有更加深切的感悟。老师拓展了我们的知识面,不仅让我们学习python,还让我们了解了正则表达式;老师的课上实践对我们帮助也很大,给我们当场用python演示算术运算。要真切了解一门语言,不仅要了解它的语法,更要在实践中应用才能更加得心应手;老师在也让我们了解了很多python的实际应用,比如监听技术,数据可视化等,使我们学习的python有了更多的用武之地。王老师的课极大地激发了我学习python 的兴趣,python 的多样化应用也让我对它更为着迷。

课程建议: 老师可以把上课的ppt发放到群里,让没有听懂的同学下课后可以继续看看,加深对python 的理解。

最后,谢谢老师深博的知识对我影响和老师对我学习中的问题耐心的回答!!!

posted @ 2022-05-29 18:28  风雾里  阅读(143)  评论(0编辑  收藏  举报