![f279c740f3b47bf1e2a7f00d717809eb.png](https://img-blog.csdnimg.cn/img_convert/f279c740f3b47bf1e2a7f00d717809eb.png)
(图书介绍:童晶:《Python趣味创意编程》新书预告)
视频教程:
知乎视频www.zhihu.comProcessing的压缩文件、Python Mode压缩包,也可以从百度云盘下载:
链接:https://pan.baidu.com/s/1YOEUhIc9r0c1pOPjHIdr9w
提取码:3i4n
![ef4055f07cb14f924c5adcdd2e1f2892.png](https://img-blog.csdnimg.cn/img_convert/ef4055f07cb14f924c5adcdd2e1f2892.png)
下载配置好的同学,可以测试运行以下代码:
particles = []
def setup():
size(1280, 800)
noStroke()
for i in range(2000):
x = random(0,width)
y = random(0,height)
v_mag = random(1.0,2.0)
v_angle = random(-2*PI,2*PI)
c = color(random(100,255),random(100,255),random(100,255))
particle = [x,y,v_mag,v_angle,c]
particles.append(particle)
def draw():
fill(0, 10)
rect(0, 0, width, height)
fill(255)
for particle in particles:
noiseValue = noise(0.001*particle[0],10+0.001*particle[1]
,frameCount*0.005)
particle[3] = map(noiseValue,0,1,-2*PI,PI*2)
vx = particle[2]*cos(particle[3])
vy = particle[2]*sin(particle[3])
particle[0] = particle[0] + vx
particle[1] = particle[1] + vy
if particle[0]<0 or particle[0]>width
or particle[1]<0 or particle[1]>height:
particle[0] = random(0,width)
particle[1] = random(0,height)
r = map(sin(frameCount/75.0),-1,1,50,255)
g = map(sin(frameCount/101.0),-1,1,75,255)
b = map(sin(frameCount/151.0),-1,1,100,255)
particle[4] = color(r,g,b)
fill(particle[4])
circle(particle[0], particle[1], 2)
正常运行可以得到 第8章 随风飘动的粒子 的效果:
![b26ceac36ac82e35dc15142929cbd8a1.png](https://img-blog.csdnimg.cn/img_convert/b26ceac36ac82e35dc15142929cbd8a1.png)
这一章主要了解了计算机程序、Python编程语言的基本概念,学习了Processing的下载、配置方法,下一章我们将开始趣味创意编程的学习开发。