Пример #1
0
 def item(self, name, pos, hpr0=HPR(0, 0, 0), size=0.2, action=None):
     if action == "bounce":
         item = rectangle(pos,
                          pos + P3(0, size, 0),
                          pos + P3(0, 0, size),
                          texture=name,
                          color=Color(0, 0, 0, 0),
                          hpr=hpr0)
     elif action == "spin":
         item = rectangle(pos,
                          pos + P3(0, size, 0),
                          pos + P3(0, 0, size),
                          texture=name,
                          color=Color(0, 0, 0, 0))
     elif action == "both":
         item = rectangle(pos,
                          pos + P3(0, size, 0),
                          pos + P3(0, 0, size),
                          texture=name,
                          color=Color(0, 0, 0, 0))
     else:
         item = rectangle(pos,
                          pos + P3(0, size, 0),
                          pos + P3(0, 0, size),
                          texture=name,
                          color=Color(0, 0, 0, 0))
     items.append(item)
     return items[-1]
Пример #2
0
    def _add_command(self, cmd_type, generic_params, **kwargs):
        # Set defaults
        Cmd = {'linewidth': 1.0, 'color': Color.Color("red")}

        # TBD - Check generic parameters against known params

        # Override
        for k in generic_params:
            if generic_params[k] is None:
                continue
            if k == 'color':
                Cmd[k] = Color.Color(generic_params[k])
            else:
                Cmd[k] = generic_params[k]

        # Set type
        Cmd['type'] = cmd_type

        # Set specific params
        for k in kwargs:
            if kwargs[k] is None:
                continue
            Cmd[k] = kwargs[k]

        self.display_list.append(Cmd)
Пример #3
0
    def __init__(self,
                 left=0,
                 top=0,
                 width=0,
                 height=0,
                 bg_color=None,
                 fg_color=None):
        self.left = left or 0
        self.top = top or 0
        self.width = width or 0
        self.height = height or 0
        try:
            self.rect = Rect(self.left, self.top, self.width, self.height)
        except TypeError:
            logger.debug('Invalid Rect: left=%r, top=%r, width=%r, height=%r',
                         left, top, width, height)

        self.osd = osd.get_singleton()

        self.label = None
        self.icon = None
        self.surface = None
        self.bg_surface = None
        self.bg_image = None

        self.parent = None

        self.children = []
        self.enabled = 1
        self.visible = 1
        self.selected = 0

        self.rect = pygame.Rect(0, 0, 0, 0)

        self.refresh_abs_position()

        self.rect.width = self.width
        self.rect.height = self.height
        self.bg_color = bg_color
        self.fg_color = fg_color

        self.event_context = None

        style = skin.get_singleton().get_popupbox_style(self)
        self.content_layout, self.background_layout = style

        self.skin_info_widget = self.content_layout.types['widget']
        self.skin_info_font = self.skin_info_widget.font

        self.h_margin = self.content_layout.spacing
        self.v_margin = self.content_layout.spacing

        ci = self.content_layout.types['widget'].rectangle
        self.bg_color = self.bg_color or Color(ci.bgcolor)
        self.fg_color = self.fg_color or Color(ci.color)

        self.set_v_align(Align.NONE)
        self.set_h_align(Align.NONE)
Пример #4
0
    def render(self, graph):
        ''' this function renders the mandelbrot into the graph, using the
        parameters specified in the data boxes. If the input value is wrong
        the box will turn red
        '''

        # gather the user inputs and check validity
        minx = self.data_boxes.get("x min")
        maxx = self.data_boxes.get("x max")
        miny = self.data_boxes.get("y min")
        maxy = self.data_boxes.get("y max")
        it = self.data_boxes.get("max iterations")

        # this user inputs are strings so they will always be in a valid
        # format.
        # yet they are keys into dictonaries, so if the key is missng
        # the error handling is inside the next body
        mode = self.data_boxes.data_boxes["mode"].entry.get()
        colormap = self.data_boxes.data_boxes["colormap"].entry.get()

        print("start rendering...")
        print("max iteration: " + str(it))

        # run the render
        correct_format = [
            True if v is not None else False
            for v in [minx, maxx, miny, maxy, it]
        ]

        if any(correct_format):
            color_matrix = None
            # this will try to render the mandelbrot, if the mode or the
            # colormaps are wrong it will turn the boxes red
            try:
                bounds = Mandelbrot.Boundaries(graph.width, graph.height, minx,
                                               maxx, miny, maxy)
                self.mandelbrot = Mandelbrot.Mandelbrot(
                    bounds, it, mode, colormap)
                color_matrix = self.mandelbrot.get_color_matrix()

            except Mandelbrot.KeyErrorMode:
                self.data_boxes.data_boxes["mode"].set_color(
                    Color.Color(255, 0, 0))

            except Mandelbrot.KeyErrorColormap:
                self.data_boxes.data_boxes["colormap"].set_color(
                    Color.Color(255, 0, 0))

            if color_matrix is not None:
                graph.update_image(color_matrix)
                graph.draw()
                print("rendering done")
