def _get_rows_of_plants(types): """ Types is array of (row, spacing, plant) tuples """ plants = [] for row, spacing, plant_type in types: for col in range(spacing // 2 + 2, NUM_X_STEPS - spacing // 2, spacing): plants.append(Plant.from_preset(plant_type, col, row)) return plants
def _get_random_plants_of_type(types): plants = [] for plant_type, num in types: x_locations = np.random.randint(3, NUM_X_STEPS - 3, (num, 1)) y_locations = np.random.randint(3, NUM_Y_STEPS - 3, (num, 1)) locations = np.hstack((x_locations, y_locations)) plants.extend([ Plant.from_preset(plant_type, row, col) for row, col in locations ]) return plants
def _get_grid_of_plants(types): count = 0 plants = [] for row in range(0, NUM_Y_STEPS - 1, 10): for col in range(0, NUM_X_STEPS - 1, 10): plants.append(Plant.from_preset(types[0][0], col, row)) count += 1 if count >= types[0][1]: types.pop(0) count = 0 return plants
def _get_random_plants(plant_types, plants_per_color, seed=None): if seed is not None: np.random.seed(seed) plants = [] for name in plant_types: x_locations = np.random.randint(1, NUM_X_STEPS - 1, (plants_per_color, 1)) y_locations = np.random.randint(1, NUM_Y_STEPS - 1, (plants_per_color, 1)) locations = np.hstack((x_locations, y_locations)) plants.extend( [Plant.from_preset(name, row, col) for row, col in locations]) return plants
def _read_plants_from_csv(path): plants = [] with open(path) as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for row in csv_reader: if line_count == 0: line_count += 1 else: coord = literal_eval(row[2]) x = round(coord[0] * NUM_X_STEPS / 1920) y = round(NUM_Y_STEPS - coord[1] * NUM_Y_STEPS / 1080) plants.append(Plant.from_preset(row[1], x, y)) line_count += 1 return plants