def set_up(props=None): """ A func to set up run that can also be used by test code. """ global sandpile_env global groups global group_indices pa = get_props(MODEL_NAME, props) width = pa.get('grid_width', DEF_WIDTH) height = pa.get('grid_height', DEF_HEIGHT) groups = [] group_indices = {} for i in range(NUM_GROUPS): groups.append(Composite("Group" + str(i), {"marker": CIRCLE})) group_indices[groups[i].name] = i for y in range(height): for x in range(width): groups[0] += create_grain(x, y) sandpile_env = Env("Sandpile", action=sandpile_action, height=height, width=width, members=groups, attrs={"size": 65, "hide_axes": True, "hide_legend": True}, random_placing=False, props=pa) sandpile_env.attrs["center_agent"] = sandpile_env.get_agent_at(height // 2, width // 2) return sandpile_env, groups, group_indices
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY width = get_prop('grid_width', DEF_WIDTH, execution_key=execution_key) height = (width // 2) + (width % 2) groups = [ Composite(WHITE, {"color": WHITE}, execution_key=execution_key), Composite(BLACK, { "color": BLACK, "marker": SQUARE }, execution_key=execution_key) ] for y in range(height): for x in range(width): groups[W] += create_wolf_cell(x, y, execution_key) wolfram_env = Env(MODEL_NAME, action=wolfram_action, height=height, width=width, members=groups, attrs={ "size": 50, "hide_grid_lines": True, "hide_legend": True }, random_placing=False, execution_key=execution_key) rule_num = get_prop('rule_number', DEF_RULE, execution_key=execution_key) wolfram_env.set_attr("rule_num", rule_num) wolfram_env.set_attr("rule_dict", get_rule(rule_num)) wolfram_env.exclude_menu_item("line_graph") ''' This switch needs to happen before the environment is executed. Using add switch doesn't process the switch until after the environment is executed which breaks the model. ''' top_center_agent = \ wolfram_env.get_agent_at(width // 2, top_row(execution_key)) switch(top_center_agent.name, WHITE, BLACK, execution_key=execution_key) # top row is the "previous" because we just processed it set_env_attr("prev_row_idx", top_row(execution_key), execution_key=execution_key)
def set_up(): """ A func to set up run that can also be used by test code. """ for i in range(NUM_GROUPS): groups.append(Composite("Group" + str(i))) group_indices[groups[i].name] = i for i in range((HEIGHT) * (WIDTH)): groups[0] += create_agent(i) sandpile = Env("A sandpile", action=sandpile_action, members=groups, height=HEIGHT, width=WIDTH) sandpile.attrs["center_agent"] = sandpile.get_agent_at( int(HEIGHT / 2), int(WIDTH / 2)) return (groups, group_indices, sandpile)
def set_up(): """ A func to set up run that can also be used by test code. """ group0 = Composite("Group0", {"color": disp.BLACK}) group1 = Composite("Group1", {"color": disp.MAGENTA}) group2 = Composite("Group2", {"color": disp.BLUE}) group3 = Composite("Group3", {"color": disp.CYAN}) group4 = Composite("Group4", {"color": disp.RED}) group5 = Composite("Group5", {"color": disp.YELLOW}) for i in range((HEIGHT) * (WIDTH)): group0 += create_agent(i) sandpile = Env("A sandpile", action=sandpile_action, members=[group0, group1, group2, group3, group4, group5], height=HEIGHT, width=WIDTH) sandpile.attrs["center_agent"] = sandpile.get_agent_at( HEIGHT / 2, WIDTH / 2) return (group0, group1, group2, group3, group4, group5, sandpile)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ global groups global curr_row global rule_dict global rule_num pa = get_props(MODEL_NAME, props) width = pa.get('grid_width', DEF_WIDTH) rule_num = pa.get('rule_number', DEF_RULE) rule_dict = get_rule(rule_num) height = 0 height = (width // 2) + (width % 2) white = Composite("White", {"color": WHITE}) black = Composite("Black", {"color": BLACK, "marker": SQUARE}) groups = [white, black] for y in range(height): for x in range(width): groups[W] += create_wolf_cell(x, y) wolfram_env = Env("Wolfram Model", action=wolfram_action, height=height, width=width, members=groups, attrs={ "size": 50, "hide_grid_lines": True, "hide_legend": True }, random_placing=False, props=pa) wolfram_env.exclude_menu_item("line_graph") wolfram_env.now_switch(wolfram_env.get_agent_at(width // 2, height - 1), groups[W], groups[B]) curr_row = wolfram_env.get_row_hood(wolfram_env.height - 1) return (wolfram_env, groups, rule_dict)