0
点赞
收藏
分享

微信扫一扫

windows10下 iperf3测试带宽

泠之屋 2023-10-12 阅读 15

910e86d390fe458c9084472db3e1df34.png

系列文章

序号文章目录直达链接
1浪漫520表白代码https://want595.blog.csdn.net/article/details/130666881
2满屏表白代码https://want595.blog.csdn.net/article/details/129794518
3跳动的爱心https://want595.blog.csdn.net/article/details/129503123
4漂浮爱心https://want595.blog.csdn.net/article/details/128808630
5爱心光波https://want595.blog.csdn.net/article/details/132311588
6流星雨https://want595.blog.csdn.net/article/details/129395465
7满天星https://want595.blog.csdn.net/article/details/129572082
8烟花秀https://want595.blog.csdn.net/article/details/128746664
9圣诞树https://want595.blog.csdn.net/article/details/128213770
10雪花代码https://want595.blog.csdn.net/article/details/129038108
11模拟星空https://want595.blog.csdn.net/article/details/129948882
12生日蛋糕https://want595.blog.csdn.net/article/details/129694998
13樱花树https://want595.blog.csdn.net/article/details/130350743
14五彩气球https://want595.blog.csdn.net/article/details/130950744
15七彩花朵https://want595.blog.csdn.net/article/details/130897838
16恶搞代码https://want595.blog.csdn.net/article/details/131274862
17代码雨https://want595.blog.csdn.net/article/details/132574687
18中秋星空https://want595.blog.csdn.net/article/details/132910075
19国庆祝福https://want595.blog.csdn.net/article/details/133427031

前言

用python实现三只爱心宝可梦! 

小海龟

Python中的turtle是一个简单易用的绘图库,它可以让我们通过编程的方式画出各种各样的图形。它内部实现了一个海龟(turtle),我们可以通过控制海龟的移动方向和长度等参数来进行绘图,非常适合初学者入门使用。本文将介绍turtle的基本绘图函数和实例,帮助初学者快速入门。

1.安装turtle

turtle是Python自带的标准库,所以我们不需要安装任何东西,只需要在Python终端或者编辑器上导入turtle库即可开始使用。

import turtle

2.turtle的基本绘图函数

turtle的基本绘图函数有很多,下面是一些常用的函数:

  • turtle.forward(distance):向当前方向移动指定距离的海龟。
  • turtle.backward(distance):向相反方向移动指定距离的海龟。
  • turtle.right(angle):将当前方向向右旋转指定角度。
  • turtle.left(angle):将当前方向向左旋转指定角度。
  • turtle.penup():将画笔抬起,不再画出海龟的轨迹。
  • turtle.pendown():将画笔放下,继续画出海龟的轨迹。
  • turtle.pensize(width):设置画笔的宽度为指定大小。
  • turtle.pencolor(color):设置画笔的颜色为指定颜色。
  • turtle.fillcolor(color):设置填充的颜色为指定颜色。
  • turtle.begin_fill():开始填充。
  • turtle.end_fill():结束填充。
  • turtle.circle(radius):绘制一个指定半径的圆形。

3.turtle的实例

下面是一些turtle的实例,帮助我们更好地理解上面的基本绘图函数。

3.1 简单的绘图

我们先来画一个简单的图形,让海龟向前移动100个像素,然后向左旋转90度,再向前移动100个像素,最后向左旋转90度,形成一个正方形图形。

import turtle

turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)

turtle.done()   # 表示绘图结束

3.2 绘制彩色螺旋图形

下面我们来绘制一个彩色的螺旋图形,让海龟不断向前移动并旋转,每次旋转的角度和颜色都不同,最终形成一个美丽的螺旋图形。
 

import turtle

turtle.speed(10)
for i in range(200):
    turtle.forward(i)
    turtle.right(98)
    turtle.pencolor('red')
    turtle.pencolor('orange')
    turtle.pencolor('yellow')
    turtle.pencolor('green')
    turtle.pencolor('cyan')
    turtle.pencolor('blue')
    turtle.pencolor('purple')

