转:
1 Python与Processing介绍(《Python趣味创意编程》教学视频) - 知乎
视频教程:
知乎视频 www.zhihu.comProcessing的压缩文件、Python Mode压缩包,也可以从百度云盘下载:
链接:https://pan.baidu.com/s/1YOEUhIc9r0c1pOPjHIdr9w
提取码:3i4n
下载配置好的同学,可以测试运行以下代码:
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章 随风飘动的粒子 的效果:
知乎视频 www.zhihu.com转: