文章目录
- 系列文章
- 前言
- Turtle基础
- 1.1 Turtle画板
- 1.2 Turtle画笔
- 1.3 Turtle画图
- 1.4 Turtle填色
- 1.5 Turtle写字
- 五彩气球
- 气球类
- 漂浮函数
- 气球函数
- 六一祝福
- 完整代码
- 尾声
系列文章
序号 | 文章目录 | 直达链接 | |
表白系列 | |||
1 | 无法拒绝的表白界面 | https://want595.blog.csdn.net/article/details/134744894 | |
2 | 满屏飘字表白代码 | https://want595.blog.csdn.net/article/details/135037388 | |
3 | 无限弹窗表白代码 | https://want595.blog.csdn.net/article/details/134744711 | |
4 | 李峋同款可写字版跳动的爱心 | https://want595.blog.csdn.net/article/details/134744191 | |
5 | 流星雨 | https://want595.blog.csdn.net/article/details/134747408 | |
6 | 漂浮爱心 | https://want595.blog.csdn.net/article/details/134744929 | |
7 | 爱心光波 | https://want595.blog.csdn.net/article/details/134747365 | |
8 | 玫瑰花 | https://want595.blog.csdn.net/article/details/134747447 | |
节日系列 | |||
1 | 新春/跨年 | 烟花秀(2022) | https://want595.blog.csdn.net/article/details/128727394 |
烟花秀(2023) | https://want595.blog.csdn.net/article/details/135042880 | ||
粒子烟花 | https://want595.blog.csdn.net/article/details/136029420 | ||
2 | 圣诞节 | 圣诞礼物 | https://want595.blog.csdn.net/article/details/135336583 |
圣诞树(2022) | https://want595.blog.csdn.net/article/details/128428985 | ||
绿色圣诞树(2023) | https://want595.blog.csdn.net/article/details/135048607 | ||
粉色圣诞树(2023) | https://want595.blog.csdn.net/article/details/135043042 | ||
3 | 冬至 | 大雪纷飞 | https://want595.blog.csdn.net/article/details/128806017 |
4 | 生日 | 生日蛋糕 | https://want595.blog.csdn.net/article/details/128739755 |
5 | 儿童节 | 五彩气球 | https://want595.blog.csdn.net/article/details/128741043 |
6 | 国庆节 | 国庆祝福 | https://want595.blog.csdn.net/article/details/128740923 |
7 | 万圣节 | 万圣礼物 | https://want595.blog.csdn.net/article/details/128734395 |
8 | 愚人节 | 愚人代码 | https://want595.blog.csdn.net/article/details/128696990 |
9 | 中秋节 | 浪漫星空 | https://want595.blog.csdn.net/article/details/128737284 |
10 | 植树节 | 樱花树 | https://want595.blog.csdn.net/article/details/128700178 |
动漫系列 | |||
1 | 名侦探柯南系列 | 柯南 | https://want595.blog.csdn.net/article/details/134777613 |
2 | 喜羊羊与灰太狼系列 | 喜羊羊 | https://want595.blog.csdn.net/article/details/134778583 |
懒羊羊 | https://want595.blog.csdn.net/article/details/134847642 | ||
灰太狼 | https://want595.blog.csdn.net/article/details/135335303 | ||
小灰灰 | https://want595.blog.csdn.net/article/details/135335445 | ||
小香香 | https://want595.blog.csdn.net/article/details/135056783 | ||
3 | 海绵宝宝系列 | 海绵宝宝 | https://want595.blog.csdn.net/article/details/134847364 |
4 | 哆啦A梦系列 | 哆啦A梦 | https://want595.blog.csdn.net/article/details/135037884 |
5 | HelloKitty系列 | hellokitty | https://want595.blog.csdn.net/article/details/135337732 |
6 | Tom&Jerry系列 | Tom&Jerry | https://want595.blog.csdn.net/article/details/135337775 |
7 | 草莓熊系列 | 草莓熊 | https://want595.blog.csdn.net/article/details/135337832 |
8 | 皮卡丘系列 | 迷你皮卡丘 | https://want595.blog.csdn.net/article/details/135337911 |
高级皮卡丘 | https://want595.blog.csdn.net/article/details/135337937 | ||
豪华皮卡丘 | https://want595.blog.csdn.net/article/details/135337947 | ||
炫酷系列 | |||
1 | 一闪一闪亮星星系列 | 张万森下雪了 | https://want595.blog.csdn.net/article/details/135336915 |
一闪一闪亮星星 | https://want595.blog.csdn.net/article/details/135337049 | ||
2 | 代码雨 | https://want595.blog.csdn.net/article/details/135054341 | |
3 | 七彩花朵 | https://want595.blog.csdn.net/article/details/135056670 | |
4 | 3D星空 | https://want595.blog.csdn.net/article/details/135056516 | |
5 | 金榜题名 | https://want595.blog.csdn.net/article/details/135056150 | |
6 | 满天星 | https://want595.blog.csdn.net/article/details/135056305 | |
…… |
前言
六一要来啦,快来领取博主精心准备的五彩气球吧!
Turtle基础
小海龟(Turtle)是Python中画图的一个重要的包(内置包),里面包含丰富的画图工具以及画图的各种功能,当你学会了用Turtle画图后,你可以画任何你想画的图案哦
1.1 Turtle画板
Turtle的画板大小可以用turtle.setup()函数来设置
turtle.setup(width,height):设置画板的大小,包括宽和高,width为宽,height为高
1.2 Turtle画笔
Turtle的画笔有几个常用的函数
①turtle.penup():抬起画笔,此时移动画笔不会在画布上留下痕迹哦
②turtle.pendown():放下画笔,与turtle.penup相对应,放下画笔后就可以继续画画了(放下画笔后画画会在画布上留下痕迹)
③turtle.pensize():控制画笔的大小(可以根据需求自行定义画笔的大小哦)
④turtle.pencolor():控制画笔的颜色(可以自己在网上查阅所有python可以使用的颜色,python里面可以用的颜色有很多的哦)
⑤turtle.hideturtle():隐藏画笔(隐藏画笔以后画图时画笔就看不到了)
1.3 Turtle画图
在画图的过程中,我们经常要使用一些简单的移动函数
①turtle.forward(x):将画笔向前移动x个像素(x可以理解为距离)
②turtle.backward(x):将画笔向后退x个像素(x可以理解为距离)
③turtle.left(n):将画笔向左旋转n度
④turtle.right(n):将画笔向右旋转n度
⑤turtle.speed():设置画笔画图的速度(1~10递增,0最快)
1.4 Turtle填色
在画好图后,我们经常需要对其进行填色,这里可以用turtle.fillcolor()函数,括号里写入你想填充的颜色即可。
在使用turtle.fillcolor()函数要注意其基本格式
turtle.beginfill() #开始填充
turtle.fillcolor() #输入填充的颜色
turtle.endfill() #结束填充
1.5 Turtle写字
在完成整个画图后,我们可以使用turtle.write()函数进行写字
turtle.write(” “,move,align,font)
① 第一个位置双引号内填入要写的字
② move(可选):在默认情况下,move为false。如果move为true,则笔将移动到右下角
③ align(可选):可取值是left即左、center即中、right即右之一,是字符串格式
④ font(可选):字体三元组(fontname、fontsize、fonttype),fontname即字体名称(字符串格式,如“宋体”),fontsize即字体大小),fonttype即字体类型如:normal(普通)、bold(粗体)、italic(斜体)
五彩气球
气球类
class Balloon():#每个气球(气球类)def __init__(self):self.r = ra.randint(12,20)#气球的半径self.x = ra.randint(-1000,1000) #气球的横坐标self.y = ra.randint(-500,500) #气球的纵坐标self.f = ra.uniform(-3.14,3.14) #气球左右移动呈正弦函数self.speed = ra.randint(5,10) #气球移动速度self.color = ra.choice(colors)#气球的颜色self.outline = 1#气球的外框大小(可不要)
漂浮函数
def move(self):#气球移动函数if self.y <= 500:#当气球还在画布中时self.y += self.speed #设置上下移动速度self.x += self.speed * math.sin(self.f)#设置左右移动速度self.f += 0.1#可以理解成标志,改变左右移动的方向else:#当气球漂出了画布时,重新生成一个气球self.r = ra.randint(12,20)self.x = ra.randint(-1000,1000)self.y = -500self.f = ra.uniform(-3.14,3.14)self.speed = ra.randint(5,10)self.color = ra.choice(colors)self.outline = 1
气球函数
def draw(self): #画气球函数,就是用turtle画气球t.penup()t.goto(self.x,self.y)t.pendown()t.color(self.color)t.left(45)t.begin_fill()t.fillcolor(self.color)for i in range(2):t.circle(self.r*2, 90)t.circle(self.r, 90)t.end_fill()t.hideturtle()t.circle(self.r,-45)t.right(90)t.circle(20,90)
六一祝福
tu.penup()#写祝福tu.goto(-250,20)tu.pendown()tu.color("skyblue")tu.write("六一快乐!",font=("黑体", 80,"italic"))#"italic"表示斜体tu.hideturtle()
完整代码
https://want595.blog.csdn.net/article/details/128741043
尾声
六一快乐吖!