turtle.done()

3.3 绘制五角星

下面我们来绘制一个五角星,让海龟向前移动100个像素,向左旋转72度,重复5次,即可形成一个五角星。
 

import turtle

turtle.pensize(5)
turtle.pencolor('purple')
turtle.fillcolor('yellow')
turtle.begin_fill()

for i in range(5):
    turtle.forward(100)
    turtle.right(72)
    turtle.forward(100)
    turtle.left(144)

turtle.end_fill()
turtle.done()

3.4 绘制圆形和正方形

下面我们来绘制一个圆形和一个正方形,先绘制一个圆形,然后以圆心为起点,绘制出正方形。

import turtle

turtle.circle(50)   # 画一个圆形

turtle.penup()  # 将画笔抬起
turtle.goto(0, -50)  # 将海龟移动到圆心下面的位置
turtle.pendown()   # 将画笔放下

for i in range(4):
    turtle.forward(100)
    turtle.left(90)

turtle.done()

通过上述实例,我们可以看到,turtle库非常适合初学者入门使用,其简单易用的接口和实时绘图的效果,可以让我们快速地理解和掌握Python编程的基本思路和方法。

皮卡丘

迷你版

623bc76cd3fb4819956d7e4f681c2b8a.png

程序设计

import turtle as t
import time
# 基础设置
t.setup(500, 500) # 设置画布大小
t.bgcolor("pink")
t.title("pikachu")
t.pensize(1) # 设置画笔的大小
# 画左偏曲线函数
def left(ang, dis, step, n):
for i in range(n):
dis += step # dis增大step
t.lt(ang) # 向左转ang度
t.fd(dis) # 向前走dis的步长
def right(ang, dis, step, n):
for i in range(n):
dis += step
t.rt(ang) # 向左转ang度
t.fd(dis) # 向前走dis的步长
# 画耳朵
def Ears():
t.color("black", "yellow")
# 左耳朵曲线
t.pu() # 提笔
t.goto(-50, 100) # 笔头初始位置
t.pd() # 下笔
t.setheading(110) # 画笔角度
t.begin_fill()
left(1.2, 0.4, 0.1, 40)
t.setheading(270) # 画笔角度
left(1.2, 0.4, 0.1, 40)
t.setheading(44) # 画笔角度
t.forward(32)
t.end_fill()
# 右耳朵曲线
t.pu() # 提笔
t.goto(50, 100) # 笔头初始位置
t.pd() # 下笔
t.setheading(70) # 画笔角度
t.begin_fill()
right(1.2, 0.4, 0.1, 40)
t.setheading(270) # 画笔角度
right(1.2, 0.4, 0.1, 40)
t.setheading(136) # 画笔角度
t.forward(32)
t.end_fill()
# 耳朵黑
t.begin_fill()
t.fillcolor("black")
t.pu() # 提笔
t.goto(88, 141) # 笔头初始位置
t.pd() # 下笔
t.setheading(35) # 画笔角度
right(1.2, 1.6, 0.1, 16)
t.setheading(270) # 画笔角度
right(1.2, 0.4, 0.1, 25)
t.setheading(132) # 画笔角度
t.forward(31)
t.end_fill()
t.begin_fill()
t.fillcolor("black")
t.pu() # 提笔
t.goto(-88, 141) # 笔头初始位置
t.pd() # 下笔
t.setheading(145) # 画笔角度
left(1.2, 1.6, 0.1, 16)
t.setheading(270) # 画笔角度
left(1.2, 0.4, 0.1, 25)
t.setheading(48) # 画笔角度
t.forward(31)
t.end_fill()
# 画尾巴
def Tail():
# 尾巴
t.begin_fill()
t.fillcolor("yellow")
t.pu() # 提笔
t.goto(64, -140) # 笔头初始位置
t.pd() # 下笔
t.setheading(10) # 画笔角度
t.forward(20)
t.setheading(90) # 画笔角度
t.forward(20)
t.setheading(10) # 画笔角度
t.forward(10)
t.setheading(80) # 画笔角度
t.forward(100)
t.setheading(35) # 画笔角度
t.forward(80)
t.setheading(260) # 画笔角度
t.forward(100)
t.setheading(205) # 画笔角度
t.forward(40)
t.setheading(260) # 画笔角度
t.forward(37)
t.setheading(205) # 画笔角度
t.forward(20)
t.setheading(260) # 画笔角度
t.forward(25)
t.setheading(175) # 画笔角度
t.forward(30)
t.setheading(100) # 画笔角度
t.forward(13)
t.end_fill()
# 画脚
def Foots():
# 脚
t.begin_fill()
t.fillcolor("yellow")
t.pensize(2)
t.pu() # 提笔
t.goto(-70, -200) # 笔头初始位置
t.pd() # 下笔
t.setheading(225) # 画笔角度
left(0.5, 1.2, 0, 12)
left(35, 0.6, 0, 4)
left(1, 1.2, 0, 18)
t.setheading(160) # 画笔角度
t.forward(13)
t.end_fill()
t.begin_fill()
t.fillcolor("yellow")
t.pensize(2)
t.pu() # 提笔
t.goto(70, -200) # 笔头初始位置
t.pd() # 下笔
t.setheading(315) # 画笔角度
right(0.5, 1.2, 0, 12)
right(35, 0.6, 0, 4)
right(1, 1.2, 0, 18)
t.setheading(20) # 画笔角度
t.forward(13)
t.end_fill()
# 画身体
def Body():
# 外形轮廓
t.begin_fill()
t.pu() # 提笔
t.goto(112, 0) # 笔头初始位置
t.pd() # 下笔
t.setheading(90) # 画笔角度
t.circle(112, 180)
t.setheading(250) # 画笔角度
left(1.6, 1.3, 0, 50)
left(0.8, 1.5, 0, 25)
t.setheading(255) # 画笔角度
left(0.4, 1.6, 0.2, 27)
left(2.8, 1, 0, 45)
right(0.9, 1.4, 0, 31)
t.setheading(355) # 画笔角度
right(0.9, 1.4, 0, 31)
left(2.8, 1, 0, 45)
left(0.4, 7.2, -0.2, 27)
t.setheading(10) # 画笔角度
left(0.8, 1.5, 0, 25)
left(1.6, 1.3, 0, 50)
t.end_fill()
def Eyes_Open():
# 左眼睛
t.begin_fill()
t.fillcolor("black")
t.pu() # 提笔
t.goto(-46, 10) # 笔头初始位置
t.pd() # 下笔
t.setheading(90) # 画笔角度
t.circle(5, 360)
t.end_fill()
# 右眼睛
t.begin_fill()
t.fillcolor("black")
t.pu() # 提笔
t.goto(46, 10) # 笔头初始位置
t.pd() # 下笔
t.setheading(-90) # 画笔角度
t.circle(5, 360)
t.end_fill()
# 画脸
def Face():
# 脸蛋
t.begin_fill()
t.fillcolor("red")
t.pu() # 提笔
t.goto(-63, -10) # 笔头初始位置
t.pd() # 下笔
t.setheading(90) # 画笔角度
t.circle(10, 360)
t.end_fill()
t.begin_fill()
t.fillcolor("red")
t.pu() # 提笔
t.goto(63, -10) # 笔头初始位置
t.pd() # 下笔
t.setheading(-90) # 画笔角度
t.circle(10, 360)
t.end_fill()
# 嘴巴
t.pensize(2.2)
t.pu() # 提笔
t.goto(0, 0) # 笔头初始位置
t.pd() # 下笔
t.setheading(235) # 画笔角度
right(5, 0.8, 0, 30)
t.pu() # 提笔
t.goto(0, 0) # 笔头初始位置
t.pd() # 下笔
t.setheading(305) # 画笔角度
left(5, 0.8, 0, 30)
# 画手
def Hands():
# 左手
t.pensize(2)
t.pu() # 提笔
t.goto(-46, -100) # 笔头初始位置
t.pd() # 下笔
t.setheading(285) # 画笔角度
right(0.4, 1.2, 0, 26)
right(5, 0.35, 0, 26)
right(0.3, 1.2, 0, 15)
# 右手
t.pu() # 提笔
t.goto(46, -100) # 笔头初始位置
t.pd() # 下笔
t.setheading(255) # 画笔角度
left(0.4, 1.2, 0, 26)
left(5, 0.35, 0, 26)
left(0.3, 1.2, 0, 15)
def Eyes_Close():
# 左眼睛
t.pu() # 提笔
t.goto(-46, 12) # 笔头初始位置
t.pd() # 下笔
t.setheading(180) # 画笔角度
t.forward(10)
# 右眼睛
t.pu() # 提笔
t.goto(46, 12) # 笔头初始位置
t.pd() # 下笔
t.setheading(0) # 画笔角度
t.forward(10)

