Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ABV-Visualization
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
phwitte
ABV-Visualization
Commits
3b272b80
Commit
3b272b80
authored
6 years ago
by
phwitte
Browse files
Options
Downloads
Patches
Plain Diff
Update Life.py
parent
ff7076ce
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Life.py
+23
-8
23 additions, 8 deletions
Life.py
with
23 additions
and
8 deletions
Life.py
+
23
−
8
View file @
3b272b80
...
@@ -15,7 +15,7 @@ matplotlib.use('TkAgg')
...
@@ -15,7 +15,7 @@ matplotlib.use('TkAgg')
import
matplotlib.pyplot
as
pyplot
import
matplotlib.pyplot
as
pyplot
def
circleArray
(
r1
,
r2
,
weight
,
oval
=
0
,
ovalscaling
=
2
,
invers
=
False
,
xshift
=
0
,
yshift
=
0
):
def
circleArray
(
r1
,
r2
,
weight
,
oval
=
0
,
ovalscaling
=
2
,
invers
=
False
,
xshift
=
1
,
yshift
=
1
):
width
=
2
*
r2
+
1
width
=
2
*
r2
+
1
height
=
2
*
r2
+
1
height
=
2
*
r2
+
1
...
@@ -61,7 +61,7 @@ def circleArray(r1, r2, weight, oval=0, ovalscaling= 2, invers=False, xshift = 0
...
@@ -61,7 +61,7 @@ def circleArray(r1, r2, weight, oval=0, ovalscaling= 2, invers=False, xshift = 0
return
map_
return
map_
def
squareArray
(
r1
,
r2
,
weight
,
rect
=
1
,
rectscaling
=
2
):
def
squareArray
(
r1
,
r2
,
weight
,
rect
=
0
,
rectscaling
=
2
):
width
=
2
*
r2
+
1
width
=
2
*
r2
+
1
height
=
2
*
r2
+
1
height
=
2
*
r2
+
1
...
@@ -93,7 +93,7 @@ class Life(object):
...
@@ -93,7 +93,7 @@ class Life(object):
n: the number of rows and columns
n: the number of rows and columns
"""
"""
def
__init__
(
self
,
n
,
mode
=
'
wrap
'
,
random
=
Tru
e
,
p
=
0.001
,
radius1
=
3
,
radius2
=
6
,
weight
=-
0.5
,
doubleStates
=
Fals
e
,
inversion
=
False
):
def
__init__
(
self
,
n
,
mode
=
'
wrap
'
,
random
=
Fals
e
,
p
=
0.001
,
radius1
=
3
,
radius2
=
6
,
weight
=-
0.
2
5
,
doubleStates
=
Tru
e
,
inversion
=
False
):
"""
Attributes:
"""
Attributes:
n: number of rows and columns
n: number of rows and columns
mode: how border conditions are handled
mode: how border conditions are handled
...
@@ -141,18 +141,31 @@ class Life(object):
...
@@ -141,18 +141,31 @@ class Life(object):
"""
Executes one time step.
"""
"""
Executes one time step.
"""
con
=
scipy
.
ndimage
.
filters
.
convolve
(
self
.
array
,
con
=
scipy
.
ndimage
.
filters
.
convolve
(
self
.
array
,
self
.
weights
,
self
.
weights
,
mode
=
self
.
mode
)
mode
=
self
.
mode
,
cval
=
0.0
)
#boolean = (con==3) | (con==12) | (con==13)
#boolean = (con==3) | (con==12) | (con==13)
sideBorders
=
True
topbotBorders
=
True
if
(
not
self
.
doubleStates
):
if
(
not
self
.
doubleStates
):
boolean
=
(
con
>=
1
)
boolean
=
(
con
>=
1
)
for
y
in
range
(
self
.
n
):
for
x
in
range
(
self
.
n
):
if
sideBorders
and
((
x
<
self
.
radius2
)
or
(
x
>
self
.
n
-
self
.
radius2
)):
boolean
[
y
][
x
]
=
True
if
topbotBorders
and
((
y
<
self
.
radius2
)
or
(
y
>
self
.
n
-
self
.
radius2
)):
boolean
[
y
][
x
]
=
True
self
.
array
=
numpy
.
int8
(
boolean
)
self
.
array
=
numpy
.
int8
(
boolean
)
else
:
else
:
print
(
"
doublestates
"
)
values
=
[[
0
for
x
in
range
(
self
.
n
)]
for
y
in
range
(
self
.
n
)]
values
=
[[
0
for
x
in
range
(
self
.
n
)]
for
y
in
range
(
self
.
n
)]
for
y
in
range
(
self
.
n
):
for
y
in
range
(
self
.
n
):
for
x
in
range
(
self
.
n
):
for
x
in
range
(
self
.
n
):
if
con
[
y
][
x
]
>=
4
*
self
.
radius2
:
if
sideBorders
and
((
x
<
self
.
radius2
)
or
(
x
>
self
.
n
-
self
.
radius2
)):
values
[
y
][
x
]
=
0
if
topbotBorders
and
((
y
<
self
.
radius2
)
or
(
y
>
self
.
n
-
self
.
radius2
)):
values
[
y
][
x
]
=
0
elif
con
[
y
][
x
]
>=
2
*
self
.
radius2
:
values
[
y
][
x
]
=
2
values
[
y
][
x
]
=
2
elif
con
[
y
][
x
]
>=
1
:
elif
con
[
y
][
x
]
>=
1
:
values
[
y
][
x
]
=
1
values
[
y
][
x
]
=
1
...
@@ -185,19 +198,21 @@ class LifeViewer(object):
...
@@ -185,19 +198,21 @@ class LifeViewer(object):
self
.
pcolor
=
pyplot
.
pcolor
(
a
,
cmap
=
self
.
cmap
)
self
.
pcolor
=
pyplot
.
pcolor
(
a
,
cmap
=
self
.
cmap
)
self
.
fig
.
canvas
.
draw
()
self
.
fig
.
canvas
.
draw
()
def
animate
(
self
,
steps
=
1
0
):
def
animate
(
self
,
steps
=
1
):
"""
Creates the GUI and then invokes animate_callback.
"""
Creates the GUI and then invokes animate_callback.
Generates an animation with the given number of steps.
Generates an animation with the given number of steps.
"""
"""
self
.
steps
=
steps
self
.
steps
=
steps
self
.
fig
.
canvas
.
manager
.
window
.
after
(
1000
,
self
.
animate_callback
)
self
.
fig
.
canvas
.
manager
.
window
.
after
(
1000
,
self
.
animate_callback
)
self
.
fig
.
savefig
(
'
/home/phill/Cell_Automata/test_0/pic.png
'
)
pyplot
.
show
()
pyplot
.
show
()
def
animate_callback
(
self
):
def
animate_callback
(
self
):
"""
Runs the animation.
"""
"""
Runs the animation.
"""
for
i
in
range
(
self
.
steps
):
for
i
in
range
(
self
.
steps
):
self
.
life
.
step
()
self
.
life
.
step
()
self
.
fig
.
savefig
(
'
/home/phill/Cell_Automata/test_0/pic
'
+
str
(
i
)
+
'
.png
'
)
self
.
update
()
self
.
update
()
print
(
'
end
'
)
print
(
'
end
'
)
...
@@ -209,7 +224,7 @@ def main(script, n=20, radius1 = 5, radius2 = 10,p= 0.1, weight=-0.5, doubleStat
...
@@ -209,7 +224,7 @@ def main(script, n=20, radius1 = 5, radius2 = 10,p= 0.1, weight=-0.5, doubleStat
life
=
Life
(
n
,
random
=
True
,
radius1
=
radius1
,
radius2
=
radius2
,
p
=
p
,
weight
=
weight
,
doubleStates
=
doubleStates
,
inversion
=
inversion
)
life
=
Life
(
n
,
random
=
True
,
radius1
=
radius1
,
radius2
=
radius2
,
p
=
p
,
weight
=
weight
,
doubleStates
=
doubleStates
,
inversion
=
inversion
)
#life.add_glider(10, 10)
#life.add_glider(10, 10)
viewer
=
LifeViewer
(
life
)
viewer
=
LifeViewer
(
life
)
viewer
.
animate
(
steps
=
10
0
)
viewer
.
animate
(
steps
=
10
)
"""
df
"""
"""
df
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment