diff --git a/examples/hex_ant/app.py b/examples/hex_ant/app.py index 952f391f9..b2636f201 100644 --- a/examples/hex_ant/app.py +++ b/examples/hex_ant/app.py @@ -1,10 +1,9 @@ import matplotlib.pyplot as plt +from agent import AntState from matplotlib.colors import LinearSegmentedColormap, ListedColormap from mesa.visualization import SolaraViz, make_space_component from mesa.visualization.components import PropertyLayerStyle - -from .agent import AntState -from .model import AntForaging +from model import AntForaging plt.rcParams["figure.figsize"] = (10, 10) diff --git a/examples/hex_ant/model.py b/examples/hex_ant/model.py index 5fb769cea..562940bb3 100644 --- a/examples/hex_ant/model.py +++ b/examples/hex_ant/model.py @@ -1,8 +1,7 @@ import mesa +from agent import Ant from mesa.discrete_space import HexGrid -from .agent import Ant - class AntForaging(mesa.Model): """ diff --git a/examples/hex_snowflake/hex_snowflake/app.py b/examples/hex_snowflake/hex_snowflake/app.py new file mode 100644 index 000000000..0e45911fd --- /dev/null +++ b/examples/hex_snowflake/hex_snowflake/app.py @@ -0,0 +1,21 @@ +from hex_snowflake.cell import Cell +from hex_snowflake.model import HexSnowflake +from mesa.visualization import SolaraViz, make_space_component + + +def agent_portrayal(agent): + if agent is None: + return + + if isinstance(agent, Cell): + color = "tab:green" if agent.state == Cell.ALIVE else "tab:grey" + return {"color": color, "size": 20} + + +model = HexSnowflake() + +page = SolaraViz( + model, + components=[make_space_component(agent_portrayal=agent_portrayal)], + name="Hex Snowflake", +) diff --git a/examples/hex_snowflake/hex_snowflake/portrayal.py b/examples/hex_snowflake/hex_snowflake/portrayal.py deleted file mode 100644 index 621baf79c..000000000 --- a/examples/hex_snowflake/hex_snowflake/portrayal.py +++ /dev/null @@ -1,17 +0,0 @@ -def portrayCell(cell): - """This function is registered with the visualization server to be called - each tick to indicate how to draw the cell in its current state. - :param cell: the cell in the simulation - :return: the portrayal dictionary. - """ - if cell is None: - raise AssertionError - return { - "Shape": "hex", - "r": 1, - "Filled": "true", - "Layer": 0, - "x": cell.x, - "y": cell.y, - "Color": "black" if cell.isAlive else "white", - } diff --git a/examples/hex_snowflake/hex_snowflake/server.py b/examples/hex_snowflake/hex_snowflake/server.py deleted file mode 100644 index f00f20c97..000000000 --- a/examples/hex_snowflake/hex_snowflake/server.py +++ /dev/null @@ -1,12 +0,0 @@ -import mesa -from hex_snowflake.model import HexSnowflake -from hex_snowflake.portrayal import portrayCell - -width, height = 50, 50 - -# Make a world that is 50x50, on a 500x500 display. -canvas_element = mesa.visualization.CanvasHexGrid(portrayCell, width, height, 500, 500) - -server = mesa.visualization.ModularServer( - HexSnowflake, [canvas_element], "Hex Snowflake", {"height": height, "width": width} -) diff --git a/examples/hex_snowflake/run.py b/examples/hex_snowflake/run.py index 7a8226474..e69de29bb 100644 --- a/examples/hex_snowflake/run.py +++ b/examples/hex_snowflake/run.py @@ -1,3 +0,0 @@ -from hex_snowflake.server import server - -server.launch(open_browser=True)