# 爱心
def Love(): # 画爱心函数,就是用turtle画爱心
t.pensize(1)
t.penup()
t.color("pink")
t.goto(-2.5, -100)
t.pendown()
t.begin_fill()
t.fillcolor('pink')
t.setheading(120)
t.circle(20, 195)
t.fd(20 * 2.4)
t.lt(90)
t.fd(20 * 2.4)
t.circle(20, 195)
t.end_fill()

# 初始化
def Init():
Ears()
Tail()
Foots()
Body()
Face()
Hands()
Eyes_Open()
Love()
# 眨眼睛
def Close():
Ears()
Tail()
Foots()
Body()
Face()
Hands()
Eyes_Close()
def Open():
Ears()
Tail()
Foots()
Body()
Face()
Hands()
Eyes_Open()
Love()


def main():
# 初始化皮卡丘
Init()
# 眨眼睛动画
for i in range(30):
if i % 2 == 0:
t.reset()
t.hideturtle()
Close()
t.update()
time.sleep(0.3)
else:
t.reset()
t.hideturtle()
Open()
t.update()
time.sleep(1)
t.tracer(0)
main()
t.done()

程序分析

高级版

1e189bc767144e958c2b5f727ca18e89.png

程序设计

from turtle import *
import turtle as t

def infoPrt():
print('coordinate: ' + str(t.pos()))
print('angle: ' + str(t.heading()))

