序号 | 文章目录 | 直达链接 | |
表白系列 | |||
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 | |
…… |
万圣节即将来临,快来领取博主给大家准备的礼物吧!
Python的小海龟(Turtle Graphics)是一个简单而有趣的绘图库,适合初学者入门学习编程。它允许你使用Python语言对图形进行绘制,通过简单的命令就能创造出各种有趣的图形。在本文中,我将为你提供一个关于Python小海龟绘图的入门简介。
小海龟绘图可以追溯到Logo语言,它是由Seymour Papert在20世纪60年代开发的。而在Python中,我们可以使用turtle库来实现类似的功能。
首先,我们需要在Python中导入turtle库。可以使用以下代码来实现:
import turtle
现在,我们可以创建一个海龟实例,并命名为my_turtle
:
my_turtle = turtle.Turtle()
海龟实例是一个图形窗口,你可以在其中绘制图形。它有一个默认的方向,朝向屏幕的右侧。
让我们来尝试一些基本的绘图操作。例如,绘制一个正方形,代码如下:
my_turtle.forward(100) my_turtle.right(90) my_turtle.forward(100) my_turtle.right(90) my_turtle.forward(100) my_turtle.right(90) my_turtle.forward(100)
在这个例子中,我们使用forward()
方法向前绘制一条直线,使用right()
方法向右转动一定角度。通过不断的重复这两个操作,我们可以绘制出一个正方形。
现在,我们尝试绘制一个更复杂的图形,比如一个五角星。代码如下:
for i in range(5): my_turtle.forward(100) my_turtle.right(144)
在这个例子中,我们使用for
循环来重复执行一系列操作。forward()
方法和right()
方法的参数可以根据你的需要调整,以实现想要的图形效果。
除了基本的直线和角度操作之外,turtle库还提供了其他一些功能,例如改变画笔的颜色、粗细、移动、填充等操作。你可以根据需要来探索这些功能。
最后,当你完成绘图后,记得使用以下代码来保持图形窗口打开,以便查看你的绘图结果:
turtle.done()
这是一个简单的Python小海龟绘图入门简介。通过掌握这些基本的概念和操作,你可以开始创造出各种有趣的图形和艺术作品。希望这篇简介对你有所帮助,祝你在学习Python小海龟绘图过程中取得成功!
让我们先从一只小蝙蝠开始吧!
程序设计
import turtle as t k = 0.5 t.title("蝙蝠") t.setup(0.5, 0.5) t.begin_fill() t.fillcolor('black') t.forward(k*10) t.setheading(75) t.forward(k*35) t.setheading(-75) t.forward(k*55) t.setheading(0) t.circle(k*40,90) t.right(90) t.forward(k*100) t.left(180) t.circle(k*100,90) t.setheading(180) t.circle(k*70,90) t.left(180) t.circle(k*70,90) t.right(90) t.circle(k*100,90) t.right(180) t.forward(k*100) t.right(90) t.circle(k*40,90) t.setheading(75) t.forward(k*55) t.setheading(-75) t.forward(k*35) t.setheading(0) t.forward(k*10) t.end_fill() t.mainloop()
程序分析
这段代码利用了turtle库,在画布上绘制了一个黑色的蝙蝠。下面是代码具体的分析:
import turtle as t
t.title("蝙蝠") t.setup(0.5, 0.5)
t.begin_fill() t.fillcolor('black')
t.forward(k*10) t.setheading(75) t.forward(k*35) t.setheading(-75) t.forward(k*55) t.setheading(0) t.circle(k*40,90)
t.right(90) t.forward(k*100) t.left(180) t.circle(k*100,90)
t.setheading(180) t.circle(k*70,90) t.left(180) t.circle(k*70,90)
t.right(90) t.circle(k*100,90)
t.right(180) t.forward(k*100) t.right(90) t.circle(k*40,90)
t.setheading(75) t.forward(k*55) t.setheading(-75) t.forward(k*35) t.setheading(0) t.forward(k*10)
t.end_fill() t.mainloop()
万圣节怎么能少的了南瓜头呢~
程序设计
import turtle def init(): turtle.setup(1.0,1.0) turtle.speed(10) turtle.hideturtle() turtle.bgcolor('orange') def outline(): turtle.color('#CF5E1A', '#CF5E1A') turtle.penup() turtle.goto(250, 30) turtle.pendown() turtle.seth(90) turtle.begin_fill() for j in range(25): turtle.fd(j) turtle.left(3.6) for j in range(25, 0, -1): turtle.fd(j) turtle.left(3.6) turtle.seth(-90) turtle.circle(254, 180) turtle.end_fill() def eyes(args): for items in args: position, angle, direction = items turtle.pensize(6) turtle.penup() turtle.goto(position, 0) turtle.pendown() turtle.color('#4C180D', '#4C180D') turtle.begin_fill() turtle.seth(angle) for j in range(55): turtle.fd(3) if direction: turtle.left(3) # 左转3度 else: turtle.right(3) # 右转3度 turtle.goto(position, 0) turtle.end_fill() def nose(): # 鼻子 turtle.penup() turtle.goto(0, 0) turtle.seth(180) turtle.pendown() turtle.begin_fill() turtle.circle(50, steps=3) turtle.end_fill() def mouth(): # 嘴巴 turtle.color('#F9D503', '#F9D503') turtle.pensize(6) turtle.penup() turtle.penup() turtle.goto(-150, -100) turtle.pendown() turtle.begin_fill() turtle.seth(-30) turtle.fd(100) turtle.left(90) turtle.fd(30) turtle.right(90) turtle.fd(60) turtle.left(60) turtle.fd(60) turtle.right(90) turtle.fd(30) turtle.left(90) turtle.fd(100) turtle.end_fill() turtle.done() def tail(): turtle.penup() turtle.goto(0, 180) turtle.pendown() turtle.color('#2E3C01') turtle.seth(100) turtle.pensize(25) turtle.circle(60, 100) turtle.tracer(0) init() outline() tail() eyes_items = [(-60, 230, 0), (60, -50, 1)] eyes(eyes_items) nose() mouth() turtle.done()
程序分析
这段代码是利用turtle库在画布上绘制了一个南瓜头。下面是代码具体的分析:
import turtle
def init(): turtle.setup(1.0,1.0) turtle.speed(10) turtle.hideturtle() turtle.bgcolor('orange')
def outline(): turtle.color('#CF5E1A', '#CF5E1A') turtle.penup() turtle.goto(250, 30) turtle.pendown() turtle.seth(90) turtle.begin_fill() for j in range(25): turtle.fd(j) turtle.left(3.6) for j in range(25, 0, -1): turtle.fd(j) turtle.left(3.6) turtle.seth(-90) turtle.circle(254, 180) turtle.end_fill()
def eyes(args): for items in args: position, angle, direction = items turtle.pensize(6) turtle.penup() turtle.goto(position, 0) turtle.pendown() turtle.color('#4C180D', '#4C180D') turtle.begin_fill() turtle.seth(angle) for j in range(55): turtle.fd(3) if direction: turtle.left(3) # 左转3度 else: turtle.right(3) # 右转3度 turtle.goto(position, 0) turtle.end_fill()
def nose(): turtle.penup() turtle.goto(0, 0) turtle.seth(180) turtle.pendown() turtle.begin_fill() turtle.circle(50, steps=3) turtle.end_fill()
def mouth(): turtle.color('#F9D503', '#F9D503') turtle.pensize(6) turtle.penup() turtle.penup() turtle.goto(-150, -100) turtle.pendown() turtle.begin_fill() turtle.seth(-30) turtle.fd(100) turtle.left(90) turtle.fd(30) turtle.right(90) turtle.fd(60) turtle.left(60) turtle.fd(60) turtle.right(90) turtle.fd(30) turtle.left(90) turtle.fd(100) turtle.end_fill() turtle.done()
def tail(): turtle.penup() turtle.goto(0, 180) turtle.pendown() turtle.color('#2E3C01') turtle.seth(100) turtle.pensize(25) turtle.circle(60, 100)
turtle.tracer(0) init() outline() tail() eyes_items = [(-60, 230, 0), (60, -50, 1)] eyes(eyes_items) nose() mouth() turtle.done()
让我们将蝙蝠和南瓜头结合一下吧!
程序设计
import turtle as tu import random as ra import math tu.setup(1.0, 1.0) tu.screensize(1.0, 1.0) tu.title("万圣节") tu.bgcolor('darkorange') t = tu.Pen() t.ht() colors = ['black'] class Bat(): #每个蝙蝠(蝙蝠类) def __init__(self): ……
完整代码
https://want595.blog.csdn.net/article/details/128734395
程序分析
这是一段python代码,用turtle模块创建了一个万圣节的场景,包括南瓜和蝙蝠。其中,南瓜的形状和颜色都很逼真,蝙蝠则实现了飞舞的动态效果。
代码中定义了一个Bat类来创建蝙蝠对象,包含蝙蝠的大小、位置、颜色、移动速度等属性。move()方法实现了蝙蝠随机移动的效果,当蝙蝠飞出画布时,重新生成一个蝙蝠对象。pumpkin()方法用turtle画出了南瓜的形状和特点,包括南瓜的圆润和嘴巴的扭曲。
最后,在主程序中实例化了100个蝙蝠对象,并使用while循环使它们在画布中不断移动,同时更新画面,显示出动态效果。
整段代码用到了python的一些基本语法和turtle模块的函数,如setup()、screensize()、Pen()、begin_fill()、end_fill()等。通过这个小例子,我们可以了解到turtle的绘图功能,以及python类的基本使用。
感谢小伙伴们的支持吖,祝大家万圣节快乐哦!
上一篇:玩家教程!(WPK技巧)辅助透视!(透视)外挂辅助器ai(2022已更新)(哔哩哔哩)
下一篇:【阿里云 centos7安装python3.12遇到的坑,openssl】Could not build the ssl module! Python requires a OpenSSL 1.1.1