Esempio n. 1
0
 def __init__(self,parent,dpi=100.0):
     Canvas.__init__(self,parent,dpi)
     self.has_data = False
     self.sqplot = None
     self.cb = None
     self.colormap = customcolormap.make_colormap("mymap", 1.0, 0.001, 10)
     self.cmaplimits = 2.0
Esempio n. 2
0
    def __init__(self, renderer, max_update_delay=0.2, *args, **keys):
        ''' Inits this canvas.
            Things setupped: background color, default camera, node factory,
            model/view/primitve renderer registries, adapter registry and
            render/update policies.
        '''

        if 'name' not in keys:
            keys['name'] = 'unnamed canvas'

        self.renderer = renderer

        if 'backgroundColor' in keys:
            self.backgroundColor = keys['backgroundColor']
            del keys['backgroundColor']
        else:
            self.backgroundColor = None

        if 'renderPolicy' in keys:
            self.renderPolicy = keys['renderPolicy']
            del keys['renderPolicy']
        else:
            #self.renderPolicy = DefaultRenderPolicy()
            self.renderPolicy = CullingRenderPolicy()

        Canvas.__init__(self, self.renderer, False, None, None, None, None,
                        observables.ObservableLinearTransform2D(), *args,
                        **keys)

        self.camera = observables.ObservableCamera(
            observables.ObservableLinearTransform2D(), name='default camera')
        self.addChild(self.camera)

        self.model_kinds = [
            'Rectangle', 'RoundedRectangle', 'Circle', 'Ellipse', 'Arc',
            'Text', 'Line', 'LineLength', 'Lines', 'LinesList', 'LineSegments',
            'LineSegmentsSeparate', 'Bitmap', 'CubicSpline', 'QuadraticSpline',
            'Polygon', 'PolygonList', 'Arrow', 'AngleArrow'
        ]
        self.primitive_kinds = [
            'Rectangle', 'RoundedRectangle', 'Ellipse', 'Arc', 'Text',
            'LinesList', 'LineSegmentsSeparate', 'Bitmap', 'CubicSpline',
            'QuadraticSpline', 'PolygonList', 'Arrow'
        ]

        self._setupRegistries()
        self._setupNodeFactory()
        self._setupAdapters()

        if 'updatePolicy' in keys:
            self.updatePolicy = keys['updatePolicy']
            del keys['updatePolicy']
        else:
            self.updatePolicy = DefaultUpdatePolicy(self, max_update_delay)

        self.controllers = []

        self.subscribe(self.onDirty, 'attribChanged')
Esempio n. 3
0
 def __init__(self, varname, player_1='human', player_2='random', id=None, width=300, height=300):
     valid_players = ('human', 'random', 'alphabeta')
     if player_1 not in valid_players or player_2 not in valid_players:
         raise TypeError("Players must be one of {}".format(valid_players))
     Canvas.__init__(self, varname, id, width, height)
     self.ttt = TicTacToe()
     self.state = self.ttt.initial
     self.turn = 0
     self.strokeWidth(5)
     self.players = (player_1, player_2)
     self.draw_board()
     self.font("Ariel 30px")
Esempio n. 4
0
 def __init__(self, varname, player_1='human', player_2='random', id=None, width=300, height=300):
     valid_players = ('human', 'random', 'alphabeta')
     if player_1 not in valid_players or player_2 not in valid_players:
         raise TypeError("Players must be one of {}".format(valid_players))
     Canvas.__init__(self, varname, id, width, height)
     self.ttt = TicTacToe()
     self.state = self.ttt.initial
     self.turn = 0
     self.strokeWidth(5)
     self.players = (player_1, player_2)
     self.draw_board()
     self.font("Ariel 30px")
Esempio n. 5
0
 def __init__(self, parent):
     Canvas.__init__(self, parent)
     self.pen_cadre_1 = Pen((0,0,250), 2)
     self.pen_cadre_2 = Pen(width=3)
     self.pen_aiguille_1 = Pen(width=6)
     self.pen_aiguille_2 = Pen(width=5)
     self.pen_aiguille_3 = Pen(width=2, color=(255,0,0))
     
     self.bind(size=self.on_size)
     #self._draw_cadre()
     self.aiguille_draw_op = CombineDrawOperation(self, [])
     self.scheduler = Thread(target=self.schedule)
     self.scheduler.start()