t.tracer(0)
t.pensize(3)
t.hideturtle()
t.colormode(255)
t.color("black")
t.setup(700, 650)
t.speed(1)
t.st()
#t.dot()
t.pu()
#t.goto(-150,100)
t.goto(-210,86)
t.pd()
infoPrt()
……(完整代码文末公众号免费获取哦)

程序分析

豪华版

15a6fddeb1324d8ab3c0f58df4ecefbf.png

程序设计

import turtle

turtle.setup(999, 777)
turtle.title('Pikachu')
pikachu = Pikachu()
pikachu.start()
turtle.penup()
turtle.goto(-444,200)
turtle.bgcolor("blue")
turtle.color("gold")
turtle.write("Pika !", move = True, align="left", font=("Comic Sans MS", 66, "bold"))
turtle.pensize(1)
turtle.penup()
turtle.color("skyblue")
turtle.goto(-2.5, -100)
turtle.pendown()
turtle.begin_fill()
turtle.fillcolor('skyblue')
turtle.setheading(120)
turtle.circle(30, 195)
turtle.fd(30 * 2.4)
turtle.lt(90)
turtle.fd(30 * 2.4)
turtle.circle(30, 195)
turtle.end_fill()
turtle.pendown()
turtle.mainloop()
……(完整代码文末公众号免费获取哦)

程序分析

尾声

感谢支持吖!

举报

相关推荐

0 条评论