Пример #5
0
    def __init__(self,
                 path,
                 radius=10,
                 center_x=0,
                 center_y=0,
                 center_z=0,
                 is_hide=False):
        self.vertexes = []
        self.triangles = []

        self.center = Vector3(0, 0, 0)
        self.set_center(center_x, center_y, center_z)
        self.proceed_vector = Vector3(0, 0, 0)

        self.face_color = Color(0.0, 0.0, 0.0, 1.0)
        self.is_hide = is_hide

        # objファイル読み込み
        lines = read_file_line(path)
        vertexes = vertex_list(lines)
        triangles = triangle_list(lines)

        # 頂点座標
        for vertex in vertexes:
            x = vertex[0]
            y = vertex[1]
            z = vertex[2]
            self.add_vertex(Vertex(x, y, z))

        # 三角形を生成する
        for triangle in triangles:
            # 頂点x,y,z座標の配列を格納する
            self.add_triangle(Triangle(triangle))
Пример #6
0
    def read_csv(self):
        # method reads the colors.csv file into local variables

        # delete current color data
        del self.__colors[:]
        del self.__color_names[:]

        # open colors.csv
        csv_file = self.__def_name
        file = open(csv_file, "r")

        # read color label, exclusivity, hsv min, and hsv max values from color
        # file and store data in local vars
        for line in file:
            line = line.strip()
            csv_line = line.split(",")
            name = csv_line[0]
            hsv_min = [int(csv_line[1]), int(csv_line[2]), int(csv_line[3])]
            hsv_max = [int(csv_line[4]), int(csv_line[5]), int(csv_line[6])]

            exclusive = None
            if csv_line[7] == "FALSE":
                exclusive = False

            elif csv_line[7] == "TRUE":
                exclusive = True

            self.__color_names.append(name)
            new_Obj = color.Color(name, hsv_min, hsv_max, exclusive)
            self.__colors.append(new_Obj)

        file.close()
Пример #7
0
 def delete_node(self, node):
     c = Color.Color()
     if not node or node == self.nil:
         return
     if node.leftChild == self.nil or node.rightChild == self.nil:
         y_node = node
     else:
         y_node = node.rightChild
         while y_node.leftChild != self.nil:
             y_node = y_node.leftChild
     if y_node.leftChild != self.nil:
         x = y_node.leftChild
     else:
         x = y_node.rightChild
     x._parent = y_node.parent
     if y_node.parent:
         if y_node == y_node.parent.leftChild:
             y_node.parent._leftChild = x
         else:
             y_node.parent._rightChild = x
     else:
         self._root = x
     if y_node != node:
         node._data = y_node.data
     if y_node.color == c.BLACK:
         self._delete_fix(x)
Пример #8
0
 def _add_fix(self, node):  # восстановление свойств красно-черного дерева
     c = Color.Color()
     while node.parent.color:
         u = self._uncle(node)
         if u.color:
             node.parent._color = c.BLACK
             u._color = c.BLACK
             self._grandfather(node)._color = c.RED
             node = self._grandfather(node)
         else:
             if node.parent == node.parent.parent.leftChild:
                 if node == node.parent.rightChild:
                     node = node.parent
                     self._turn_left(node)
                 node.parent._color = c.BLACK
                 self._grandfather(node)._color = c.RED
                 self._turn_right(self._grandfather(node))
             else:
                 if node == node.parent.leftChild:
                     node = node.parent
                     self._turn_right(node)
                 node.parent._color = c.BLACK
                 self._grandfather(node)._color = c.RED
                 self._turn_left(self._grandfather(node))
     self.root._color = c.BLACK
