def __init__(self): vals = getDefaultPosition() x_sc = LinearScale(min=0, max=4) y_sc = LinearScale(min=0, max=8) y_sc.reverse = True x_sc.allow_padding = False y_sc.allow_padding = False # -1 are the empty squares (not in output from network) col_sc = ColorScale(min=-1, max=1, colors=['red', 'white', 'black']) x_ax = Axis(label='X', scale=x_sc) y_ax = Axis(label='Y', scale=y_sc, orientation='vertical') bg = plt.gridheatmap(vals, scales={ 'column': x_sc, 'row': y_sc, 'color': col_sc }) self.board = bg fig = Figure(marks=[bg], axes=[x_ax, y_ax]) fig.min_aspect_ratio = 0.63 # Idfk why this makes it have an aspect ratio around 0.5 but w/e fig.max_aspect_ratio = 0.63 self.fig = fig
def __init__(self): # Setup & Axis stuff... x_sc = LinearScale(min=0, max=8) y_sc = LinearScale(min=0, max=8) x_ax = Axis(label='X', scale=x_sc) y_ax = Axis(label='Y', scale=y_sc, orientation='vertical') y_sc.reverse = True col_sc = ColorScale(min=-1, max=1, colors=['white', 'blue', 'red']) bg = plt.gridheatmap(np.zeros((16, 16)), scales={ 'column': x_sc, 'row': y_sc, 'color': col_sc }) bg.row = np.arange(16) / 2 bg.column = np.arange(16) / 2 self.board = bg fig = Figure(marks=[bg], axes=[x_ax, y_ax]) # Force square. fig.min_aspect_ratio = 1 fig.max_aspect_ratio = 1 # Give random data self.update(np.random.random((8, 4, 4))) self.fig = fig
def __init__(self, canInteract=True): # Setup & Axis stuff... x_sc = LinearScale(min=0, max=8) y_sc = LinearScale(min=0, max=8) y_sc.reverse = True x_ax = Axis(label='X', scale=x_sc) y_ax = Axis(label='Y', scale=y_sc, orientation='vertical') # Display starting position for checkers game. # Colour checkerboard... Extra stuff for alignment to grid. vals = np.zeros((8, 8)) vals[::2, ::2] = -1 vals[1::2, 1::2] = -1 col_sc = ColorScale(colors=['white', 'lightgray']) bg = plt.gridheatmap(vals, scales={ 'column': x_sc, 'row': y_sc, 'color': col_sc }) bg.row = np.arange(8) bg.column = np.arange(8) self.bg = bg # Foreground... # colors of pieces col_sc = ColorScale(colors=['firebrick', 'black']) # Create empty scatter grid. fg = Scatter(x=[], y=[]) fg.scales = {'x': x_sc, 'y': y_sc, 'color': col_sc} fg.color = [] fg.default_size = 550 fg.enable_move = canInteract print(fg.drag_size) fg.drag_size = 0.1 print(fg.drag_size) self.fg = fg fig = Figure(marks=[bg, fg], axes=[x_ax, y_ax]) # Force square. fig.min_aspect_ratio = 1 fig.max_aspect_ratio = 1 # display(fig) self.fig = fig