Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ahmad Reza Cheraghi
swarm-sim
Commits
6b638d6d
Commit
6b638d6d
authored
Sep 26, 2019
by
Ahmad Reza
Browse files
Renamed the attributes coords to coordinations and alpha to transparency
parent
2b269a47
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
lib/csv_generator.py
View file @
6b638d6d
"""
TODO:
1- Order the names based on particles, markers, and tiles and
alpha
betic
1- Order the names based on particles, markers, and tiles and
transparency
betic
2- A new column called round_success
3- On demand extenstion of the metrics.
...
...
lib/marker.py
View file @
6b638d6d
...
...
@@ -6,8 +6,8 @@ from lib.swarm_sim_header import *
class
Marker
(
matter
.
Matter
):
"""In the classe marker all the methods for the characterstic of a marker is included"""
def
__init__
(
self
,
world
,
x
,
y
,
color
=
black
,
alpha
=
1
):
def
__init__
(
self
,
world
,
x
,
y
,
color
=
black
,
transparency
=
1
):
"""Initializing the marker constructor"""
super
().
__init__
(
world
,
(
x
,
y
),
color
,
alpha
,
type
=
"marker"
,
mm_size
=
world
.
config_data
.
marker_mm_size
)
super
().
__init__
(
world
,
(
x
,
y
),
color
,
transparency
,
type
=
"marker"
,
mm_size
=
world
.
config_data
.
marker_mm_size
)
lib/matter.py
View file @
6b638d6d
...
...
@@ -7,42 +7,42 @@ from lib.swarm_sim_header import *
class
Matter
:
"""In the classe marker all the methods for the characterstic of a marker is included"""
def
__init__
(
self
,
world
,
coords
,
color
=
black
,
alpha
=
1
,
type
=
None
,
mm_size
=
100
):
def
__init__
(
self
,
world
,
coord
inate
s
,
color
=
black
,
transparency
=
1
,
type
=
None
,
mm_size
=
100
):
"""Initializing the marker constructor"""
self
.
coords
=
coords
self
.
coord
inate
s
=
coord
inate
s
self
.
color
=
color_map
[
color
]
self
.
__id
=
str
(
uuid
.
uuid4
())
self
.
world
=
world
self
.
_memory
=
{}
self
.
__
alpha
=
alpha
self
.
__
transparency
=
transparency
self
.
type
=
type
self
.
memory_limitation
=
world
.
config_data
.
memory_limitation
self
.
mm_size
=
mm_size
self
.
modified
=
False
self
.
created
=
False
def
set_
alpha
(
self
,
alpha
):
def
set_
transparency
(
self
,
transparency
):
"""
Set the
alpha
value of the particle
Set the
transparency
value of the particle
:param
alpha: The alpha
of the particle
:param
transparency: The transparency
of the particle
:return: None
"""
if
(
0
<=
alpha
<=
1
):
self
.
__
alpha
=
round
(
alpha
,
2
)
elif
alpha
<
0
:
self
.
__
alpha
=
0
elif
alpha
>
1
:
self
.
__
alpha
=
1
if
(
0
<=
transparency
<=
1
):
self
.
__
transparency
=
round
(
transparency
,
2
)
elif
transparency
<
0
:
self
.
__
transparency
=
0
elif
transparency
>
1
:
self
.
__
transparency
=
1
self
.
touch
()
def
get_
alpha
(
self
):
def
get_
transparency
(
self
):
"""
Returns the
alpha
value of the particle
Returns the
transparency
value of the particle
:return:
alpha
:return:
transparency
"""
return
round
(
self
.
__
alpha
,
2
)
return
round
(
self
.
__
transparency
,
2
)
def
read_memory_with
(
self
,
key
):
"""
...
...
lib/particle.py
View file @
6b638d6d
This diff is collapsed.
Click to expand it.
lib/swarm_sim_header.py
View file @
6b638d6d
...
...
@@ -85,78 +85,78 @@ def direction_in_range(direction):
return
direction
%
6
def
check_values_are_coordinates
(
coords_x
,
coords_y
):
def
check_values_are_coordinates
(
coord
inate
s_x
,
coord
inate
s_y
):
"""
Checks if the given coordinates are matching the
hexagon coordinates
:param coords_x: proposed x coordinate
:param coords_y: proposed y coordinate
:param coord
inate
s_x: proposed x coordinate
:param coord
inate
s_y: proposed y coordinate
:return: True: Correct x and y coordinates; False: Incorrect coordinates
"""
if
(
coords_x
/
0.5
)
%
2
==
0
:
if
coords_y
%
2
!=
0
:
if
(
coord
inate
s_x
/
0.5
)
%
2
==
0
:
if
coord
inate
s_y
%
2
!=
0
:
return
False
else
:
return
True
else
:
if
coords_y
%
2
==
0
:
if
coord
inate
s_y
%
2
==
0
:
return
False
else
:
return
True
def
coords_to_sim
(
coords
):
return
coords
[
0
],
coords
[
1
]
*
math
.
sqrt
(
3
/
4
)
def
coord
inate
s_to_sim
(
coord
inate
s
):
return
coord
inate
s
[
0
],
coord
inate
s
[
1
]
*
math
.
sqrt
(
3
/
4
)
def
sim_to_coords
(
x
,
y
):
def
sim_to_coord
inate
s
(
x
,
y
):
return
x
,
round
(
y
/
math
.
sqrt
(
3
/
4
),
0
)
def
get_coords_in_direction
(
coords
,
direction
):
def
get_coord
inate
s_in_direction
(
coord
inate
s
,
direction
):
"""
Returns the coordination data of the pointed directions
:param coords: particles actual staying coordination
:param coord
inate
s: particles actual staying coordination
:param direction: The direction. Options: E, SE, SW, W, NW, or NE
:return: The coordinaiton of the pointed directions
"""
return
coords
[
0
]
+
x_offset
[
direction
],
coords
[
1
]
+
y_offset
[
direction
]
return
coord
inate
s
[
0
]
+
x_offset
[
direction
],
coord
inate
s
[
1
]
+
y_offset
[
direction
]
def
global_scanning
(
matter_map_coords_dict
,
hop
,
starting_x
,
starting_y
):
def
global_scanning
(
matter_map_coord
inate
s_dict
,
hop
,
starting_x
,
starting_y
):
hop_list
=
[]
if
(
hop
/
2
+
starting_x
,
hop
+
starting_y
)
in
matter_map_coords_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
hop
/
2
+
starting_x
,
hop
+
starting_y
)])
if
(
hop
+
starting_x
,
starting_y
)
in
matter_map_coords_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
hop
+
starting_x
,
starting_y
)])
if
(
hop
/
2
+
starting_x
,
-
hop
+
starting_y
)
in
matter_map_coords_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
hop
/
2
+
starting_x
,
-
hop
+
starting_y
)])
if
(
-
hop
/
2
+
starting_x
,
-
hop
+
starting_y
)
in
matter_map_coords_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
-
hop
/
2
+
starting_x
,
-
hop
+
starting_y
)])
if
(
-
hop
+
starting_x
,
starting_y
)
in
matter_map_coords_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
-
hop
+
starting_x
,
starting_y
)])
if
(
-
hop
/
2
+
starting_x
,
hop
+
starting_y
)
in
matter_map_coords_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
-
hop
/
2
+
starting_x
,
hop
+
starting_y
)])
if
(
hop
/
2
+
starting_x
,
hop
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coord
inate
s_dict
[(
hop
/
2
+
starting_x
,
hop
+
starting_y
)])
if
(
hop
+
starting_x
,
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coord
inate
s_dict
[(
hop
+
starting_x
,
starting_y
)])
if
(
hop
/
2
+
starting_x
,
-
hop
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coord
inate
s_dict
[(
hop
/
2
+
starting_x
,
-
hop
+
starting_y
)])
if
(
-
hop
/
2
+
starting_x
,
-
hop
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coord
inate
s_dict
[(
-
hop
/
2
+
starting_x
,
-
hop
+
starting_y
)])
if
(
-
hop
+
starting_x
,
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coord
inate
s_dict
[(
-
hop
+
starting_x
,
starting_y
)])
if
(
-
hop
/
2
+
starting_x
,
hop
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coord
inate
s_dict
[(
-
hop
/
2
+
starting_x
,
hop
+
starting_y
)])
for
i
in
range
(
1
,
hop
):
if
(
-
hop
/
2
+
i
+
starting_x
,
hop
+
starting_y
)
in
matter_map_coords_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
-
hop
/
2
+
i
+
starting_x
,
hop
+
starting_y
)])
if
(
hop
/
2
+
(
0.5
*
i
)
+
starting_x
,
hop
-
i
+
starting_y
)
in
matter_map_coords_dict
:
if
(
-
hop
/
2
+
i
+
starting_x
,
hop
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coord
inate
s_dict
[(
-
hop
/
2
+
i
+
starting_x
,
hop
+
starting_y
)])
if
(
hop
/
2
+
(
0.5
*
i
)
+
starting_x
,
hop
-
i
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
hop
/
2
+
(
0.5
*
i
)
+
starting_x
,
hop
-
i
+
starting_y
)])
if
(
hop
/
2
+
(
0.5
*
i
)
+
starting_x
,
-
hop
+
i
+
starting_y
)
in
matter_map_coords_dict
:
matter_map_coord
inate
s_dict
[(
hop
/
2
+
(
0.5
*
i
)
+
starting_x
,
hop
-
i
+
starting_y
)])
if
(
hop
/
2
+
(
0.5
*
i
)
+
starting_x
,
-
hop
+
i
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
hop
/
2
+
(
0.5
*
i
)
+
starting_x
,
-
hop
+
i
+
starting_y
)])
if
(
-
hop
/
2
+
i
+
starting_x
,
-
hop
+
starting_y
)
in
matter_map_coords_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
-
hop
/
2
+
i
+
starting_x
,
-
hop
+
starting_y
)])
if
(
-
hop
/
2
-
(
0.5
*
i
)
+
starting_x
,
-
hop
+
i
+
starting_y
)
in
matter_map_coords_dict
:
matter_map_coord
inate
s_dict
[(
hop
/
2
+
(
0.5
*
i
)
+
starting_x
,
-
hop
+
i
+
starting_y
)])
if
(
-
hop
/
2
+
i
+
starting_x
,
-
hop
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coord
inate
s_dict
[(
-
hop
/
2
+
i
+
starting_x
,
-
hop
+
starting_y
)])
if
(
-
hop
/
2
-
(
0.5
*
i
)
+
starting_x
,
-
hop
+
i
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
-
hop
/
2
-
(
0.5
*
i
)
+
starting_x
,
-
hop
+
i
+
starting_y
)])
if
(
-
hop
/
2
-
(
0.5
*
i
)
+
starting_x
,
hop
-
i
+
starting_y
)
in
matter_map_coords_dict
:
matter_map_coord
inate
s_dict
[(
-
hop
/
2
-
(
0.5
*
i
)
+
starting_x
,
-
hop
+
i
+
starting_y
)])
if
(
-
hop
/
2
-
(
0.5
*
i
)
+
starting_x
,
hop
-
i
+
starting_y
)
in
matter_map_coord
inate
s_dict
:
hop_list
.
append
(
matter_map_coords_dict
[(
-
hop
/
2
-
(
0.5
*
i
)
+
starting_x
,
hop
-
i
+
starting_y
)])
matter_map_coord
inate
s_dict
[(
-
hop
/
2
-
(
0.5
*
i
)
+
starting_x
,
hop
-
i
+
starting_y
)])
return
hop_list
...
...
@@ -169,28 +169,28 @@ def generating_random_spraded_particles (world, max_size_particle):
y
=
random
.
randrange
(
-
world
.
get_world_y_size
(),
world
.
get_world_y_size
())
if
y
%
2
==
1
:
x
=
x
+
0.5
if
(
x
,
y
)
not
in
world
.
tile_map_coords
:
if
(
x
,
y
)
not
in
world
.
tile_map_coord
inate
s
:
world
.
add_particle
(
x
,
y
)
else
:
print
(
" x and y "
,
(
x
,
y
))
print
(
"Max Size of created Particle"
,
len
(
world
.
particles
))
def
create_particle_in_line
(
world
,
max_size_particle
,
start_coords
):
if
start_coords
[
0
]
%
1
!=
0
:
start_i
=
int
(
start_coords
[
0
]
-
0.5
)
def
create_particle_in_line
(
world
,
max_size_particle
,
start_coord
inate
s
):
if
start_coord
inate
s
[
0
]
%
1
!=
0
:
start_i
=
int
(
start_coord
inate
s
[
0
]
-
0.5
)
for
i
in
range
(
start_i
,
start_i
+
max_size_particle
):
world
.
add_particle
(
i
+
1.5
,
start_coords
[
1
])
world
.
add_particle
(
i
+
1.5
,
start_coord
inate
s
[
1
])
else
:
for
i
in
range
(
int
(
start_coords
[
0
]
+
1
),
int
(
start_coords
[
0
]
+
1
)
+
max_size_particle
):
world
.
add_particle
(
i
,
start_coords
[
1
])
for
i
in
range
(
int
(
start_coord
inate
s
[
0
]
+
1
),
int
(
start_coord
inate
s
[
0
]
+
1
)
+
max_size_particle
):
world
.
add_particle
(
i
,
start_coord
inate
s
[
1
])
def
create_particle_in_square
(
world
,
max_size_particle
,
start_coords
):
def
create_particle_in_square
(
world
,
max_size_particle
,
start_coord
inate
s
):
for
y
in
range
(
start_coords
[
1
],
round
(
max_size_particle
/
2
)):
for
x
in
range
(
start_coords
[
0
],
round
(
max_size_particle
/
2
)):
for
y
in
range
(
start_coord
inate
s
[
1
],
round
(
max_size_particle
/
2
)):
for
x
in
range
(
start_coord
inate
s
[
0
],
round
(
max_size_particle
/
2
)):
world
.
add_particle
(
x
+
0.5
,
2
*
y
+
1.0
)
world
.
add_particle
(
-
(
x
+
0.5
),
2
*
y
+
1.0
)
world
.
add_particle
(
x
+
0.5
,
-
(
2
*
y
+
1.0
))
...
...
@@ -292,7 +292,7 @@ def move_to_dest_step_by_step(particle, destiny):
:param destiny:
:return: True if movement occured, False if not movment and a Matter if the next direction point has a matter on it
"""
next_dir
=
get_next_direction_to
(
particle
.
coords
[
0
],
particle
.
coords
[
1
],
destiny
.
coords
[
0
],
destiny
.
coords
[
1
])
next_dir
=
get_next_direction_to
(
particle
.
coord
inate
s
[
0
],
particle
.
coord
inate
s
[
1
],
destiny
.
coord
inate
s
[
0
],
destiny
.
coord
inate
s
[
1
])
if
particle
.
matter_in
(
next_dir
):
particle
.
get_matter_in
(
next_dir
)
return
particle
.
get_matter_in
(
next_dir
)
...
...
lib/tile.py
View file @
6b638d6d
...
...
@@ -6,9 +6,9 @@ from lib.swarm_sim_header import *
class
Tile
(
matter
.
Matter
):
"""In the classe marker all the methods for the characterstic of a marker is included"""
def
__init__
(
self
,
world
,
x
,
y
,
color
=
gray
,
alpha
=
1
):
def
__init__
(
self
,
world
,
x
,
y
,
color
=
gray
,
transparency
=
1
):
"""Initializing the marker constructor"""
super
().
__init__
(
world
,
(
x
,
y
),
color
,
alpha
,
type
=
"tile"
,
mm_size
=
world
.
config_data
.
tile_mm_size
)
super
().
__init__
(
world
,
(
x
,
y
),
color
,
transparency
,
type
=
"tile"
,
mm_size
=
world
.
config_data
.
tile_mm_size
)
self
.
__isCarried
=
False
def
get_tile_status
(
self
):
...
...
@@ -28,46 +28,46 @@ class Tile(matter.Matter):
"""
self
.
__isCarried
=
status
def
take
(
self
,
coords
=
0
):
def
take
(
self
,
coord
inate
s
=
0
):
"""
Takes the tile on the given coordinate if it is not taken
:param coords: Coordination of tile that should be taken
:param coord
inate
s: Coordination of tile that should be taken
:return: True: Successful taken; False: Cannot be taken or wrong Coordinates
"""
if
coords
==
0
:
if
coord
inate
s
==
0
:
if
self
.
__isCarried
==
False
:
if
self
.
coords
in
self
.
world
.
tile_map
:
del
self
.
world
.
tile_map_coords
[
self
.
coords
]
if
self
.
coord
inate
s
in
self
.
world
.
tile_map
:
del
self
.
world
.
tile_map_coord
inate
s
[
self
.
coord
inate
s
]
self
.
__isCarried
=
True
self
.
set_
alpha
(
0.5
)
self
.
set_
transparency
(
0.5
)
self
.
touch
()
return
True
else
:
return
False
else
:
if
self
.
__isCarried
==
False
:
if
self
.
coords
in
self
.
world
.
tile_map_coords
:
del
self
.
world
.
tile_map_coords
[
self
.
coords
]
if
self
.
coord
inate
s
in
self
.
world
.
tile_map_coord
inate
s
:
del
self
.
world
.
tile_map_coord
inate
s
[
self
.
coord
inate
s
]
self
.
__isCarried
=
True
self
.
coords
=
coords
self
.
set_
alpha
(
0.5
)
self
.
coord
inate
s
=
coord
inate
s
self
.
set_
transparency
(
0.5
)
self
.
touch
()
return
True
else
:
return
False
def
drop_me
(
self
,
coords
):
def
drop_me
(
self
,
coord
inate
s
):
"""
Drops the tile
:param coords: the given position
:param coord
inate
s: the given position
:return: None
"""
self
.
world
.
tile_map_coords
[
coords
]
=
self
self
.
coords
=
coords
self
.
world
.
tile_map_coord
inate
s
[
coord
inate
s
]
=
self
self
.
coord
inate
s
=
coord
inate
s
self
.
__isCarried
=
False
self
.
set_
alpha
(
1
)
self
.
set_
transparency
(
1
)
self
.
touch
()
def
touch
(
self
):
...
...
lib/vis.py
View file @
6b638d6d
...
...
@@ -32,17 +32,17 @@ print_frame_stats = False
# simulation parameters
rounds_per_second
=
10
# tile_
alpha
= 0.6
particle_
alpha
=
1
# tile_
transparency
= 0.6
particle_
transparency
=
1
marker_
alpha
=
1
marker_
transparency
=
1
def
coords_to_sim
(
coords
):
return
coords
[
0
],
coords
[
1
]
*
math
.
sqrt
(
3
/
4
)
def
coord
inate
s_to_sim
(
coord
inate
s
):
return
coord
inate
s
[
0
],
coord
inate
s
[
1
]
*
math
.
sqrt
(
3
/
4
)
def
sim_to_coords
(
x
,
y
):
def
sim_to_coord
inate
s
(
x
,
y
):
return
x
,
round
(
y
/
math
.
sqrt
(
3
/
4
),
0
)
...
...
@@ -142,7 +142,6 @@ class VisWindow(pyglet.window.Window):
self
.
video_mode
=
False
self
.
draw
()
def
on_mouse_drag
(
self
,
x
,
y
,
dx
,
dy
,
buttons
,
modifiers
):
if
buttons
&
mouse
.
LEFT
:
self
.
view
.
drag
(
dx
,
dy
)
...
...
@@ -155,16 +154,16 @@ class VisWindow(pyglet.window.Window):
def
on_mouse_press
(
self
,
x
,
y
,
button
,
modifiers
):
if
modifiers
&
key
.
MOD_CTRL
:
# get correct coordinates
sim_coords
=
window_to_sim
(
x
,
y
,
self
.
view
)
coords_coords
=
sim_to_coords
(
sim_coords
[
0
],
sim_coords
[
1
])
rounded_coords
=
0
if
coords_coords
[
1
]
%
2
!=
0
:
rounded_coords
=
round
(
coords_coords
[
0
],
0
)
+
0.5
sim_coord
inate
s
=
window_to_sim
(
x
,
y
,
self
.
view
)
coord
inate
s_coord
inate
s
=
sim_to_coord
inate
s
(
sim_coord
inate
s
[
0
],
sim_coord
inate
s
[
1
])
rounded_coord
inate
s
=
0
if
coord
inate
s_coord
inate
s
[
1
]
%
2
!=
0
:
rounded_coord
inate
s
=
round
(
coord
inate
s_coord
inate
s
[
0
],
0
)
+
0.5
else
:
rounded_coords
=
round
(
coords_coords
[
0
],
0
)
if
(
rounded_coords
,
coords_coords
[
1
])
not
in
self
.
world
.
tile_map_coords
:
rounded_coord
inate
s
=
round
(
coord
inate
s_coord
inate
s
[
0
],
0
)
if
(
rounded_coord
inate
s
,
coord
inate
s_coord
inate
s
[
1
])
not
in
self
.
world
.
tile_map_coord
inate
s
:
# add tile and vertices
if
self
.
world
.
add_tile_vis
(
rounded_coords
,
coords_coords
[
1
]):
if
self
.
world
.
add_tile_vis
(
rounded_coord
inate
s
,
coord
inate
s_coord
inate
s
[
1
]):
self
.
tile_vertex_list
.
resize
(
4
*
len
(
self
.
world
.
tiles
),
4
*
len
(
self
.
world
.
tiles
))
#self.tile_vertex_list.resize(4 * len(self.world.tiles), 8 * len(self.world.tiles))
self
.
tile_vertex_list
.
indices
[
4
*
(
len
(
self
.
world
.
tiles
)
-
1
)
:
4
*
(
len
(
self
.
world
.
tiles
)
-
1
)
+
4
]
=
range
(
4
*
(
len
(
self
.
world
.
tiles
)
-
1
),
4
*
(
len
(
self
.
world
.
tiles
)
-
1
)
+
4
)
...
...
@@ -173,7 +172,7 @@ class VisWindow(pyglet.window.Window):
self
.
update_tiles
(
True
)
else
:
# delete tile
self
.
world
.
remove_tile_on
((
rounded_coords
,
coords_coords
[
1
]))
self
.
world
.
remove_tile_on
((
rounded_coord
inate
s
,
coord
inate
s_coord
inate
s
[
1
]))
self
.
tile_vertex_list
.
resize
(
4
*
len
(
self
.
world
.
tiles
),
4
*
len
(
self
.
world
.
tiles
))
self
.
update_tiles
(
True
)
...
...
@@ -295,7 +294,7 @@ class VisWindow(pyglet.window.Window):
def
update_tile
(
self
,
i
,
tile
):
weird
=
256
/
220
pos
=
coords_to_sim
(
tile
.
coords
)
pos
=
coord
inate
s_to_sim
(
tile
.
coord
inate
s
)
x
=
pos
[
0
]
y
=
pos
[
1
]
...
...
@@ -307,18 +306,18 @@ class VisWindow(pyglet.window.Window):
texRight
=
1
/
8
texBottom
=
5
/
8
texTop
=
6
/
8
#tile_
alpha
= 1
#tile_
transparency
= 1
else
:
texLeft
=
7
/
8
texRight
=
1
# 8/8
texBottom
=
4
/
8
texTop
=
5
/
8
#tile_
alpha
= 0.5
#tile_
transparency
= 0.5
self
.
tile_vertex_list
.
tex_coords
[
8
*
i
:
8
*
i
+
8
]
=
[
texLeft
,
texBottom
,
texRight
,
texBottom
,
texRight
,
texTop
,
texLeft
,
texTop
]
self
.
tile_vertex_list
.
colors
[
16
*
i
:
16
*
i
+
16
]
=
(
tile
.
color
+
[
tile
.
get_
alpha
()])
*
4
self
.
tile_vertex_list
.
colors
[
16
*
i
:
16
*
i
+
16
]
=
(
tile
.
color
+
[
tile
.
get_
transparency
()])
*
4
def
init_particle_vertex_list
(
self
):
self
.
particle_vertex_list
=
self
.
particle_vertex_list
=
pyglet
.
graphics
.
vertex_list
\
...
...
@@ -344,7 +343,7 @@ class VisWindow(pyglet.window.Window):
def
update_particle
(
self
,
i
,
particle
):
weird
=
256
/
220
pos
=
coords_to_sim
(
particle
.
coords
)
pos
=
coord
inate
s_to_sim
(
particle
.
coord
inate
s
)
x
=
pos
[
0
]
y
=
pos
[
1
]
...
...
@@ -357,17 +356,17 @@ class VisWindow(pyglet.window.Window):
texRight
=
1
/
8
texBottom
=
7
/
8
texTop
=
6
/
8
#particle.set_
alpha
(0.5)
#particle.set_
transparency
(0.5)
else
:
texLeft
=
0
/
8
texRight
=
1
/
8
texBottom
=
0
/
8
texTop
=
1
/
8
#particle.set_
alpha
(1)
#particle.set_
transparency
(1)
self
.
particle_vertex_list
.
tex_coords
[
8
*
i
:
8
*
i
+
8
]
=
[
texLeft
,
texBottom
,
texRight
,
texBottom
,
texRight
,
texTop
,
texLeft
,
texTop
]
self
.
particle_vertex_list
.
colors
[
16
*
i
:
16
*
i
+
16
]
=
(
particle
.
color
+
[
particle
.
get_
alpha
()])
*
4
self
.
particle_vertex_list
.
colors
[
16
*
i
:
16
*
i
+
16
]
=
(
particle
.
color
+
[
particle
.
get_
transparency
()])
*
4
def
init_marker_vertex_list
(
self
):
self
.
marker_vertex_list
=
self
.
marker_vertex_list
=
pyglet
.
graphics
.
vertex_list
\
...
...
@@ -393,7 +392,7 @@ class VisWindow(pyglet.window.Window):
def
update_marker
(
self
,
i
,
marker
):
weird
=
256
/
220
pos
=
coords_to_sim
(
marker
.
coords
)
pos
=
coord
inate
s_to_sim
(
marker
.
coord
inate
s
)
x
=
pos
[
0
]
y
=
pos
[
1
]
...
...
@@ -407,7 +406,7 @@ class VisWindow(pyglet.window.Window):
self
.
marker_vertex_list
.
tex_coords
[
8
*
i
:
8
*
i
+
8
]
=
[
texLeft
,
texBottom
,
texRight
,
texBottom
,
texRight
,
texTop
,
texLeft
,
texTop
]
self
.
marker_vertex_list
.
colors
[
16
*
i
:
16
*
i
+
16
]
=
(
marker
.
color
+
[
marker
.
get_
alpha
()])
*
4
self
.
marker_vertex_list
.
colors
[
16
*
i
:
16
*
i
+
16
]
=
(
marker
.
color
+
[
marker
.
get_
transparency
()])
*
4
def
draw_world
(
self
,
round_start_timestamp
):
while
not
self
.
simulation_running
:
...
...
lib/world.py
View file @
6b638d6d
...
...
@@ -34,21 +34,21 @@ class World:
self
.
particles
=
[]
self
.
particles_created
=
[]
self
.
particle_rm
=
[]
self
.
particle_map_coords
=
{}
self
.
particle_map_coord
inate
s
=
{}
self
.
particle_map_id
=
{}
self
.
__particle_deleted
=
False
self
.
tiles
=
[]
self
.
tiles_created
=
[]
self
.
tiles_rm
=
[]
self
.
tile_map_coords
=
{}
self
.
tile_map_coord
inate
s
=
{}
self
.
tile_map_id
=
{}
self
.
__tile_deleted
=
False
self
.
new_tile
=
None
self
.
markers
=
[]
self
.
markers_created
=
[]
self
.
marker_map_coords
=
{}
self
.
marker_map_coord
inate
s
=
{}
self
.
marker_map_id
=
{}
self
.
markers_rm
=
[]
self
.
__marker_deleted
=
False
...
...
@@ -148,13 +148,13 @@ class World:
"""
return
self
.
particles
def
get_particle_map_coords
(
self
):
def
get_particle_map_coord
inate
s
(
self
):
"""
Get a dictionary with all particles mapped with their actual coordinates
:return: a dictionary with particles and their coordinates
"""
return
self
.
particle_map_coords
return
self
.
particle_map_coord
inate
s
def
get_particle_map_id
(
self
):
"""
...
...
@@ -180,13 +180,13 @@ class World:
"""
return
self
.
tiles
def
get_tile_map_coords
(
self
):
def
get_tile_map_coord
inate
s
(
self
):
"""
Get a dictionary with all tiles mapped with their actual coordinates
:return: a dictionary with particles and their coordinates
"""
return
self
.
tile_map_coords
return
self
.
tile_map_coord
inate
s
def
get_tile_map_id
(
self
):
"""
...
...
@@ -212,13 +212,13 @@ class World:
"""
return
self
.
markers
def
get_marker_map_coords
(
self
):
def
get_marker_map_coord
inate
s
(
self
):
"""
Get a dictionary with all markers mapped with their actual coordinates
:return: a dictionary with markers and their coordinates
"""
return
self
.
marker_map_coords
return
self
.
marker_map_coord
inate
s
def
get_marker_map_id
(
self
):
"""
...
...
@@ -265,7 +265,7 @@ class World:
def
set_marker_deleted
(
self
):
self
.
__marker_deleted
=
False
def
add_particle
(
self
,
x
,
y
,
color
=
black
,
alpha
=
1
):
def
add_particle
(
self
,
x
,
y
,
color
=
black
,
transparency
=
1
):
"""
Add a particle to the world database
...
...
@@ -276,23 +276,23 @@ class World:
:param color: The color of the particle. Coloroptions: black, gray, red, green, or blue
:return: Added Matter; False: Unsuccsessful
"""
if
alpha
<
0
or
alpha
>
1
:
alpha
=
1
if
transparency
<
0
or
transparency
>
1
:
transparency
=
1
if
len
(
self
.
particles
)
<
self
.
config_data
.
max_particles
:
if
check_values_are_coordinates
(
x
,
y
)
==
True
:
if
(
x
,
y
)
not
in
self
.
get_particle_map_coords
():
if
(
x
,
y
)
not
in
self
.
get_particle_map_coord
inate
s
():
self
.
particle_id_counter
+=
1
new_particle
=
particle
.
Particle
(
self
,
x
,
y
,
color
,
alpha
,
self
.
particle_id_counter
)
new_particle
=
particle
.
Particle
(
self
,
x
,
y
,
color
,
transparency
,
self
.
particle_id_counter
)
print
(
new_particle
.
number
)
self
.
particles_created
.
append
(
new_particle
)
self
.
particle_map_coords
[
new_particle
.
coords
]
=
new_particle
self
.
particle_map_coord
inate
s
[
new_particle
.
coord
inate
s
]
=
new_particle
self
.
particle_map_id
[
new_particle
.
get_id
()]
=
new_particle
self
.
particles
.
append
(
new_particle
)
new_particle
.
touch
()
self
.
csv_round
.
update_particle_num
(
len
(
self
.
particles
))
self
.
init_particles
.
append
(
new_particle
)
new_particle
.
created
=
True
logging
.
info
(
"Created particle at %s"
,
new_particle
.
coords
)
logging
.
info
(
"Created particle at %s"
,
new_particle
.
coord
inate
s
)
return
new_particle
else
:
print
(
"for x %f and y %f not not possible because Particle exist "
,
x
,
y
)
...
...
@@ -315,7 +315,7 @@ class World:
if
rm_particle
:
self
.
particles
.
remove
(
rm_particle
)
try
:
del
self
.
particle_map_coords
[
rm_particle
.
coords
]
del
self
.
particle_map_coord
inate
s
[
rm_particle
.
coord
inate
s
]
del
self
.
particle_map_id
[
id
]
except
:
pass
...
...
@@ -327,22 +327,22 @@ class World:
else
:
return
False
def
remove_particle_on
(
self
,
coords
):
def
remove_particle_on
(
self
,
coord
inate
s
):
"""
Removes a particle on a give coordinat from to the world database
:param coords: A tupel that includes the x and y coorindates
:param coord
inate
s: A tupel that includes the x and y coorindates
:return: True: Successful removed; False: Unsuccessful
"""
if
coords
in
self
.
particle_map_coords
:
self
.
particles
.
remove
(
self
.
particle_map_coords
[
coords
])
self
.
particle_rm
.
append
(
self
.
particle_map_coords
[
coords
])