def _draw_title(self, gc, label=None, axis_offset=None): """ Draws the title for the axis. """ if label is None: title_label = Label(text=self.title, font=self.title_font, color=self.title_color, rotate_angle=self.title_angle) else: title_label = label # get the _rotated_ bounding box of the label tl_bounds = array(title_label.get_bounding_box(gc), float64) text_center_to_corner = -tl_bounds/2.0 # which axis are we moving away from the axis line along? axis_index = self._major_axis.argmin() if self.title_spacing != 'auto': axis_offset = self.title_spacing if (self.title_spacing) and (axis_offset is None ): if not self.ticklabel_cache: axis_offset = 25 else: axis_offset = max([l._bounding_box[axis_index] for l in self.ticklabel_cache]) * 1.3 offset = (self._origin_point+self._end_axis_point)/2 axis_dist = self.tick_out + tl_bounds[axis_index]/2.0 + axis_offset offset -= self._inside_vector * axis_dist offset += text_center_to_corner gc.translate_ctm(*offset) title_label.draw(gc) gc.translate_ctm(*(-offset)) return
class Map: def __init__(self, window_width, window_height, map_file): self.krakow_map = pyglet.image.load(map_file) self.krakow_map.anchor_x = self.krakow_map.width // 2 self.krakow_map.anchor_y = self.krakow_map.height // 2 self.label = Label(window_width) def draw(self, window_width, window_height, x, y): self.krakow_map.blit(x, y) self.label.draw(window_width)
class List: def __init__(self, x, y, w, title, entries=None): self.x = x self.y = y self.w = w self.h = len(entries) + 2 x += 2 w -= 4 self.tlabel = Label(x, y, w, title, align=Label.ALIGN_CENTER, fg=COLOR_LIGHT_GREY) self.labels = [] y += 1 self.lx = x self.ly = y self.lw = w if entries != None: self.add_entries(entries) def add_entries(self, entries): y = self.ly for e in entries: l = Label(self.lx, y, self.lw, e) self.labels.append(l) y += 1 self.ly = y def add_entry(self, entry): l = Label(self.lx, self.ly, self.lw, entry) self.ly += 1 def draw(self, gc): gc.set_color_fg(COLOR_LIGHT_GREY) gc.draw_border(1, self.x, self.y, self.w - 2, self.h - 2) self.tlabel.draw(gc) for l in self.labels: l.draw(gc) def get_label(self, i): return self.labels[i]
class List: def __init__(self, x, y, w, title, entries=None): self.x = x self.y = y self.w = w self.h = len(entries) + 2 x += 2 w -= 4 self.tlabel = Label(x,y,w,title, align=Label.ALIGN_CENTER, fg=COLOR_LIGHT_GREY) self.labels = [] y += 1 self.lx = x self.ly = y self.lw = w if entries != None: self.add_entries(entries) def add_entries(self, entries): y = self.ly for e in entries: l = Label(self.lx,y,self.lw,e) self.labels.append(l) y += 1 self.ly = y def add_entry(self, entry): l = Label(self.lx,self.ly,self.lw,entry) self.ly += 1 def draw(self, gc): gc.set_color_fg(COLOR_LIGHT_GREY) gc.draw_border(1, self.x, self.y, self.w-2, self.h-2) self.tlabel.draw(gc) for l in self.labels: l.draw(gc) def get_label(self, i): return self.labels[i]
class SpecialistPanel(Clickable): def __init__(self, x, y, specialist_instance, selectable=False): self.surface = Surface((200, 60)) self.specialist = specialist_instance self.s_type = Label(0, 0, specialist.mapping[specialist_instance.s_type]) self.s_exp = Label(0, 40, "") self.s_level = Label(0, 20, "") self.selectable = selectable self.selected = False self.x = x self.y = y self.w = 200 self.h = 60 def draw(self, screen): self.surface.fill(0x000000) pygame.draw.rect(self.surface, 0xb7f315 if self.selected else 0xffffff, Rect(0, 0, 198, 58), 2) self.s_exp.set_text("Exp: %s/%s" % (self.specialist.experience, self.specialist.level_up_exp)) self.s_level.set_text("Level: %s" % self.specialist.level) self.s_type.draw(self.surface) self.s_exp.draw(self.surface) self.s_level.draw(self.surface) screen.blit(self.surface, (self.x, self.y)) def is_pressed(self, x, y, button): if not self.selectable: return False if x < self.x: return False elif x > self.x + self.w: return False elif y < self.y: return False elif y > self.y + self.h: return False self.selected = not self.selected return True
def overlay(self, component, gc, view_bounds=None, mode="normal"): """ Draws the box overlaid on another component. Overrides AbstractOverlay. """ if not self.visible: return # draw the label on a transparent box. This allows us to draw # different shapes and put the text inside it without the label # filling a rectangle on top of it label = Label(text=self.text, font=self.font, bgcolor="transparent", margin=5) width, height = label.get_width_height(gc) valign, halign = self.align if self.alternate_position: x, y = self.alternate_position if valign == "u": y += self.padding else: y -= self.padding + height if halign == "r": x += self.padding else: x -= self.padding + width else: if valign == "u": y = component.y2 - self.padding - height else: y = component.y + self.padding if halign == "r": x = component.x2 - self.padding - width else: x = component.x + self.padding # attempt to get the box entirely within the component if x + width > component.width: x = max(0, component.width-width) if y + height > component.height: y = max(0, component.height - height) elif y < 0: y = 0 # apply the alpha channel color = self.bgcolor_ if self.bgcolor != "transparent": if self.alpha: color = list(self.bgcolor_) if len(color) == 4: color[3] = self.alpha else: color += [self.alpha] with gc: gc.translate_ctm(x, y) gc.set_line_width(self.border_size) gc.set_stroke_color(self.border_color_) gc.set_fill_color(color) # draw a rounded rectangle x = y = 0 end_radius = 8.0 gc.begin_path() gc.move_to(x + end_radius, y) gc.arc_to(x + width, y, x + width, y + end_radius, end_radius) gc.arc_to(x + width, y + height, x + width - end_radius, y + height, end_radius) gc.arc_to(x, y + height, x, y, end_radius) gc.arc_to(x, y, x + width + end_radius, y, end_radius) gc.draw_path() label.draw(gc)
class TD: def __init__(self): pygame.init() self.total_rows = TOTAL_ROWS self.WIDTH = WIDTH self.gap = GAP self.screen = pygame.display.set_mode( (self.WIDTH + 200, self.WIDTH + 45)) pygame.display.set_caption("TD Pokémon") self.movement = 0 self.clock = pygame.time.Clock() self.money = 20000 self.hp = 10 self.wave = 1 self.sLabel = Label(self.screen, 30, 810) self.pathway = [ Path(self.screen, 1, 1, self.gap, self.total_rows), Path(self.screen, 2, 1, self.gap, self.total_rows), Path(self.screen, 3, 1, self.gap, self.total_rows), Path(self.screen, 4, 1, self.gap, self.total_rows), Path(self.screen, 4, 2, self.gap, self.total_rows), Path(self.screen, 4, 3, self.gap, self.total_rows), Path(self.screen, 3, 3, self.gap, self.total_rows), Path(self.screen, 2, 3, self.gap, self.total_rows), Path(self.screen, 1, 3, self.gap, self.total_rows), Path(self.screen, 1, 4, self.gap, self.total_rows), Path(self.screen, 1, 5, self.gap, self.total_rows), Path(self.screen, 2, 5, self.gap, self.total_rows), Path(self.screen, 2, 6, self.gap, self.total_rows), Path(self.screen, 3, 6, self.gap, self.total_rows), Path(self.screen, 4, 6, self.gap, self.total_rows), ] self.pathway[0].image = pygame.image.load("./images/Start.jpg") self.pathway[0].image = pygame.transform.scale(self.pathway[0].image, (GAP, GAP)) self.pathway[-1].image = pygame.image.load("./images/End.jpg") self.pathway[-1].image = pygame.transform.scale( self.pathway[-1].image, (GAP, GAP)) self.grid = [ [ Node(self.screen, 0, 0, self.gap, self.total_rows), Node(self.screen, 1, 0, self.gap, self.total_rows), Node(self.screen, 2, 0, self.gap, self.total_rows), Node(self.screen, 3, 0, self.gap, self.total_rows), Node(self.screen, 4, 0, self.gap, self.total_rows), Node(self.screen, 5, 0, self.gap, self.total_rows), Node(self.screen, 6, 0, self.gap, self.total_rows), Node(self.screen, 7, 0, self.gap, self.total_rows) ], [ Node(self.screen, 0, 1, self.gap, self.total_rows), self.pathway[0], self.pathway[1], self.pathway[2], self.pathway[3], Node(self.screen, 5, 1, self.gap, self.total_rows), Node(self.screen, 6, 1, self.gap, self.total_rows), Node(self.screen, 7, 1, self.gap, self.total_rows), ], [ Node(self.screen, 0, 2, self.gap, self.total_rows), Node(self.screen, 1, 2, self.gap, self.total_rows), Node(self.screen, 2, 2, self.gap, self.total_rows), Node(self.screen, 3, 2, self.gap, self.total_rows), self.pathway[4], Node(self.screen, 5, 2, self.gap, self.total_rows), Node(self.screen, 6, 2, self.gap, self.total_rows), Node(self.screen, 7, 2, self.gap, self.total_rows) ], [ Node(self.screen, 0, 3, self.gap, self.total_rows), self.pathway[8], self.pathway[5], self.pathway[6], self.pathway[7], Node(self.screen, 5, 3, self.gap, self.total_rows), Node(self.screen, 6, 3, self.gap, self.total_rows), Node(self.screen, 7, 3, self.gap, self.total_rows) ], [ Node(self.screen, 0, 4, self.gap, self.total_rows), self.pathway[9], Node(self.screen, 2, 4, self.gap, self.total_rows), Node(self.screen, 3, 4, self.gap, self.total_rows), Node(self.screen, 4, 4, self.gap, self.total_rows), Node(self.screen, 5, 4, self.gap, self.total_rows), Node(self.screen, 6, 4, self.gap, self.total_rows), Node(self.screen, 7, 4, self.gap, self.total_rows) ], [ Node(self.screen, 0, 5, self.gap, self.total_rows), self.pathway[10], self.pathway[11], Node(self.screen, 3, 5, self.gap, self.total_rows), Node(self.screen, 4, 5, self.gap, self.total_rows), Node(self.screen, 5, 5, self.gap, self.total_rows), Node(self.screen, 6, 5, self.gap, self.total_rows), Node(self.screen, 7, 5, self.gap, self.total_rows) ], [ Node(self.screen, 0, 6, self.gap, self.total_rows), Node(self.screen, 1, 6, self.gap, self.total_rows), self.pathway[12], self.pathway[13], self.pathway[14], Node(self.screen, 5, 6, self.gap, self.total_rows), Node(self.screen, 6, 6, self.gap, self.total_rows), Node(self.screen, 7, 6, self.gap, self.total_rows) ], [ Node(self.screen, 0, 7, self.gap, self.total_rows), Node(self.screen, 1, 7, self.gap, self.total_rows), Node(self.screen, 2, 7, self.gap, self.total_rows), Node(self.screen, 3, 7, self.gap, self.total_rows), Node(self.screen, 4, 7, self.gap, self.total_rows), Node(self.screen, 5, 7, self.gap, self.total_rows), Node(self.screen, 6, 7, self.gap, self.total_rows), Node(self.screen, 7, 7, self.gap, self.total_rows) ], ] self.towers = [] self.enemies = [] self.icons = [] self.towerChoose = 'Taubsi' self.towerPrices = {'Taubsi': 80, 'Glumanda': 140, 'Dratini': 190} self.taubsiIMG = TaubsiIMG(self.screen, self.towerPrices['Taubsi'], 820, 20) self.glumandaIMG = GlumandaIMG(self.screen, self.towerPrices['Glumanda'], 820, 205) self.dratiniIMG = DratiniIMG(self.screen, self.towerPrices['Dratini'], 820, 390) self.icons.append(self.taubsiIMG) self.icons.append(self.glumandaIMG) self.icons.append(self.dratiniIMG) self.move_enemy_event = pygame.USEREVENT + 1 self.spawn_enemy_event = pygame.USEREVENT + 2 self.tower_fire_event = pygame.USEREVENT + 3 self.move_bullets_event = pygame.USEREVENT + 4 self.multiplier = 1 self.spawns = 0 pygame.time.set_timer(self.move_bullets_event, 100) pygame.time.set_timer(self.move_enemy_event, round(100 / self.multiplier)) pygame.time.set_timer(self.spawn_enemy_event, round(2800 / self.multiplier)) pygame.time.set_timer(self.tower_fire_event, 200) self.wave1 = [ Mauzi(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2), Mauzi(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2), Mauzi(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2), Mauzi(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2), Mauzi(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2), Mauzi(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2), Mauzi(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2), Smogmog(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2) ] # self.wave2 = [Mauzi(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2), Mauzi(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2), # Mauzi(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2), Smogmog(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2), # Smogmog(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2), Mauzi(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2), # Mauzi(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2), Smogmog(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2)] # self.wave3 = [Woingenau(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2), Woingenau(self.screen, self.pathway[0].x+GAP//2, self.pathway[0].y+GAP//2)] # self.wave4 = [] # self.wave5 = [] while True: # if self.hp > 0: # self.clock.tick(40) self.check_events() self.update_screen() def check_events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == self.tower_fire_event: self.tower_fire() if event.type == self.move_bullets_event: self.move_bullets() if event.type == self.move_enemy_event: self.move_enemy() if event.type == self.spawn_enemy_event: self.spawn_enemy() if event.type == pygame.MOUSEBUTTONUP: pos = pygame.mouse.get_pos() if pos[0] < 800: row, col = self.get_clicked_pos(pos) tile = self.grid[col][row] if event.button == 1: if tile.__str__() == 'Node': if tile.rImage == "./images/BG1.jpg": if not tile.tower and self.money >= self.towerPrices[ self.towerChoose]: if self.towerChoose == 'Taubsi': Ntower = Taubsi(self.screen, row, col) elif self.towerChoose == 'Glumanda': Ntower = Glumanda( self.screen, row, col) elif self.towerChoose == 'Dratini': Ntower = Dratini(self.screen, row, col) self.towers.append(Ntower) tile.tower = Ntower self.money -= Ntower.price elif tile.tower and self.money >= tile.tower.upgradeCost[ tile.tower.level - 2] and tile.tower.level < tile.tower.maxLevel: self.money -= tile.tower.upgradeCost[ tile.tower.level - 2] tile.tower.upgrade() else: if tile.__str__() == 'Node' and tile.tower: otower = tile.tower self.money += round(otower.price * .8) self.towers.remove(otower) tile.tower = None if pos[0] > 820 and pos[0] < 820 + 150: if pos[1] > self.taubsiIMG.rect.y and pos[ 1] < self.taubsiIMG.rect.y + self.taubsiIMG.rect.height: self.towerChoose = self.taubsiIMG.name elif pos[1] > self.glumandaIMG.rect.y and pos[ 1] < self.glumandaIMG.rect.y + self.glumandaIMG.rect.height: self.towerChoose = self.glumandaIMG.name elif pos[1] > self.dratiniIMG.rect.y and pos[ 1] < self.dratiniIMG.rect.y + self.dratiniIMG.rect.height: self.towerChoose = self.dratiniIMG.name def get_clicked_pos(self, pos): y, x = pos row = y // GAP col = x // GAP return row, col def update_screen(self): self.screen.fill((181, 168, 220)) for row in self.grid: for tile in row: tile.draw() # for i in range(TOTAL_ROWS): # pygame.draw.line(self.screen, GREY, (0, i * self.gap), (self.WIDTH, i * self.gap)) # for j in range(TOTAL_ROWS): # pygame.draw.line(self.screen, GREY, (j * self.gap, 0), (j * self.gap, self.WIDTH)) for tower in self.towers: for bullet in tower.bullets: bullet.draw() tower.draw(self.money) for enemy in self.enemies: enemy.draw() for icon in self.icons: icon.draw(self.towerChoose) self.sLabel.draw( f'HP: {self.hp} Wave: {self.wave} Money: {self.money}$') pygame.display.update() def move_enemy(self): rEnemy = None for enemy in self.enemies: if enemy.i == len(self.pathway) - 1: rEnemy = enemy else: nPath = self.pathway[enemy.i + 1] if enemy.rect.centerx < nPath.x + GAP // 2: enemy.rect.centerx += enemy.speed if enemy.rect.centerx > nPath.x + GAP // 2: enemy.rect.centerx -= enemy.speed if enemy.rect.centery < nPath.y + GAP // 2: enemy.rect.centery += enemy.speed elif enemy.rect.centery > nPath.y + GAP // 2: enemy.rect.centery -= enemy.speed if abs(enemy.rect.centerx - nPath.x - GAP // 2) <= 40 and abs( enemy.rect.centery - nPath.y - GAP // 2) <= 40: enemy.i += 1 if rEnemy: self.enemies.remove(rEnemy) self.hp -= 1 if self.hp < 1: sys.exit() def spawn_enemy(self): if self.spawns == 10: self.multiplier += .3 self.spawns = 0 self.money += 20 self.wave += 1 self.spawns += 1 if self.wave == 1: if len(self.wave1) > 0: spawn = self.wave1[0] spawn.max_hp *= self.multiplier spawn.hp *= self.multiplier self.enemies.append(spawn) self.wave1.remove(spawn) elif self.wave > 1: rEnemy = random.randint(1, 3) if rEnemy == 1: spawn = Mauzi(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2) spawn.max_hp *= self.multiplier spawn.hp *= self.multiplier self.enemies.append(spawn) if rEnemy == 2: spawn = Smogmog(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2) spawn.max_hp *= self.multiplier spawn.hp *= self.multiplier self.enemies.append(spawn) if rEnemy == 3: spawn = Woingenau(self.screen, self.pathway[0].x + GAP // 2, self.pathway[0].y + GAP // 2) spawn.max_hp *= self.multiplier spawn.hp *= self.multiplier self.enemies.append(spawn) def tower_fire(self): for tower in self.towers: for enemy in self.enemies: if abs(tower.rect.centerx - enemy.rect.centerx) < tower.range and abs( tower.rect.centery - enemy.rect.centery) < tower.range: if len(tower.bullets) < tower.ammo: tower.bullets.append( Bullet(self.screen, tower.rect.centerx, tower.rect.centery, int(enemy.rect.centerx), int(enemy.rect.centery), tower.bsize, tower.bulletIMG)) break def move_bullets(self): for tower in self.towers: for bullet in tower.bullets: dx = bullet.x - bullet.ex dy = bullet.y - bullet.ey d = abs(dx) + abs(dy) if d > tower.speed - 1: dyp = abs(dy) / d if dx > 0: bullet.x -= round(tower.speed * (1 - dyp)) elif dx < 0: bullet.x += round(tower.speed * (1 - dyp)) if dy > 0: bullet.y -= round(tower.speed * (dyp)) if dy < 0: bullet.y += round(tower.speed * (dyp)) else: tower.bullets.remove(bullet) hitBullet = None for enemy in self.enemies: if abs(bullet.x - enemy.rect.centerx) < enemy.rect.height / 2 and abs( bullet.y - enemy.rect.centery) < enemy.rect.height / 2: hitBullet = bullet enemy.hp -= tower.damage if enemy.hp <= 0: self.enemies.remove(enemy) self.money += enemy.bounty if self.wave == 1: if len(self.enemies) == 0 and len( self.wave1) == 0: self.wave += 1 try: if hitBullet: tower.bullets.remove(hitBullet) except: pass
def overlay(self, component, gc, view_bounds=None, mode="normal"): """ Draws the box overlaid on another component. Overrides AbstractOverlay. """ if not self.visible: return # draw the label on a transparent box. This allows us to draw # different shapes and put the text inside it without the label # filling a rectangle on top of it label = Label(text=self.text, font=self.font, bgcolor="transparent", color=self.text_color, max_width=self.max_text_width, margin=5) width, height = label.get_width_height(gc) valign, halign = self.align if self.alternate_position: x, y = self.alternate_position if valign == "u": y += self.padding else: y -= self.padding + height if halign == "r": x += self.padding else: x -= self.padding + width else: if valign == "u": y = component.y2 - self.padding - height else: y = component.y + self.padding if halign == "r": x = component.x2 - self.padding - width else: x = component.x + self.padding # attempt to get the box entirely within the component x_min, y_min, x_max, y_max = (component.x, component.y, component.x + component.width, component.y + component.height) if x + width > x_max: x = max(x_min, x_max - width) if y + height > y_max: y = max(y_min, y_max - height) elif y < y_min: y = y_min # apply the alpha channel color = self.bgcolor_ if self.bgcolor != "transparent": if self.alpha: color = list(self.bgcolor_) if len(color) == 4: color[3] = self.alpha else: color += [self.alpha] with gc: gc.translate_ctm(x, y) gc.set_line_width(self.border_size) gc.set_stroke_color(self.border_color_) gc.set_fill_color(color) if self.border_visible: # draw a rounded rectangle. x = y = 0 end_radius = 8.0 gc.begin_path() gc.move_to(x + end_radius, y) gc.arc_to(x + width, y, x + width, y + end_radius, end_radius) gc.arc_to(x + width, y + height, x + width - end_radius, y + height, end_radius) gc.arc_to(x, y + height, x, y, end_radius) gc.arc_to(x, y, x + width + end_radius, y, end_radius) gc.draw_path() label.draw(gc)
class Vertex(Element): def __init__(self, id, center, canvas, color=VERTEX_FILL_COLOR): Element.__init__(self, id) self.center = center self.color = color self.canvas = canvas self.degree = 0 self.edgeGroups = [] self.label = Label( id, id, Point(center.x + VERTEX_RADIUS, center.y - VERTEX_RADIUS)) self.degree = 0 self.degreeLabel = Label( id, self.degree, Point(center.x - VERTEX_RADIUS, center.y - VERTEX_RADIUS), 'red') def __str__(self): #return "Vertex(id: {}, cid: {}, center: {}, degree: {}, color: {}, edges: {})".format(self.id, self.cid, self.center, self.degree, self.color, self.edgeCids) return str(self.id) def setId(self, newId): self.id = newId self.label.labelText = newId def setDegree(self, newDegree): self.degree = newDegree self.degreeLabel.labelText = newDegree def addEdge(self, edge): for group in self.edgeGroups: if group.addEdge(edge): print("Adding to existing group") if edge.isLoop: self.setDegree(self.degree + 2) else: self.setDegree(self.degree + 1) self.update() return newGroup = EdgeGroup(0, edge.start, edge.end, self.canvas) newGroup.addEdge(edge) self.edgeGroups.append(newGroup) if edge.isLoop: self.setDegree(self.degree + 2) else: self.setDegree(self.degree + 1) self.update() def delEdge(self, edge): for group in self.edgeGroups: if group.delEdge(edge): if edge.isLoop: self.setDegree(self.degree - 2) else: self.setDegree(self.degree - 1) self.update() return True return False def delGroup(self, group): for g in self.edgeGroups: if (g.start is group.start and g.end is group.end ) or (g.start is group.end and g.end is group.start) and len( g.edges) == 0: self.edgeGroups.remove(g) def draw(self): self.canvas.delete(self.cid) self.cid = self.canvas.create_oval(self.center.x - VERTEX_RADIUS, self.center.y - VERTEX_RADIUS, self.center.x + VERTEX_RADIUS, self.center.y + VERTEX_RADIUS, fill=self.color, activefill=CIRCLE_ACTIVE_FILL_COLOR) self.label.draw(self.canvas) self.degreeLabel.draw(self.canvas) for group in self.edgeGroups: group.draw() def update(self): self.canvas.coords(self.cid, self.center.x - VERTEX_RADIUS, self.center.y - VERTEX_RADIUS, self.center.x + VERTEX_RADIUS, self.center.y + VERTEX_RADIUS) self.label.point = Point(self.center.x + VERTEX_RADIUS, self.center.y - VERTEX_RADIUS) self.label.update(self.canvas) self.degreeLabel.point = Point(self.center.x - VERTEX_RADIUS, self.center.y - VERTEX_RADIUS) self.degreeLabel.update(self.canvas) for group in self.edgeGroups: group.update() def delete(self): cids_to_delete = [] Element.delete(self, self.canvas) self.label.delete(self.canvas) self.degreeLabel.delete(self.canvas) for group in self.edgeGroups: cids_to_delete += group.edge_cids() group.delete(self) return cids_to_delete