Пример #9
0
    def __init__(self,
                 left=0,
                 top=0,
                 width=0,
                 height=0,
                 bg_color=None,
                 fg_color=None):

        self.osd = osd.get_singleton()

        self.label = None
        self.icon = None
        self.surface = None
        self.bg_surface = None
        self.bg_image = None

        self.parent = None

        self.children = []
        self.enabled = 1
        self.visible = 1
        self.selected = 0

        self.left = left
        self.top = top
        self.width = width
        self.height = height
        self.bg_color = bg_color
        self.fg_color = fg_color

        self.event_context = None

        style = skin.get_singleton().get_popupbox_style(self)
        self.content_layout, self.background_layout = style

        self.skin_info_widget = self.content_layout.types['widget']
        self.skin_info_font = self.skin_info_widget.font

        self.h_margin = self.content_layout.spacing
        self.v_margin = self.content_layout.spacing

        ci = self.content_layout.types['widget'].rectangle
        self.bg_color = self.bg_color or Color(ci.bgcolor)
        self.fg_color = self.fg_color or Color(ci.color)

        self.set_v_align(Align.NONE)
        self.set_h_align(Align.NONE)
Пример #10
0
 def __init__(self, data):  # инициализация узла
     c = Color.Color()
     """setters"""
     self._data = data  # Некие данные, хранимые в узле. В данной реализации - целые числа
     self._color = c.BLACK  # Цвет узла: False = BLACK, True = RED
     self._leftChild = None
     self._rightChild = None
     self._parent = None  # Родитель узла
Пример #11
0
 def gradient(start, stop, steps):
     
     dRed = (stop.r - start.r)/ (steps-1)
     dGrn = (stop.g - start.g)/ (steps-1)
     dBlu = (stop.b - start.b)/ (steps-1)
     return list(
             map(lambda n: Color.Color( (n * dRed) + start.r,
                                  (n * dGrn) + start.g,
                                  (n * dBlu) + start.b).__str__(), range(steps)))
Пример #12
0
 def create(params):
     ls = params['ls']
     col = Color(params['color'][0], params['color'][1], params['color'][2],
                 params['color'][3])
     minam = params['min_amount']
     samplertype = params['sampler']
     samplenum = params['num_samples']
     sampler = eval('%s(%d)' % (samplertype, samplenum))
     return AmbientOccluder(sampler, ls, col, minam)
Пример #13
0
def ground(x, y, image, rotation):
    #return rectangle(P3(x,y+rotation,0), P3(x+rotation,y+1,0), P3(x+1,y,0), color = Color(240,240,240,rotation))
    col = 100 + (100 * rotation)
    #print col
    # the checkerboard coloring doesn't work. is there a bug in the color interpolation code?
    return rectangle(P3(x, y + rotation, 0),
                     P3(x + rotation, y + 1, 0),
                     P3(x + (1 + rotation) % 2, y, 0),
                     texture=image,
                     color=Color(col, col, col))
Пример #14
0
 def create(params):
     ls = params['ls']
     d = Vector3(params['direction'][0], params['direction'][1],
                 params['direction'][2])
     col = Color(params['color'][0], params['color'][1], params['color'][2],
                 params['color'][3])
     shadow = False
     if 'shadow' in params:
         shadow = params['shadow'] == 1
     return DirectionalLight(shadow, d, ls, col)
Пример #15
0
 def create(params):
     ls = params['ls']
     pos = Vector3(params['position'][0], params['position'][1],
                   params['position'][2])
     col = Color(params['color'][0], params['color'][1], params['color'][2],
                 params['color'][3])
     shadow = False
     if 'shadow' in params:
         shadow = params['shadow'] == 1
     return PointLight(shadow, pos, ls, col)
Пример #16
0
    def __init__(self,
                 region_surface=None,
                 left=None,
                 top=None,
                 width=300,
                 height=160,
                 bg_color=None,
                 fg_color=None,
                 border=None,
                 bd_color=None,
                 bd_width=None,
                 show_h_scrollbar=None,
                 show_v_scrollbar=None):

        self.show_h_scrollbar = show_h_scrollbar
        self.show_v_scrollbar = show_v_scrollbar

        Container.__init__(self,
                           'widget',
                           left,
                           top,
                           width,
                           height,
                           bg_color,
                           fg_color,
                           border=border,
                           bd_color=bd_color,
                           bd_width=bd_width)

        self.internal_h_align = Align.NONE
        self.internal_v_align = Align.NONE

        if self.show_h_scrollbar != 0 and not self.show_h_scrollbar:
            self.show_h_scrollbar = 1
        if self.show_v_scrollbar != 0 and not self.show_v_scrollbar:
            self.show_v_scrollbar = 1

        self.set_surface(region_surface)
        self.x_scroll_interval = 25
        self.y_scroll_interval = 25
        self.h_margin = 2
        self.v_margin = 2

        self.v_scrollbar = Scrollbar(self, 'vertical')
        self.add_child(self.v_scrollbar)
        self.h_scrollbar = Scrollbar(self, 'horizontal')
        self.add_child(self.h_scrollbar)

        self.filler = self.osd.Surface(
            (self.v_scrollbar.thickness, self.h_scrollbar.thickness), 0, 32)
        filler_c = Color((0, 0, 0, 255))
        fc_c = filler_c.get_color_sdl()
        fc_a = filler_c.get_alpha()
        self.filler.fill(fc_c)
        self.filler.set_alpha(fc_a)
