下图截gif的时候,其软件对图片进行压缩,实际效果是更好的。
以下是部分代码预览:
"""用python的海龟画图制作的粒子效果演示动画,
这个程序建立了一个叫Particle的类,这个类继承自海龟类"""
from turtle import *
from random import randint
from time import sleep
class Particle(Turtle):
def __init__(self):
Turtle.__init__(self,visible=False,shape="circle")
self.penup()
self.speed(0)
color = (randint(0,255),randint(0,255),randint(0,255))
self.color(color)
self.shapesize(0.1,0.1) # 形状为1/10
self.sw = self.screen.window_height() # 定义属性,让它能访问屏幕高度
self.accspeed = -0.1 # 加速度
def move(self):
"""移动粒子,到了最下边则隐藏重新移动"""
x = self.xcor() + self.xspeed # 水平方向移动
y = self.ycor() + self.yspeed # 垂直方向受重力移动
if __name__=="__main__": # 如果程序由自身启动,(非做为模块启动)
width,height = 480,360
screen = Screen()
screen.setup(width,height)
screen.title("python海龟画图的彩色粒子效果by李兴球")
screen.bgcolor("black")
screen.bgpic("月圆之日.png")
screen.colormode(255)
screen.delay(0)
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
