文章目录

  • 系列文章
  • 前言
    • 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
5HelloKitty系列hellokittyhttps://want595.blog.csdn.net/article/details/135337732
6Tom&Jerry系列Tom&Jerryhttps://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
43D星空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

尾声

六一快乐吖!