glVertex2f(x2, y1d) else: glColor3f(0, 0, 0) glVertex2f(x1, y1) glColor3f(*GATHERED_COLOR) glVertex2f(x1, y2) glVertex2f(x2, y2) glColor3f(0, 0, 0) glVertex2f(x2, y1) glEnd() def byte_to_py(self, byte): return int(self.byte_to_relative_y(byte) * self.height) def byte_to_relative_y(self, byte): return float(byte) / self.torrent_length def handle_segment_waveform_value(self, segment, value): segment.waveform.appendleft(value) def finished(self): if len(self.gatherer.pieces()) == 1: piece = self.gatherer.pieces()[0] return piece.begin == 0 and piece.end == self.torrent_length else: return False visualizer.run(Waves)
self.safe_width = int(self.width * (1 - APPEND_MARGIN - PREPEND_MARGIN)) self.prepend_margin_width = int(self.width * PREPEND_MARGIN) self.files = {} self.segments = {} self.y_scope = DynamicScope(padding=1) def render(self): for peer in self.peers.values(): peer.update() if len(self.files) > 0: self.y_scope.update() self.draw_gathered_segments() self.draw_branches() def draw_gathered_segments(self): for f in self.files.values(): f.render() def draw_branches(self): for peer in self.peers.values(): peer.draw() def added_file(self, f): self.y_scope.put(f.filenum) def filenum_to_y_coord(self, filenum): return self.y_scope.map(filenum) * self.height if __name__ == '__main__': visualizer.run(Puzzle)
glLineWidth(1) glEnable(GL_LINE_SMOOTH) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glColor3f(1,1,1) self.plot() def draw_path(self, points): glBegin(GL_LINE_STRIP) for (t, b) in points: x, y = self._position(t, b) glVertex2f(x, y) glEnd() def draw_curve(self, x1, y1, x2, y2): control_points = [ Vector2d(x1, y1), Vector2d(x1 + (x2 - x1) * 0.3, y1), Vector2d(x1 + (x2 - x1) * 0.7, y2), Vector2d(x2, y2) ] bezier = make_bezier([(p.x, p.y) for p in control_points]) points = bezier(CURVE_PRECISION) glBegin(GL_LINE_STRIP) for x, y in points: glVertex2f(x, y) glEnd() visualizer.run(Ancestry)
glVertex2i(x3, y2) glVertex2i(x3, y1) glEnd() def segment_position(self, segment): x1 = self.byte_to_px(segment.begin) x2 = self.byte_to_px(segment.end) x2 = max(x2, x1 + 1) return x1, x2 def byte_to_px(self, byte): return MARGIN + int(self.byte_to_relative_x(byte) * (self.visualizer.width - 2*MARGIN)) def byte_to_relative_x(self, byte): return float((self.visualizer.max_file_length - self.length) / 2 + byte) / \ self.visualizer.max_file_length class Simple(visualizer.Visualizer): def __init__(self, args): visualizer.Visualizer.__init__(self, args, file_class=File) def added_file(self, _f): self.max_file_length = max([f.length for f in self.files.values()]) def render(self): for f in self.files.values(): f.update() f.render() visualizer.run(Simple)