def draw_adaptive(bz, tolerance): if bz.is_flat(tolerance=tolerance): line.draw(bz.pts[0], bz.pts[3]) else: bzs = bz.split() for bn in bzs: draw_adaptive(bn, tolerance)
def draw_it(bz): u = bz.get(.0) for t in xrange(5, 100, 5): t /= 100. v = bz.get(t) print v line.draw(u, v) u = v
def draw_rec_topflat(vertices, shading_func): v1, v2, v3 = vertices invslope1 = (v3[0] - v1[0]) / float(v3[1] - v1[1]) invslope2 = (v3[0] - v2[0]) / float(v3[1] - v2[1]) curr_x1, curr_x2 = float(v3[0]), float(v3[0]) for scan_y in xrange(int(v3[1]), int(v1[1]), -1): curr_x1 -= invslope1 curr_x2 -= invslope2 line.draw((curr_x1, scan_y), (curr_x2, scan_y), shading_func)
def draw_rec_bottomflat(vertices, shading_func): v1, v2, v3 = vertices invslope1 = (v2[0] - v1[0]) / float(v2[1] - v1[1]) invslope2 = (v3[0] - v1[0]) / float(v3[1] - v1[1]) curr_x1, curr_x2 = float(v1[0]), float(v1[0]) for scan_y in xrange(int(v1[1]), int(v2[1] + 1)): line.draw((curr_x1, scan_y), (curr_x2, scan_y), shading_func) curr_x1 += invslope1 curr_x2 += invslope2
def render(self, origin, end): self.base_image.fill(BLACK) base_origin = self.get_scaled_coord(origin) base_end = self.get_scaled_coord(end) for line in self.line_cluster: line.move_origin(base_origin) line.move_end(base_end) line.draw(self.base_image) self.scale_image()
def draw(self, canvas): canvas.create_text('3.75i', '.25i', font = ('Helvetica', '20'), text='Telephone schematic - telephone.py') for pole in self.poleList: pole.draw(canvas) for line in self.lineList: line.draw(canvas) self.left_mic.draw(canvas) self.right_mic.draw(canvas) self.left_ear.draw(canvas) self.right_ear.draw(canvas) fns.sideways(canvas, self.left_mic.connect(), self.poleList[0].right_point()) fns.sideways(canvas, self.left_ear.connect(), self.poleList[0].left_point()) fns.up_down(canvas, self.right_mic.connect(), self.poleList[2].left_point()) fns.up_down(canvas, self.right_ear.connect(), self.poleList[2].right_point())
def draw_rec(vertices, shading_func, *args, **kwargs): vertices = sorted(vertices, key=lambda x: x[1]) vertices = [map(int, v) for v in vertices] v1, v2, v3 = vertices if v2[1] == v3[1]: if v1[1] == v2[1]: # collinear line.draw(v1, v2, shading_func) line.draw(v2, v3, shading_func) line.draw(v1, v3, shading_func) else: draw_rec_bottomflat(vertices, shading_func) elif v1[1] == v2[1]: draw_rec_topflat(vertices, shading_func) else: v4 = (v1[0] + (v2[1] - v1[1]) / float(v3[1] - v1[1]) * (v3[0] - v1[0]), v2[1]) v4 = map(int, v4) try: draw_rec_bottomflat([v1, v2, v4], shading_func) draw_rec_topflat([v2, v4, v3], shading_func) except RuntimeError: print([v1, v2, v4]) print v4 raise RuntimeError
def draw(vertices): vertices_a = vertices + [vertices[0]] for v, v_n in zip(vertices_a, vertices_a[1:]): line.draw(v, v_n)
def draw_wireframe(vertices): for v in vertices: screen.draw_pixel(*v[:2]) for v, u in zip(vertices, vertices[1:] + [vertices[0]]): line.draw(v[:2], u[:2])