示例#1
0
def swiss_flag(n_rows=10, n_cols=10):
    red = (255, 0, 0)
    white = (255, 255, 255)

    screen = BlockGrid(n_cols, n_rows, fill=(255, 0, 0))
    screen.lines_on = False
    screen[2:8, 4:6] = white
    screen[4:6, 2:8] = white
    return screen
def calcNResGrid(resList, anchors, rad):
    """
    Makes a visualization using ipython blocks of the number resources in each location in a world. 
    resList is a list of strings indicating which resources to place in the world.
    Anchors is a list of tuples denoting where to anchor the circles. 
    Rad is an int indicating the radius of the circles.
    """
    world = []
    grid = BlockGrid(args.worldSize, args.worldSize)
    for i in range(args.worldSize):
        world.append([])
        for j in range(args.worldSize):
            world[i].append(0)

    for i in range(args.worldSize):
        for j in range(args.worldSize):
            for k in range(len(anchors)):
                if (dist((i,j), anchors[k])) <= rad-1:
                    world[i][j] += 1
    
    entropy = 0
    niches = {}
    for i in range(args.worldSize):
        for j in range(args.worldSize):
            arr = np.zeros((1,1,3))
            if float(world[i][j]) != 0:
                arr[0,0,0] = (float(world[i][j]/10.0)*.6)
            else:
                arr[0,0,0] = 0
                
            arr[0,0,1] = 1
            arr[0,0,2] = 1
            rgb = matplotlib.colors.hsv_to_rgb(arr)
            grid[i,j].red = rgb[0,0,0]*255
            grid[i,j].green = rgb[0,0,1]*255
            grid[i,j].blue = rgb[0,0,2]*255

    grid.lines_on = False
    return grid
def calcGrid(resList, anchors, rad):
    """
    Makes a visualization using ipython blocks of the locations of each resource in resList in a world. Anchors is a list of tuples
    denoting where to anchor the circles. Rad is and int indicating the radius of the circles.
    """
    world = []
    grid = BlockGrid(args.worldSize, args.worldSize)
    for i in range(args.worldSize):
        world.append([])
        for j in range(args.worldSize):
            world[i].append(set())

    for i in range(args.worldSize):
        for j in range(args.worldSize):
            for k in range(len(anchors)):
                if (dist((i,j), anchors[k])) <= rad-1:
                    world[i][j].add(resList[k][3:-1])
    
    entropy = 0
    niches = {}
    for i in range(args.worldSize):
        for j in range(args.worldSize):
            greenVal = 0.0
            blueVal = 0.0
            redVal = 0.0
            colorDict = {"AND":(255, 0, 0), "OR":(0, 255, 0), "ORN":(0,0,255), "ANDN":(255, 255, 0), "XOR":(255,0,255), "NOR":(0, 255, 255), "NOT":(255, 155, 0), "NAND":(255, 255, 255)}
            for res in world[i][j]:
                redVal += colorDict[res][0]
                greenVal += colorDict[res][1]
                blueVal += colorDict[res][2]
            if len(world[i][j]) > 0:
                redVal/=len(world[i][j])
                greenVal /= len(world[i][j])
                blueVal /= len(world[i][j])
            grid[i,j].red = redVal
            grid[i,j].green = greenVal
            grid[i,j].blue = blueVal
    grid.lines_on = False
    return grid