Esempio n. 6
0
    def __init__(self, renderer, max_update_delay = 0.2, *args, **keys):
        ''' Inits this canvas.
            Things setupped: background color, default camera, node factory,
            model/view/primitve renderer registries, adapter registry and
            render/update policies.
        '''
        
        if 'name' not in keys:
            keys['name'] = 'unnamed canvas'

        self.renderer = renderer

        if 'backgroundColor' in keys:
            self.backgroundColor = keys['backgroundColor']
            del keys['backgroundColor']
        else:
            self.backgroundColor = None
        
        if 'renderPolicy' in keys:
            self.renderPolicy = keys['renderPolicy']
            del keys['renderPolicy']
        else:
            #self.renderPolicy = DefaultRenderPolicy()
            self.renderPolicy = CullingRenderPolicy()

        Canvas.__init__(self, self.renderer, False, None, None, None, None, observables.ObservableLinearTransform2D(), *args, **keys)
               
        self.camera = observables.ObservableCamera( observables.ObservableLinearTransform2D(), name = 'default camera' )
        self.addChild( self.camera )
        
        self.model_kinds = [ 'Rectangle', 'RoundedRectangle', 'Circle', 'Ellipse', 'Arc', 'Text', 'Line', 'LineLength', 'Lines', 'LinesList', 'LineSegments', 'LineSegmentsSeparate', 'Bitmap', 'CubicSpline', 'QuadraticSpline', 'Polygon', 'PolygonList', 'Arrow', 'AngleArrow' ]
        self.primitive_kinds = [ 'Rectangle', 'RoundedRectangle', 'Ellipse', 'Arc', 'Text', 'LinesList', 'LineSegmentsSeparate', 'Bitmap', 'CubicSpline', 'QuadraticSpline', 'PolygonList', 'Arrow' ]

        self._setupRegistries()
        self._setupNodeFactory()
        self._setupAdapters()

        if 'updatePolicy' in keys:
            self.updatePolicy = keys['updatePolicy']
            del keys['updatePolicy']
        else:
            self.updatePolicy = DefaultUpdatePolicy( self, max_update_delay )

        self.controllers = []
        
        self.subscribe( self.onDirty, 'attribChanged' )
 def __init__(self,parent,dpi=100.0):
   Canvas.__init__(self,parent,dpi)
   self.pos = None
   self.vel = None
Esempio n. 8
0
        The maze is represented by a matrix with `height` rows and `width` columns,
        each cell in the maze has 4 possible states:

        0: it's a wall
        1: it's in the tree
        2: it's in the path
        3: it's filled (this will not be used until the depth-first search animation)

        Initially all cells are walls. Adjacent cells in the maze are spaced out by one cell.

        mask: must be None or a white/black image instance of PIL's Image class.
              This mask image must preserve the connectivity of the graph,
              otherwise the program will not terminate.
        """
        Canvas.__init__(self, width, height, scale, min_bits, palette, loop)

        def get_mask_pixel(cell):
            if mask is None:
                return True
            else:
                return mask.getpixel(cell) == 255

        self.cells = []
        for y in range(margin, height - margin, 2):
            for x in range(margin, width - margin, 2):
                if get_mask_pixel((x, y)):
                    self.cells.append((x, y))

        def neighborhood(cell):
            x, y = cell
Esempio n. 9
0
 def __init__(self, handle):
     Canvas.__init__(self,0,0,handle)
Esempio n. 10
0
 def __init__(self, sink, enable_cairo_queue=True):
     Canvas.__init__(self, sink)
     self.size = None
     self.enable_cairo_queue = enable_cairo_queue
     self.reset_canvas()
Esempio n. 11
0
 def __init__(self, sink):
     Canvas.__init__(self, sink)
     self.size = None
Esempio n. 12
0
 def __init__(self, sink, enable_cairo_queue = True):
     Canvas.__init__(self, sink)
     self.size = None
     self.enable_cairo_queue = enable_cairo_queue
     self.reset_canvas()
Esempio n. 13
0
    def __init__(self,
                 width,
                 height,
                 margin,
                 scale,
                 min_bits,
                 palette,
                 loop=0,
                 mask=None):
        """
        width, height: size of the maze, should both be odd numbers.
        margin: size of the border of the maze.

        The maze is represented by a matrix with `height` rows and `width` columns,
        each cell in the maze has 4 possible states:

        0: it's a wall
        1: it's in the tree
        2: it's in the path
        3: it's filled (this will not be used until the depth-first search animation)

        Initially all cells are walls. Adjacent cells in the maze are spaced out by one cell.

        mask: must be None or a white/black image instance of PIL's Image class.
              This mask image must preserve the connectivity of the graph,
              otherwise the program will not terminate.
        """
        Canvas.__init__(self, width, height, scale, min_bits, palette, loop)

        def get_mask_pixel(cell):
            if mask is None:
                return True
            else:
                return mask.getpixel(cell) == 255

        self.cells = []
        for y in range(margin, height - margin, 2):
            for x in range(margin, width - margin, 2):
                if get_mask_pixel((x, y)):
                    self.cells.append((x, y))

        def neighborhood(cell):
            x, y = cell
            neighbors = []
            if x >= 2 + margin and get_mask_pixel((x - 2, y)):
                neighbors.append((x - 2, y))
            if y >= 2 + margin and get_mask_pixel((x, y - 2)):
                neighbors.append((x, y - 2))
            if x <= width - 3 - margin and get_mask_pixel((x + 2, y)):
                neighbors.append((x + 2, y))
            if y <= height - 3 - margin and get_mask_pixel((x, y + 2)):
                neighbors.append((x, y + 2))
            return neighbors

        self.graph = {v: neighborhood(v) for v in self.cells}
        # we will look for a path between this start and end.
        self.start = (margin, margin)
        self.end = (width - margin - 1, height - margin - 1)
        self.path = []  # a list holds the path in the loop erased random walk.
        # map distance to color indices.
        self.dist_to_color = lambda d: max(d % (1 << min_bits), 3)
Esempio n. 14
0
 def __init__(self, sink):
     Canvas.__init__(self, sink)
     self.size = None