Пример #17
0
	def __init__(self, name = "tunnel", fogName = "distanceFog", axis = "Y", direction = "+", scale = 1.0, tunnelTime = 2, positionX = 0, positionY = 0, positionZ = 0, fogIntensity = .8, fogColorR = 255, fogColorG = 255, fogColorB = 255, tunnelImage="tunnel/tunnel.png", tunnelModel="tunnel/tunnel", numSegments="4", relTunnelLength="50", segScale1=".155", segScale2=".155", segscale3=".305"):
		if direction == "-":
			direction = -1
		elif direction == "+":
			direction = 1
		else:
			print "Unknown direction. Assuming negative."
			direction = -1
		#First, set the fog.
		self.fog = Fog(fogName)
		#color it.
		self.fog.setColor=Color(r = fogColorR, g = fogColorG, b = fogColorB)
		#Intensity.
		self.fog.setExpDensity=(fogIntensity)
		#And parent it to the render.
		#Fog is needed so hat you can't see the tunnel end.
		render.setFog(self.fog)

		#Copypasted from tutorial and modified.
    		#Creates the list [None, None, None, None]
		##As far as I can tell, this is used to loop the tunnels and easily reference all 4.
    		self.tunnel = [None for i in range(numSegments)]
		##Texture it.
		tex = loader.loadTexture(findTexture(tunnelImage))

    		for x in range(numSegments):
      			#Load a copy of the tunnel
      			self.tunnel[x] = loader.loadModel(tunnelModel)
         		selftunnel[x].setTexture(tex, 1)
			##Changeme, need to figure out how to retexture
     			#The front segment needs to be attached to render
			##So it actually gets rendered.
     			if x == 0: self.tunnel[x].reparentTo(render)
     			#The rest of the segments parent to the previous one, so that by moving
     			#the front segement, the entire tunnel is moved
			##For easy chaining.
     			else:   self.tunnel[x].reparentTo(self.tunnel[x-1])
   			#We have to offset each segment by its length so that they stack onto
    			#each other. Otherwise, they would all occupy the same space.
			###! Check these values!
			if axis == "Z":
				self.tunnel[x].setHPR(0,0,0)
				self.tunnel[x].setPos(0, 0, direction*relTunnelLength)
			elif axis == "Y":
				self.tunnel[x].setHPR(-pi,0,0)
				self.tunnel[x].setPos(0, direction*relTunnelLength, 0)
			elif axis == "X":
				self.tunnel[x].setHPR(pi,0,0)
				self.tunnel[x].setPos(direction*relTunnelLength, 0, 0)
			else:
				print "Invalid direction. Not uppercase?"
				print "Defaulting to Y"
				self.tunnel[x].setHPR(-pi,0,0)
		self.contTunnel()
Пример #18
0
    def update(self, turtle):
        """Update the drawing of a turtle according to the turtle object."""
        item = self.items[turtle]
        vertices = [(v.x, v.y) for v in turtle.getshape()]

        self.canvas.coords(item, sum(vertices, ()))
        if self.dragging == turtle:
            style = {'width': 1, 'outline': Color(0.000000, 0.000000, 0.000000), 'fill': Color(0.000000, 0.000000, 0.000000)}
            self.canvas.itemconfigure(item, **style)
        else:
            self.canvas.itemconfigure(item, **turtle.style)
Пример #19
0
 def writeToFile(self, file):
     try:
         last = file.memo['material']
         if last == self: return
     except KeyError:
         pass
     try:
         color = self.attr['diffuse_color']
     except KeyError:
         color = Color((1., 1., 1.))
     file.writeString('color change rgb 35 ' + str(color) + '\n')
     file.memo['material'] = self
