forked from JanisErdmanis/PythonPhysics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.13.py
68 lines (59 loc) · 1.14 KB
/
10.13.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 23 11:09:42 2013
@author: akels
"""
from __future__ import division, print_function
from pylab import *
from visual import sphere,rate, display
from numpy.random import randint
L = 101
tau = L*L//6#1e4
pos0 = L//2,L//2 #50,50
#i = 50
#j = 50
grid = zeros((L-1,L-1),bool)
def add(i,j,time=0):
grid[i,j]=True
s = sphere(radius=0.5)
s.pos = i,j #i-50,j-50
color = t/tau#(1-1*exp(-t/tau))
s.color = color,color,color
print(i,j)
d = display(center=(L//2,L//2))
s = sphere()
s.pos = L,L
d.autoscale = False
s.visible=False
t = 0
while grid[pos0]==False:
t+=1
i,j = pos0
while True:
a = randint(4)
# If next position is False!=grid[i,j] then I should add sphere
if a==0: #move up
if i==L-2 or grid[i+1,j]==True:
#grid[i,j]==True # I could make a new object
add(i,j,time=t)
break
else:
i+=1
elif a==1:
if i==0 or grid[i-1,j]==True:
add(i,j,time=t)
break
else:
i-=1
elif a==2:
if j==L-2 or grid[i,j+1]==True:
add(i,j,time=t)
break
else:
j+=1
elif a==3:
if j==0 or grid[i,j-1]:
add(i,j,time=t)
break
else:
j-=1