diffusion simulation
来源:互联网 发布:软件著作权 英文 编辑:程序博客网 时间:2024/04/28 22:56
### simulation of particles diffusion
import simplegui
import random
# Golbal constants
WIDTH = 600; HEIGHT = 400; PARTICLE_RADIUS = 5; VEL = 4
COLOR_LIST = ["Red", "White", "Aqua", "Blue"]
DIRECTION_LIST = [[VEL,0],[-VEL,0],[0, VEL],[0,-VEL]]
# definition of a particle class
class particle:
def __init__(self, pos, color):
self.pos = pos
self.color = color
def move(self, offset):
self.pos[0] += offset[0]
self.pos[1] += offset[1]
def draw(self, canvas):
canvas.draw_circle(self.pos, PARTICLE_RADIUS, 20, self.color, self.color)
def __str__(self):
return "particle with position" + str(self.pos) + " and color" + self.color
# create a list of particles
particle_list = []
for i in range(1000):
j = particle([WIDTH/2,HEIGHT/2],random.choice(COLOR_LIST))
particle_list.append(j)
# draw handler
def draw(canvas):
for j in particle_list:
j.move(random.choice(DIRECTION_LIST))
for j in particle_list:
j.draw(canvas)
# create frame and register draw handler
frame = simplegui.create_frame("particle simulation", WIDTH, HEIGHT)
frame.set_draw_handler(draw)
# start frame
frame.start()
import simplegui
import random
# Golbal constants
WIDTH = 600; HEIGHT = 400; PARTICLE_RADIUS = 5; VEL = 4
COLOR_LIST = ["Red", "White", "Aqua", "Blue"]
DIRECTION_LIST = [[VEL,0],[-VEL,0],[0, VEL],[0,-VEL]]
# definition of a particle class
class particle:
def __init__(self, pos, color):
self.pos = pos
self.color = color
def move(self, offset):
self.pos[0] += offset[0]
self.pos[1] += offset[1]
def draw(self, canvas):
canvas.draw_circle(self.pos, PARTICLE_RADIUS, 20, self.color, self.color)
def __str__(self):
return "particle with position" + str(self.pos) + " and color" + self.color
# create a list of particles
particle_list = []
for i in range(1000):
j = particle([WIDTH/2,HEIGHT/2],random.choice(COLOR_LIST))
particle_list.append(j)
# draw handler
def draw(canvas):
for j in particle_list:
j.move(random.choice(DIRECTION_LIST))
for j in particle_list:
j.draw(canvas)
# create frame and register draw handler
frame = simplegui.create_frame("particle simulation", WIDTH, HEIGHT)
frame.set_draw_handler(draw)
# start frame
frame.start()
0 0
- diffusion simulation
- anisotropic diffusion
- Confusion, diffusion, Collision, Substitution
- black error diffusion
- average diffusion distance
- 各向异性扩散 Anisotropic diffusion
- Behavioral Simulation,Structural Simulation,Timing Simulation
- Diffusion of innovations(创新扩散)
- Cloth Simulation
- Simulation Robot
- Game Simulation
- Rigidbody Simulation
- game simulation
- Restaurant Simulation
- Ocean Simulation
- Squirrel Simulation
- Physics Simulation
- 模拟:simulation,与 仿真:simulation
- 大数加法简易理解并实现
- 最新手机号段归属地数据库(2016年7月15日)
- 一个IEEE论文LaTeX模板,可能较旧
- sqlite no such table
- # JAVA中集合解析篇一 ArrayList解析
- diffusion simulation
- 最新行政区划代码省市区数据库(2016年7月1日 )
- Latex作者单位的写法—AND 首页脚注
- Blocks(poj3734)组合数学
- js的隐式转换问题
- swift中使用OC的方法;在OC中调用swift方法
- 贰:Modbus常用功能码协议详解
- ECMAScript中的真值和假值
- 占坑[概率dp] poj 2096 Collecting Bugs