Пример #20
0
 def get_enter(self):
     self.reset()
     try:
         item = self.entry.get()
         self.value = float(item)
         return True
     except ValueError:
         # in case is wrong color the background of the box red
         self.set_color(Color.Color(255, 0, 0))
         self.value = None
         return False
     return False
Пример #21
0
    def get_color_mapped(self, value):
        if self.matlib_map:
            cmap_value = self.colormap(value)
            val = lambda i: int(cmap_value[i] * 255)
            color = Color.Color(val(0), val(1), val(2))
            return color

        elif self.colormap == "red":
            v = int(255 * value)
            color = Color.Color(255, 255 - v, 255 - v)
            return color

        elif self.colormap == 'blue':
            v = int(255 * value)
            color = Color.Color(255 - v, 255 - v, 255)
            return color

        elif self.colormap == "black":
            return Color.Color(0, 0, 0)

        elif self.colormap == "yellow":
            v = int(value * 255)
            color = Color.Color(255, v, 0)
            return color
 def __init__(self):
     self.selected = False
     self.highlighted = False
     self.copyOf = None
     self.deltaCenter = None
     self.graphicsItemsList = []
     self._name = ""
     self._parentItem = None
     self.mouseMoveDelta = None
     self._color = Color(0, 0, 200)
     self.defaultPen = QPen(self._color, 2, Qt.SolidLine, Qt.RoundCap)
     self.normalPen = self.defaultPen
     self.selectedPen = QPen(Qt.magenta, 3, Qt.SolidLine, Qt.RoundCap)
     self.highLightPen = QPen(Qt.blue, 4, Qt.SolidLine, Qt.RoundCap)
     self._currentPen = self.normalPen
     self._zIndex = 1
     self._id = 0
Пример #23
0
    def draw_rectangle(self):

        half_w = self.inputs.get("width") / 2
        half_h = self.inputs.get("height") / 2

        x_clicked = self.center[0]
        y_clicked = self.center[1]

        x1 = x_clicked - half_w
        y1 = y_clicked - half_h
        x2 = x_clicked + half_w
        y2 = y_clicked + half_h

        x1 = int(self.graph_coords_x.get(x1))
        x2 = int(self.graph_coords_x.get(x2))
        y1 = int(self.graph_coords_y.get(y1))
        y2 = int(self.graph_coords_y.get(y2))

        self.graph.draw_rectangle((x1, y1, x2, y2), Color.Color(255, 0, 0))
Пример #24
0
    def displayImage(self, config, grad):
        window = Tk()
        img = PhotoImage(width=config.pixels, height=config.pixels)
        gradient = GradientFactory.makeGradient(grad, config)
        self.paint(config, img, gradient)

        # Display the image on the screen
        canvas = Canvas(window,
                        width=config.pixels,
                        height=config.pixels,
                        bg=Color.Color(255, 225, 225))
        canvas.pack()
        canvas.create_image((config.pixels / 2, config.pixels / 2),
                            image=img,
                            state="normal")

        # Save the image as a PNG
        img.write(config.name + ".png")
        print(f"Wrote image {config.name}.png")
        mainloop()
Пример #25
0
    def convert_to_color_matrix(self):
        ''' converts the solution matrix in a serie of "Color" elements
        '''
        print("calculating color map...")
        bgcolor = Color.Color(0, 0, 0)
        color_matrix = Matrix.Matrix(self.width, self.height, bgcolor)

        self.mandel_solution.normalize01()

        for i in range(self.mandel_solution.width):
            for j in range(self.mandel_solution.height):
                value = self.mandel_solution.get(i, j).res
                # if is not in the mandelbrot then use a color map
                # else paint it black
                if not self.mandel_solution.get(i, j).in_set:
                    color = self.color_function.get_color(value)
                else:
                    color = self.inset_color_function.get_color(value)
                color_matrix.set(i, j, color)

        return color_matrix
Пример #26
0
 def add_node(self, node):  # добавление узла node в дерево
     c = Color.Color()
     par = self.nil
     ch = self.root
     while ch != self.nil:
         par = ch
         if node.data < ch.data:
             ch = ch.leftChild
         else:
             ch = ch.rightChild
     node._parent = par
     if par == self.nil:
         self._root = node
     elif node.data < par.data:
         par._leftChild = node
     else:
         par._rightChild = node
     node._leftChild = self.nil
     node._rightChild = self.nil
     node._color = c.RED
     self._add_fix(node)
