import random from mesa.visualization.modules import CanvasGrid from mesa.visualization.ModularVisualization import ModularServer from ForkliftModel import ForkliftModel from ForkliftAgent import ForkliftAgent from PatchAgent import PatchAgent from PatchType import PatchType colors = [ 'blue', 'cyan', 'orange', 'yellow', 'magenta', 'purple', '#103d3e', '#9fc86c', '#b4c2ed', '#31767d', '#31a5fa', '#ba96e0', '#fef3e4', '#6237ac', '#f9cacd', '#1e8123' ] def agent_portrayal(agent): if isinstance(agent, ForkliftAgent): portrayal = {"Shape": "image.png", "scale": 1.0, "Layer": 0} if isinstance(agent, PatchAgent): color = colors[0] if agent.type == PatchType.dropOff: portrayal = {"Shape": "truck.png", "scale": 1.0, "Layer": 0} elif agent.type == PatchType.pickUp: portrayal = {"Shape": "okB00mer.png", "scale": 1.0, "Layer": 0} else: color = colors[random.randrange(13)+3] portrayal = {"Shape": "rect", "Filled": "true", "Layer": 0, "Color": color, "w": 1, "h": 1} return portrayal base = 512 gridWidth = 10 gridHeight = 10 scale = base/gridWidth grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale*gridWidth, scale*gridHeight) server = ModularServer(ForkliftModel, [grid], "Automatyczny Wózek Widłowy", {"width": gridHeight, "height": gridWidth}) server.port = 8888 server.launch()