Commit 6b638d6d authored by Ahmad Reza's avatar Ahmad Reza
Browse files

Renamed the attributes coords to coordinations and alpha to transparency

parent 2b269a47
""" """
TODO: TODO:
1- Order the names based on particles, markers, and tiles and alphabetic 1- Order the names based on particles, markers, and tiles and transparencybetic
2- A new column called round_success 2- A new column called round_success
3- On demand extenstion of the metrics. 3- On demand extenstion of the metrics.
......
...@@ -6,8 +6,8 @@ from lib.swarm_sim_header import * ...@@ -6,8 +6,8 @@ from lib.swarm_sim_header import *
class Marker(matter.Matter): class Marker(matter.Matter):
"""In the classe marker all the methods for the characterstic of a marker is included""" """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""" """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)
...@@ -7,42 +7,42 @@ from lib.swarm_sim_header import * ...@@ -7,42 +7,42 @@ from lib.swarm_sim_header import *
class Matter: class Matter:
"""In the classe marker all the methods for the characterstic of a marker is included""" """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, coordinates, color=black, transparency=1, type=None, mm_size=100):
"""Initializing the marker constructor""" """Initializing the marker constructor"""
self.coords = coords self.coordinates = coordinates
self.color = color_map[color] self.color = color_map[color]
self.__id = str(uuid.uuid4()) self.__id = str(uuid.uuid4())
self.world = world self.world = world
self._memory={} self._memory={}
self.__alpha=alpha self.__transparency=transparency
self.type = type self.type = type
self.memory_limitation = world.config_data.memory_limitation self.memory_limitation = world.config_data.memory_limitation
self.mm_size = mm_size self.mm_size = mm_size
self.modified = False self.modified = False
self.created = 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 :return: None
""" """
if (0 <= alpha <= 1): if (0 <= transparency <= 1):
self.__alpha = round(alpha,2) self.__transparency = round(transparency,2)
elif alpha < 0: elif transparency < 0:
self.__alpha = 0 self.__transparency = 0
elif alpha > 1: elif transparency > 1:
self.__alpha = 1 self.__transparency = 1
self.touch() 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): def read_memory_with(self, key):
""" """
......
This diff is collapsed.
...@@ -85,78 +85,78 @@ def direction_in_range(direction): ...@@ -85,78 +85,78 @@ def direction_in_range(direction):
return direction % 6 return direction % 6
def check_values_are_coordinates(coords_x, coords_y): def check_values_are_coordinates(coordinates_x, coordinates_y):
""" """
Checks if the given coordinates are matching the Checks if the given coordinates are matching the
hexagon coordinates hexagon coordinates
:param coords_x: proposed x coordinate :param coordinates_x: proposed x coordinate
:param coords_y: proposed y coordinate :param coordinates_y: proposed y coordinate
:return: True: Correct x and y coordinates; False: Incorrect coordinates :return: True: Correct x and y coordinates; False: Incorrect coordinates
""" """
if (coords_x / 0.5) % 2 == 0: if (coordinates_x / 0.5) % 2 == 0:
if coords_y % 2 != 0: if coordinates_y % 2 != 0:
return False return False
else: else:
return True return True
else: else:
if coords_y % 2 == 0: if coordinates_y % 2 == 0:
return False return False
else: else:
return True return True
def coords_to_sim(coords): def coordinates_to_sim(coordinates):
return coords[0], coords[1] * math.sqrt(3 / 4) return coordinates[0], coordinates[1] * math.sqrt(3 / 4)
def sim_to_coords(x, y): def sim_to_coordinates(x, y):
return x, round(y / math.sqrt(3 / 4), 0) return x, round(y / math.sqrt(3 / 4), 0)
def get_coords_in_direction(coords, direction): def get_coordinates_in_direction(coordinates, direction):
""" """
Returns the coordination data of the pointed directions Returns the coordination data of the pointed directions
:param coords: particles actual staying coordination :param coordinates: particles actual staying coordination
:param direction: The direction. Options: E, SE, SW, W, NW, or NE :param direction: The direction. Options: E, SE, SW, W, NW, or NE
:return: The coordinaiton of the pointed directions :return: The coordinaiton of the pointed directions
""" """
return coords[0] + x_offset[direction], coords[1] + y_offset[direction] return coordinates[0] + x_offset[direction], coordinates[1] + y_offset[direction]
def global_scanning(matter_map_coords_dict, hop, starting_x, starting_y): def global_scanning(matter_map_coordinates_dict, hop, starting_x, starting_y):
hop_list = [] hop_list = []
if (hop / 2 + starting_x, hop + starting_y) in matter_map_coords_dict: if (hop / 2 + starting_x, hop + starting_y) in matter_map_coordinates_dict:
hop_list.append(matter_map_coords_dict[(hop / 2 + starting_x, hop + starting_y)]) hop_list.append(matter_map_coordinates_dict[(hop / 2 + starting_x, hop + starting_y)])
if (hop + starting_x, starting_y) in matter_map_coords_dict: if (hop + starting_x, starting_y) in matter_map_coordinates_dict:
hop_list.append(matter_map_coords_dict[(hop + starting_x, starting_y)]) hop_list.append(matter_map_coordinates_dict[(hop + starting_x, starting_y)])
if (hop / 2 + starting_x, -hop + starting_y) in matter_map_coords_dict: if (hop / 2 + starting_x, -hop + starting_y) in matter_map_coordinates_dict:
hop_list.append(matter_map_coords_dict[(hop / 2 + starting_x, -hop + starting_y)]) hop_list.append(matter_map_coordinates_dict[(hop / 2 + starting_x, -hop + starting_y)])
if (-hop / 2 + starting_x, -hop + starting_y) in matter_map_coords_dict: if (-hop / 2 + starting_x, -hop + starting_y) in matter_map_coordinates_dict:
hop_list.append(matter_map_coords_dict[(-hop / 2 + starting_x, -hop + starting_y)]) hop_list.append(matter_map_coordinates_dict[(-hop / 2 + starting_x, -hop + starting_y)])
if (-hop + starting_x, starting_y) in matter_map_coords_dict: if (-hop + starting_x, starting_y) in matter_map_coordinates_dict:
hop_list.append(matter_map_coords_dict[(-hop + starting_x, starting_y)]) hop_list.append(matter_map_coordinates_dict[(-hop + starting_x, starting_y)])
if (-hop / 2 + starting_x, hop + starting_y) in matter_map_coords_dict: if (-hop / 2 + starting_x, hop + starting_y) in matter_map_coordinates_dict:
hop_list.append(matter_map_coords_dict[(-hop / 2 + starting_x, hop + starting_y)]) hop_list.append(matter_map_coordinates_dict[(-hop / 2 + starting_x, hop + starting_y)])
for i in range(1, hop): for i in range(1, hop):
if (-hop / 2 + i + starting_x, hop + starting_y) in matter_map_coords_dict: if (-hop / 2 + i + starting_x, hop + starting_y) in matter_map_coordinates_dict:
hop_list.append(matter_map_coords_dict[(-hop / 2 + i + starting_x, hop + starting_y)]) hop_list.append(matter_map_coordinates_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 + (0.5 * i) + starting_x, hop - i + starting_y) in matter_map_coordinates_dict:
hop_list.append( hop_list.append(
matter_map_coords_dict[(hop / 2 + (0.5 * i) + starting_x, hop - i + starting_y)]) matter_map_coordinates_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: if (hop / 2 + (0.5 * i) + starting_x, -hop + i + starting_y) in matter_map_coordinates_dict:
hop_list.append( hop_list.append(
matter_map_coords_dict[(hop / 2 + (0.5 * i) + starting_x, -hop + i + starting_y)]) matter_map_coordinates_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: if (-hop / 2 + i + starting_x, -hop + starting_y) in matter_map_coordinates_dict:
hop_list.append(matter_map_coords_dict[(-hop / 2 + i + starting_x, -hop + starting_y)]) hop_list.append(matter_map_coordinates_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 - (0.5 * i) + starting_x, -hop + i + starting_y) in matter_map_coordinates_dict:
hop_list.append( hop_list.append(
matter_map_coords_dict[(-hop / 2 - (0.5 * i) + starting_x, -hop + i + starting_y)]) matter_map_coordinates_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: if (-hop / 2 - (0.5 * i) + starting_x, hop - i + starting_y) in matter_map_coordinates_dict:
hop_list.append( hop_list.append(
matter_map_coords_dict[(-hop / 2 - (0.5 * i) + starting_x, hop - i + starting_y)]) matter_map_coordinates_dict[(-hop / 2 - (0.5 * i) + starting_x, hop - i + starting_y)])
return hop_list return hop_list
...@@ -169,28 +169,28 @@ def generating_random_spraded_particles (world, max_size_particle): ...@@ -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()) y = random.randrange(-world.get_world_y_size(), world.get_world_y_size())
if y % 2 == 1: if y % 2 == 1:
x = x + 0.5 x = x + 0.5
if (x, y) not in world.tile_map_coords: if (x, y) not in world.tile_map_coordinates:
world.add_particle(x, y) world.add_particle(x, y)
else: else:
print(" x and y ", (x, y)) print(" x and y ", (x, y))
print("Max Size of created Particle", len(world.particles)) print("Max Size of created Particle", len(world.particles))
def create_particle_in_line(world, max_size_particle, start_coords): def create_particle_in_line(world, max_size_particle, start_coordinates):
if start_coords[0] % 1 != 0: if start_coordinates[0] % 1 != 0:
start_i = int(start_coords[0] - 0.5) start_i = int(start_coordinates[0] - 0.5)
for i in range(start_i, start_i+max_size_particle): 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_coordinates[1])
else: else:
for i in range(int(start_coords[0] + 1), int(start_coords[0] + 1) + max_size_particle): for i in range(int(start_coordinates[0] + 1), int(start_coordinates[0] + 1) + max_size_particle):
world.add_particle(i, start_coords[1]) world.add_particle(i, start_coordinates[1])
def create_particle_in_square(world, max_size_particle, start_coords): def create_particle_in_square(world, max_size_particle, start_coordinates):
for y in range(start_coords[1], round(max_size_particle/2)): for y in range(start_coordinates[1], round(max_size_particle/2)):
for x in range(start_coords[0], round(max_size_particle/2)): for x in range(start_coordinates[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) 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): ...@@ -292,7 +292,7 @@ def move_to_dest_step_by_step(particle, destiny):
:param 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 :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.coordinates[0], particle.coordinates[1], destiny.coordinates[0], destiny.coordinates[1])
if particle.matter_in(next_dir): if particle.matter_in(next_dir):
particle.get_matter_in(next_dir) particle.get_matter_in(next_dir)
return particle.get_matter_in(next_dir) return particle.get_matter_in(next_dir)
......
...@@ -6,9 +6,9 @@ from lib.swarm_sim_header import * ...@@ -6,9 +6,9 @@ from lib.swarm_sim_header import *
class Tile(matter.Matter): class Tile(matter.Matter):
"""In the classe marker all the methods for the characterstic of a marker is included""" """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""" """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 self.__isCarried = False
def get_tile_status(self): def get_tile_status(self):
...@@ -28,46 +28,46 @@ class Tile(matter.Matter): ...@@ -28,46 +28,46 @@ class Tile(matter.Matter):
""" """
self.__isCarried = status self.__isCarried = status
def take(self, coords=0): def take(self, coordinates=0):
""" """
Takes the tile on the given coordinate if it is not taken Takes the tile on the given coordinate if it is not taken
:param coords: Coordination of tile that should be taken :param coordinates: Coordination of tile that should be taken
:return: True: Successful taken; False: Cannot be taken or wrong Coordinates :return: True: Successful taken; False: Cannot be taken or wrong Coordinates
""" """
if coords==0: if coordinates==0:
if self.__isCarried == False: if self.__isCarried == False:
if self.coords in self.world.tile_map: if self.coordinates in self.world.tile_map:
del self.world.tile_map_coords[self.coords] del self.world.tile_map_coordinates[self.coordinates]
self.__isCarried = True self.__isCarried = True
self.set_alpha(0.5) self.set_transparency(0.5)
self.touch() self.touch()
return True return True
else: else:
return False return False
else: else:
if self.__isCarried == False: if self.__isCarried == False:
if self.coords in self.world.tile_map_coords: if self.coordinates in self.world.tile_map_coordinates:
del self.world.tile_map_coords[self.coords] del self.world.tile_map_coordinates[self.coordinates]
self.__isCarried = True self.__isCarried = True
self.coords = coords self.coordinates = coordinates
self.set_alpha(0.5) self.set_transparency(0.5)
self.touch() self.touch()
return True return True
else: else:
return False return False
def drop_me(self, coords): def drop_me(self, coordinates):
""" """
Drops the tile Drops the tile
:param coords: the given position :param coordinates: the given position
:return: None :return: None
""" """
self.world.tile_map_coords[coords] = self self.world.tile_map_coordinates[coordinates] = self
self.coords = coords self.coordinates = coordinates
self.__isCarried = False self.__isCarried = False
self.set_alpha(1) self.set_transparency(1)
self.touch() self.touch()
def touch(self): def touch(self):
......
...@@ -32,17 +32,17 @@ print_frame_stats = False ...@@ -32,17 +32,17 @@ print_frame_stats = False
# simulation parameters # simulation parameters
rounds_per_second = 10 rounds_per_second = 10
# tile_alpha = 0.6 # tile_transparency = 0.6
particle_alpha = 1 particle_transparency = 1
marker_alpha = 1 marker_transparency = 1
def coords_to_sim(coords): def coordinates_to_sim(coordinates):
return coords[0], coords[1] * math.sqrt(3/4) return coordinates[0], coordinates[1] * math.sqrt(3/4)
def sim_to_coords(x, y): def sim_to_coordinates(x, y):
return x, round(y / math.sqrt(3/4), 0) return x, round(y / math.sqrt(3/4), 0)
...@@ -142,7 +142,6 @@ class VisWindow(pyglet.window.Window): ...@@ -142,7 +142,6 @@ class VisWindow(pyglet.window.Window):
self.video_mode = False self.video_mode = False
self.draw() self.draw()
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers): def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
if buttons & mouse.LEFT: if buttons & mouse.LEFT:
self.view.drag(dx, dy) self.view.drag(dx, dy)
...@@ -155,16 +154,16 @@ class VisWindow(pyglet.window.Window): ...@@ -155,16 +154,16 @@ class VisWindow(pyglet.window.Window):
def on_mouse_press(self, x, y, button, modifiers): def on_mouse_press(self, x, y, button, modifiers):
if modifiers & key.MOD_CTRL: if modifiers & key.MOD_CTRL:
# get correct coordinates # get correct coordinates
sim_coords = window_to_sim(x, y, self.view) sim_coordinates = window_to_sim(x, y, self.view)
coords_coords = sim_to_coords(sim_coords[0], sim_coords[1]) coordinates_coordinates = sim_to_coordinates(sim_coordinates[0], sim_coordinates[1])
rounded_coords=0 rounded_coordinates=0
if coords_coords[1]%2!=0: if coordinates_coordinates[1]%2!=0:
rounded_coords = round(coords_coords[0],0) + 0.5 rounded_coordinates = round(coordinates_coordinates[0],0) + 0.5
else: else:
rounded_coords =round(coords_coords[0], 0) rounded_coordinates =round(coordinates_coordinates[0], 0)
if (rounded_coords,coords_coords[1]) not in self.world.tile_map_coords: if (rounded_coordinates,coordinates_coordinates[1]) not in self.world.tile_map_coordinates:
# add tile and vertices # add tile and vertices
if self.world.add_tile_vis(rounded_coords, coords_coords[1]): if self.world.add_tile_vis(rounded_coordinates, coordinates_coordinates[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), 4 * len(self.world.tiles))
#self.tile_vertex_list.resize(4 * len(self.world.tiles), 8 * 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) 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): ...@@ -173,7 +172,7 @@ class VisWindow(pyglet.window.Window):
self.update_tiles(True) self.update_tiles(True)
else: else:
# delete tile # delete tile
self.world.remove_tile_on((rounded_coords,coords_coords[1])) self.world.remove_tile_on((rounded_coordinates,coordinates_coordinates[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), 4 * len(self.world.tiles))
self.update_tiles(True) self.update_tiles(True)
...@@ -295,7 +294,7 @@ class VisWindow(pyglet.window.Window): ...@@ -295,7 +294,7 @@ class VisWindow(pyglet.window.Window):
def update_tile(self, i, tile): def update_tile(self, i, tile):
weird = 256 / 220 weird = 256 / 220
pos = coords_to_sim(tile.coords) pos = coordinates_to_sim(tile.coordinates)
x = pos[0] x = pos[0]
y = pos[1] y = pos[1]
...@@ -307,18 +306,18 @@ class VisWindow(pyglet.window.Window): ...@@ -307,18 +306,18 @@ class VisWindow(pyglet.window.Window):
texRight = 1 / 8 texRight = 1 / 8
texBottom = 5 / 8 texBottom = 5 / 8
texTop = 6 / 8 texTop = 6 / 8
#tile_alpha = 1 #tile_transparency = 1
else: else:
texLeft = 7 / 8 texLeft = 7 / 8
texRight = 1 # 8/8 texRight = 1 # 8/8
texBottom = 4 / 8 texBottom = 4 / 8
texTop = 5 / 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, self.tile_vertex_list.tex_coords[8 * i: 8 * i + 8] = [texLeft, texBottom, texRight, texBottom, texRight, texTop,
texLeft, 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): def init_particle_vertex_list(self):
self.particle_vertex_list = self.particle_vertex_list = pyglet.graphics.vertex_list \ self.particle_vertex_list = self.particle_vertex_list = pyglet.graphics.vertex_list \
...@@ -344,7 +343,7 @@ class VisWindow(pyglet.window.Window): ...@@ -344,7 +343,7 @@ class VisWindow(pyglet.window.Window):
def update_particle(self, i, particle): def update_particle(self, i, particle):
weird = 256 / 220 weird = 256 / 220
pos = coords_to_sim(particle.coords) pos = coordinates_to_sim(particle.coordinates)
x = pos[0] x = pos[0]
y = pos[1] y = pos[1]
...@@ -357,17 +356,17 @@ class VisWindow(pyglet.window.Window): ...@@ -357,17 +356,17 @@ class VisWindow(pyglet.window.Window):
texRight = 1 / 8 texRight = 1 / 8
texBottom = 7 / 8 texBottom = 7 / 8
texTop = 6 / 8 texTop = 6 / 8
#particle.set_alpha(0.5) #particle.set_transparency(0.5)
else: else:
texLeft = 0 / 8 texLeft = 0 / 8
texRight = 1 / 8 texRight = 1 / 8
texBottom = 0 / 8 texBottom = 0 / 8
texTop = 1 / 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, self.particle_vertex_list.tex_coords[8 * i: 8 * i + 8] = [texLeft, texBottom, texRight, texBottom,
texRight, texTop, texLeft, texTop] 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