Пример #27
0
    def __init__(self,
                 parent,
                 orientation,
                 thickness=10,
                 left=None,
                 top=None,
                 width=None,
                 height=None,
                 bg_color=None,
                 fg_color=None,
                 border=None,
                 bd_color=None,
                 bd_width=1):

        if orientation != "vertical" and orientation != "horizontal":
            raise TypeError, 'orientation'

        GUIObject.__init__(self, left, top, width, height)

        self.orientation = orientation
        self.bg_color = bg_color
        self.fg_color = fg_color
        self.thickness = thickness
        self.border = border
        self.bd_color = bd_color
        self.bd_width = bd_width

        if not self.bg_color:
            if self.skin_info_widget.rectangle.bgcolor:
                self.bg_color = Color(self.skin_info_widget.rectangle.bgcolor)
            else:
                self.bg_color = Color(self.osd.default_bg_color)

        if not self.fg_color:
            if self.skin_info_widget.font.color:
                self.fg_color = Color(self.skin_info_widget.font.color)
            else:
                self.fg_color = Color(self.osd.default_fg_color)

        if not self.bd_color:
            if self.skin_info_widget.rectangle.color:
                self.bd_color = Color(self.skin_info_widget.rectangle.color)
            else:
                self.bd_color = Color(self.osd.default_fg_color)

        if not self.border:
            self.border = Border(self, Border.BORDER_FLAT, self.bd_color,
                                 self.bd_width)
Пример #28
0
  def start(self):

    # GCompris initialisation
    self.gcomprisBoard.level=1
    self.gcomprisBoard.maxlevel=1
    self.gcomprisBoard.sublevel=0
    self.gcomprisBoard.number_of_sublevel=0

    gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())

    # Create our rootitem. We put each canvas item in it so at the end we
    # only have to kill it. The canvas deletes all the items it contains automaticaly.
    self.rootitem = goocanvas.Group(
      parent =  self.gcomprisBoard.canvas.get_root_item())

    self.doc = Document(self)

    # initialisation
    self.draw_tools()
    self.draw_animtools()

    self.doc.timeline.draw()
    if self.gcomprisBoard.mode == 'draw':
      self.doc.timeline.hide()

    self.color_rootitem = goocanvas.Group(
      parent =  self.gcomprisBoard.canvas.get_root_item())
    self.color = Color(self.color_rootitem, self.drawing_area)
    self.color.draw()

    self.draw_drawing_area()
    self.draw_playing_area()

    gcompris.bar_set(gcompris.BAR_JOURNAL)
    gcompris.bar_location(10, -1, 0.6)

    if gcompris.sugar_detected():
      journal_file = gcompris.sugar_load()
      if journal_file:
        fles.doc.file_to_anim(journal_file)
Пример #29
0
 def _delete_fix(self, node):
     c = Color.Color()
     while node.color == c.BLACK and node != self.root:
         b = self._brother(node)
         if b.color == c.RED:
             b._color = c.BLACK
             node.parent._color = c.RED
             self._turn_left(
                 node.parent
             ) if node == node.parent.leftChild else self._turn_right(
                 node.parent)
             b = self._brother(node)
         if b.leftChild.color == c.BLACK and b.rightChild.color == c.BLACK:
             b._color = c.RED
             node = node.parent
         else:
             if node == node.parent.leftChild:
                 if b.rightChild.color == c.BLACK:
                     b.leftChild._color = c.BLACK
                     b._color = c.RED
                     self._turn_right(b)
                     b = self._brother(node)
             else:
                 if b.leftChild.color == c.BLACK:
                     b.rightChild._color = c.BLACK
                     b._color = c.RED
                     self._turn_left(b)
                     b = self._brother(node)
         b._color = node.parent.color
         node.parent._color = c.BLACK
         if node == node.parent.leftChild:
             b.rightChild._color = c.BLACK
             self._turn_left(node.parent)
         else:
             b.leftChild._color = c.BLACK
             self._turn_right(node.parent)
         node = self.root
     node._color = c.BLACK
Пример #30
0
    def __init__(self, rootf, width, height):

        self.rootf = rootf

        self.width = width
        self.height = height

        # create a canvas with a green background
        bgcolor = Color.Color(0, 255, 125)
        self.canvas = Canvas(rootf,
                             width=width,
                             height=height,
                             bg=bgcolor.getcs(),
                             bd=0,
                             relief="ridge",
                             highlightthickness=0)

        # append the photoimage to the root so it doesn't get
        # garbage colloected
        self.rootf.image = PhotoImage(width=width, height=height)
        self.image = rootf.image

        self.ob_ids = []