def _render_legend(self, x, y): # render oscilloscope window edge gl.glPushMatrix() gl.glTranslatef(.5, .5, 0.) gl.glLineWidth(1.) gl.glDisable(gl.GL_LINE_SMOOTH) # calculate legend window size w = 0. h = self.font.height * len(self.graph_renderer.channels) for channel in self.graph_renderer.channels: w = max(w, self.font.width(channel.name)) # draw legend window background and border draw.filled_rect(x, y, w + 24, h + 4, (0.3, 0.3, 0.3, 0.3)) draw.rect(x, y, w + 24, h + 4, (0.4, 0.4, 0.4, .8)) # draw legend window example linesegments dy = y + 2. + self.font.height / 2. gl.glEnable(gl.GL_LINE_SMOOTH) for channel in self.graph_renderer.channels: gl.glLineWidth(channel.f_linewidth) draw.line(x + 4, dy, x + 14, dy, channel.f_color_avg) dy += self.font.height # draw legend window text gl.glTranslatef(-.5, -.5, 0.) dy = y + 2. for channel in self.graph_renderer.channels: self.font.drawtl(channel.name, x + 20, dy, bgcolor=(0., 0., 0., 0.), fgcolor=(0.9, 0.9, 0.9, .8)) dy += self.font.height gl.glPopMatrix()
def render(self, img, origin): for line in self.lines: draw.line(line, img, origin) for circle in self.circles: draw.circle(circle, img, origin) for poly in self.polygons: draw.polygon(poly, img, origin)
def on_draw(self, dt=0): self.try_redraw() if not graphics.drawing: #toolbar background #draw.rect(0,graphics.canvas_y,graphics.canvas_x,graphics.height) draw.gradient( 0, graphics.canvas_y, graphics.canvas_x, graphics.height, self.toolbar_bg_1, self.toolbar_bg_2, self.toolbar_bg_2, self.toolbar_bg_1 ) #draw.rect(0,0,graphics.width,graphics.canvas_y) draw.gradient( 0, 0, graphics.width, graphics.canvas_y, self.toolbar_bg_1, self.toolbar_bg_2, self.toolbar_bg_2, self.toolbar_bg_1 ) #buttons graphics.set_color(1,1,1,1) for button in self.toolbar: button.draw() #toolbar buttons for button in self.buttons: button.draw() #bottom buttons for label in self.labels: draw.label(label) #text labels self.colorpicker.draw() #color picker #self.colordisplay.draw() #line/fill color selector tool.controlspace.draw() #divider lines graphics.set_color(0,0,0,1) graphics.set_line_width(1.0) graphics.call_twice(pyglet.gl.glDisable,pyglet.gl.GL_BLEND) draw.line(0, graphics.canvas_y, graphics.width, graphics.canvas_y) draw.line(graphics.canvas_x, graphics.canvas_y, graphics.canvas_x, graphics.height) graphics.call_twice(pyglet.gl.glEnable,pyglet.gl.GL_BLEND) self.drawn_this_frame = False
def _render_legend(self, x, y): # render oscilloscope window edge gl.glPushMatrix() gl.glTranslatef(.5,.5,0.) gl.glLineWidth(1.) gl.glDisable(gl.GL_LINE_SMOOTH) # calculate legend window size w = 0. h = self.font.height * len(self.graph_renderer.channels) for channel in self.graph_renderer.channels: w = max(w, self.font.width(channel.name)) # draw legend window background and border draw.filled_rect(x, y, w+24, h+4, (0.3, 0.3, 0.3, 0.3)) draw.rect(x, y, w+24, h+4, (0.4, 0.4, 0.4, .8)) # draw legend window example linesegments dy = y + 2. + self.font.height / 2. gl.glEnable(gl.GL_LINE_SMOOTH) for channel in self.graph_renderer.channels: gl.glLineWidth(channel.f_linewidth) draw.line(x + 4, dy, x + 14, dy, channel.f_color_avg) dy += self.font.height # draw legend window text gl.glTranslatef(-.5, -.5, 0.) dy = y + 2. for channel in self.graph_renderer.channels: self.font.drawtl(channel.name, x + 20, dy, bgcolor=(0.,0.,0.,0.), fgcolor=(0.9, 0.9, 0.9, .8)) dy += self.font.height gl.glPopMatrix()
def stick_sectors(env): for h in shortcuts.my_field_hockeyists(env) + shortcuts.opponent_field_hockeyists(env): p1 = geometry.point_plus_vector( h, h.angle + env.game.stick_sector / 2., env.game.stick_length) p2 = geometry.point_plus_vector( h, h.angle - env.game.stick_sector / 2., env.game.stick_length) draw.line(h, p1) draw.line(h, p2)
def _render_sensor_line(self, x, y, sensor_angle, distval, color=(0.8,0.4,0.2, 1.)): x2, y2 = x + math.sin(math.radians(sensor_angle)) * distval, y + math.cos(math.radians(sensor_angle)) * distval glDisable(GL_LINE_STIPPLE) color_bg = list(color) #color_bg = (0., 0., 0., 1.) color_bg[-1] = 0.7 draw.line(x, y, x2, y2, color=color_bg) glEnable(GL_LINE_STIPPLE) draw.line(x, y, x2, y2, color=color)
def draw(self): for edge in self.edges.viewvalues(): ax, ay = self.points[edge.a] bx, by = self.points[edge.b] if edge.counterpart: draw.line(ax, ay, bx, by, colors=(0, 255, 0, 255, 0, 255, 0, 255)) else: draw.line(ax, ay, bx, by, colors=(255, 0, 0, 255, 0, 0, 255, 255)) draw.set_color(1,0,0,1) for point in self.points.viewvalues(): draw.rect(point[0]-5, point[1]-5, point[0]+5, point[1]+5)
def redraw(): draw.clear() for i in range(speed): robot.update() for l in lines: draw.line(*l) robot.draw() draw.camera = robot.getPos() draw.ontimer(redraw, 1000 // target_frames)
def draw(self): draw.set_color(color=self.main_color) pyglet.gl.glLineWidth(2.0) draw.line(self.x, self.y, self.x+self.width, self.y) pyglet.gl.glLineWidth(1.0) slider_x = self.x + self.width * self.position draw.set_color(color=self.outline_color) pyglet.gl.glPointSize(self.size) draw.points((slider_x, self.y)) draw.set_color(color=self.main_color) pyglet.gl.glPointSize(self.size-2) draw.points((slider_x, self.y))
def getImg(self,n): image = Image.open(self.path+"/%s" % self.files[n]) frame = cv2.imread(self.path+"/%s" % self.files[n]) b = core.GROUND_X - detect.bird_h(frame, core.DETECT_BIRD_Y, core.GROUND_X, core.PIPE_SPACE) draw = ImageDraw.Draw(image) r = 4 draw.line((0,core.DETECT_BIRD_Y,640,core.DETECT_BIRD_Y),fill='#000',width=1) draw.ellipse((b-r, core.DETECT_BIRD_Y-r, b+r, core.DETECT_BIRD_Y+r), fill='#0ff') del draw self.photo = ImageTk.PhotoImage(image) return self.photo
def draw(self, k): draw.set_pen_radius(PEN_RADIUS) draw.set_pen_color(color.BROWN) draw.line( k.x + math.cos(self.alpha) * kugel.RADIUS * (2 + self.pow), k.y + math.sin(self.alpha) * kugel.RADIUS * (2 + self.pow), k.x + math.cos(self.alpha) * kugel.RADIUS * (LENGTH + self.pow), k.y + math.sin(self.alpha) * kugel.RADIUS * (LENGTH + self.pow)) draw.set_pen_radius(0.001) draw.set_pen_color(color.RED) draw.line(k.x - math.cos(self.alpha) * kugel.RADIUS * (2), k.y - math.sin(self.alpha) * kugel.RADIUS * (2), k.x - math.cos(self.alpha) * kugel.RADIUS * (600), k.y - math.sin(self.alpha) * kugel.RADIUS * (600))
def line_motion(self, event): x0, y0 = (self.previous_point[0], self.previous_point[1]) x1, y1 = (event.x, event.y) paper = copy.copy(self.img) self.lineImg = draw.line((x0, y0), (x1, y1), brush_color, paper, self.defaultState) self.canvas.create_image(self.paper_width / 2, self.paper_height / 2, image=self.lineImg) self.defaultState = 0
def draw(self): for edge in self.edges.viewvalues(): ax, ay = self.points[edge.a] bx, by = self.points[edge.b] if edge.counterpart: draw.line(ax, ay, bx, by, colors=(0, 255, 0, 255, 0, 255, 0, 255)) else: draw.line(ax, ay, bx, by, colors=(255, 0, 0, 255, 0, 0, 255, 255)) draw.set_color(1, 0, 0, 1) for point in self.points.viewvalues(): draw.rect(point[0] - 5, point[1] - 5, point[0] + 5, point[1] + 5)
def _render_scrollbar(self, x, y, w, h): v = .6 draw.line(x + 0.5, y + h + 0.5, x + w, y + h + 0.5, (v, v, v, 1.)) adc_channel = self.graph_renderer.channels[0] if not adc_channel.size(): return x1 = self.sx1 / (adc_channel.size()) * w x2 = self.sx2 / (adc_channel.size()) * w if x2 - x1 < 1.: x2 = x1 + 1. x1 = max(x1, 0.) x2 = max(x2, 0.) x1 = min(x1, w) x2 = min(x2, w) v = .8 draw.filled_rect(x1 + x, y + 1., x2 - x1, h - 2., (v, v, v, 1.)) v = .7
def _render_scrollbar(self, x, y, w, h): v = .6 draw.line(x + 0.5, y+h + 0.5, x+w, y + h + 0.5, (v,v,v,1.)) adc_channel = self.graph_renderer.channels[0] if not adc_channel.size(): return x1 = self.sx1 / (adc_channel.size()) * w x2 = self.sx2 / (adc_channel.size()) * w if x2 - x1 < 1.: x2 = x1 + 1. x1 = max(x1, 0.) x2 = max(x2, 0.) x1 = min(x1, w) x2 = min(x2, w) v = .8 draw.filled_rect(x1+x, y + 1., x2-x1, h - 2., (v,v,v,1.)) v = .7
def _render_scrollbar(self, x, y, w, h): v = .6 draw.line(x+0.5, y+h+0.5, x+w+0.5, y+h+0.5, (v,v,v,1.)) if self.totalsample_x2 == self.totalsample_x1: return x1 = (self.visiblesample_x1 - self.totalsample_x1) / (self.totalsample_x2 - self.totalsample_x1) * w x2 = (self.visiblesample_x2 - self.totalsample_x1) / (self.totalsample_x2 - self.totalsample_x1) * w if x2 - x1 < 1.: x2 = x1 + 1. x1 = max(x1, 0.) x2 = max(x2, 0.) x1 = min(x1, w) x2 = min(x2, w) v = .8 #draw.filled_rect(x1+x, y+1., x2-x1, h-2., (v,v,v,1.)) draw.filled_rect(x1+x, y, x2-x1, h-1., (v,v,v,1.)) v = .7
def main(): img = Image.new('RGB', IMG_DIM, color='white') my_circle = Circle(Vector([200, 50]), 100) circle_2 = Circle(Vector([0, 0]), 300) arc = hyper.arc_from_angles(my_circle, math.pi / 3, 3 * math.pi / 4) draw.axes(img, ORIGIN) draw.circle(my_circle, img, ORIGIN) draw.circle_segment(circle_2, math.pi / 2, 5 * math.pi / 4, img, ORIGIN) draw.line((0, 0), (200, 300), img, ORIGIN) draw.circle_segment(arc, img, ORIGIN) img = ImageOps.flip(img) img.save('new.png')
def example_get_adjusted_map(): net = Network.load_native('data/janos-us.txt') points = [(n.long, n.lati) for n in net.nodes] projection = MercatorProjection.from_points(points, map_size=(1024, 512), padding=50) status = mapbox.get_map_as_file( 'data/map-us.png', replace=True, api_token=os.environ['MAPBOX_API_KEY'], projection=projection, style='countries_basic', ) print('Map ' + ('' if status else 'not ') + 'dowloaded') net.add_pixel_coordinates(projection) draw.prepare('data/map-us.png') for u, v in net.edges: sx, sy = net.edge_middle_point(u, v, pixel_value=True) distance = haversine(u.long, u.lati, v.long, v.lati) draw.line(u.x, u.y, v.x, v.y, marker='o', color='gray') draw.text(sx, sy, f'{distance:.0f}km', fontsize=7, color='navy', weight='bold', horizontalalignment='center') for node in net.nodes: draw.text(node.x, node.y, node.name, fontsize=8, color='black', weight='bold', horizontalalignment='center') draw.show()
def anaylze(frame, debug = False, start = 10): blue_start = -1 notblue_start = 0 notblue_end = 0 viewcolor.setIndex(start) for i in range(start, width): r = frame.item(l3,i,2) g = frame.item(l3,i,1) b = frame.item(l3,i,0) viewcolor.rgb(r,g,b) (h,s,v) = colorsys.rgb_to_hsv(r/255.0,g/255.0,b/255.0) print "%f\t%f\t%f"%(h,s,v) if h > 0.45 and h < 0.6 and blue_start < 0: blue_start = i if blue_start >=0 and h < 0.45 and s > 0.75 and notblue_start == 0: notblue_start = i print notblue_start if debug: img = draw.start(frame) draw.line(img, (0,l3), (width,l3)) draw.line(img, (notblue_start,0), (notblue_start,height)) draw.line(img, (llight,0), (llight,height)) draw.end(img) cv2.imshow('frame',frame) cv2.waitKey(0) cv2.destroyAllWindows()
def draw_tools(self): #toolbar background draw.set_color(0.8, 0.8, 0.8, 1) draw.rect(0,graphics.canvas_y,graphics.canvas_x,graphics.height) draw.rect(0,0,graphics.width,graphics.canvas_y) #buttons draw.set_color(1,1,1,1) for button in self.toolbar: button.draw() #toolbar buttons for button in self.buttons: button.draw() #bottom buttons for label in self.labels: draw.label(label) #text labelsr tool.controlspace.draw() #divider lines draw.set_color(0,0,0,1) graphics.set_line_width(1.0) draw.line(0, graphics.canvas_y, graphics.width, graphics.canvas_y) draw.line( graphics.canvas_x, graphics.canvas_y, graphics.canvas_x, graphics.height )
def example_sndlib_draw_geomanip(): projection = MercatorProjection(map_size=(1024, 512), center=(19.6153711, 52.0892499), zoom=5) status = mapbox.get_map_as_file( 'data/map-pl.png', replace=True, api_token=os.environ['MAPBOX_API_KEY'], projection=projection, style='countries_basic', ) print('Map ' + ('' if status else 'not ') + 'dowloaded') net = Network.load_native('data/polska.txt') net.add_pixel_coordinates(projection) draw.prepare('data/map-pl.png') for u, v in net.edges: sx, sy = net.edge_middle_point(u, v, pixel_value=True) distance = haversine(u.long, u.lati, v.long, v.lati) draw.line(u.x, u.y, v.x, v.y, marker='o', color='gray') draw.text(sx, sy, f'{distance:.0f}km', fontsize=7, color='navy', weight='bold', horizontalalignment='center') for node in net.nodes: draw.text(node.x, node.y, node.name, fontsize=8, color='black', weight='bold', horizontalalignment='center') draw.show()
def draw_agents(self, agent_positions, agent_goal_velocities, agent_velocities): for i in range(len(agent_positions)): # print(agent_positions[i]) agent_x = agent_positions[i][0] agent_y = agent_positions[i][1] v_i = agent_velocities[i] norm_v_i = np.linalg.norm(v_i) goal_v_i = agent_goal_velocities[i] norm_goal_v_i = np.linalg.norm(goal_v_i) normalized_v = norm_v_i / 2 draw.filled_circle(agent_x, agent_y, self._rad, self.get_heatmap_color(normalized_v)) draw.line(agent_positions[i], agent_positions[i] + 1.5 * self._rad * v_i / norm_v_i, self.get_heatmap_color(normalized_v)) draw.line( agent_positions[i], agent_positions[i] + self._rad * goal_v_i / norm_goal_v_i, Color(255, 255, 255))
def main(): pic = Image.new('RGB', (WIDTH, HEIGHT), BG_COLOR) print('main mother f****r ga') vertex, faces = get_obj() data = pic.load() draw_ordinates(data, pic) line_color = color.getrgb("#fff") def normalize_cords(point): x = int((point.x + 1) * (WIDTH - 1) / 2) y = int((point.y + 1) * (HEIGHT - 1) / 2) return Point(x, y, point.z) # for face in faces: # A, B, C = tuple(normalize_cords(vertex[f[0] - 1]) for f in face) # poly(A, B, C, data, line_color) a = (Point(10, 70, 0), Point(50,160, 0), Point(70, 80, 0)) # b = (Point(180, 50, 0), Point(150, 1, 0), Point(70, 180, 0)) # c = (Point(180, 150, 0), Point(120, 160, 0), Point(130, 180, 0)) a = tuple(sorted(a, key=lambda x: x.y)) # b = tuple(sorted(b, key=lambda x: x.y)) # c = tuple(sorted(c, key=lambda x: x.y)) height = a[2].y - a[0].y y = a[0].y line(a[0], a[1], data, color.getrgb("#0f0")) line(a[1], a[2], data, color.getrgb("#0f0")) line(a[2], a[0], data, color.getrgb("#f00")) # line(b[0], b[1], data, color.getrgb("#0f0")) # line(b[1], b[2], data, color.getrgb("#0f0")) # line(b[2], b[0], data, color.getrgb("#f00")) # # line(c[0], c[1], data, color.getrgb("#0f0")) # line(c[1], c[2], data, color.getrgb("#0f0")) # line(c[2], c[0], data, color.getrgb("#f00")) # poly(*a, data, color.getrgb("#f00")) # poly(*b, data, color.getrgb("#0f0")) # poly(*c, data, color.getrgb("#00f")) pic.show()
def draw_level(self): draw.set_color(1,1,1,1) if level.background_image != None: try: level.background_image.blit_tiled( 0, 0, 0, level.width, level.height ) except: level.background_image.blit(0,0) draw.set_color(1, 0, 1, 0.5) draw.grid(level.camera_x, level.camera_y, graphics.width, graphics.height) draw.set_color(0,0,0,1) draw.line(0,0,0,level.height) draw.line(0,level.height,level.width,level.height) draw.line(level.width,level.height,level.width,0) draw.line(level.width,0,0,0) level.draw_level_objects() draw.set_color(0,1,0,1) draw.circle(level.player_x, level.player_y, 80) if graphics.drawing: self.current_tool.keep_drawing_static()
def draw_level_objects(): colors = { True: prim_color, False: (1,0,0,1) } for obj in primitives: if obj.yaml_tag == u"!Line": if obj.visible: draw.set_color(*prim_color) else: if obj.collides: draw.set_color(0,1,0,1) else: draw.set_color(1,0,0,1) draw.line(obj.x1, obj.y1, obj.x2, obj.y2) elif obj.yaml_tag == u"!Circle": if obj.visible: draw.set_color(*prim_color) else: if obj.collides: draw.set_color(0,1,0,1) else: draw.set_color(1,0,0,1) draw.circle(obj.x, obj.y, obj.radius) elif obj.yaml_tag == u"!FilledRect": draw.set_color(*colors[obj.visible]) draw.rect(obj.x1, obj.y1, obj.x2, obj.y2) elif obj.yaml_tag == u"!FilledTriangle": draw.set_color(*colors[obj.visible]) draw.polygon((obj.x1, obj.y1, obj.x2, obj.y2, obj.x3, obj.y3)) elif obj.yaml_tag == u"!Door": draw.set_color(*resources.key_colors[obj.key]) graphics.set_line_width(5.0) draw.line(obj.x1, obj.y1, obj.x2, obj.y2) draw.set_color(*colors[True]) graphics.set_line_width(1.0) draw.line(obj.x1, obj.y1, obj.x2, obj.y2) elif obj.yaml_tag == u"!Key": draw.set_color(1,1,1,1) resources.key_images[obj.number].blit(obj.x, obj.y) simple_objects_batch.draw() draw.set_color(1,1,1,1) for label in labels: draw.rect( label.x-label.content_width/2-3, label.y-label.content_height/2, label.x+label.content_width/2+3, label.y+label.content_height/2 ) label_batch.draw()
def draw_line(): graphics.set_line_width(size) graphics.set_color(0,0,0,1) draw.line(x+15,y+10, x+w-15, y+h-10)
last_month = y_m.shift(months=-1).format('YYYY/MM') same_month = y_m.shift(years=-1).format('YYYY/MM') # 预处理,将json文件转为csv文件 pp.json_to_csv(file_name_sale, "mid_sale.csv", this_month) pp.json_to_csv(file_name_rent, "mid_rent.csv", this_month) pp.preprocess("mid_sale.csv", "sale.csv", this_month) pp.preprocess("mid_rent.csv", "rent.csv", this_month) # 新sale表合并过来并保存 cal.save_table("286sale.csv", "sale.csv", this_month) # 计算286sale同比和环比 cal.sale_calculate(last_month, same_month, this_month) # 计算百城投资收益指数 cal.index_calculate(last_month, same_month, this_month) # 新index表合并过来保存 cal.save_table('286index.csv', 'index_new.csv', this_month) # 绘图 dw.map(this_month) dw.hist(this_month) dw.box() dw.pie(this_month) dw.line() dw.bar()
def draw(self): draw.line(self.start, self.end)
def draw(self, scale, x, y): for wall in self.getWalls(scale, x, y): draw.line(*wall)
def paint_flower_pen(self, event): draw = ImageDraw.Draw(self.img) draw.line((self.previous_point, (event.x, event.y)), brush_color, brush_size) self.pencil_img = ImageTk.PhotoImage(self.img) self.canvas.create_image(self.paper_width / 2, self.paper_height / 2, image=self.pencil_img)
def tick(self, pattern, beat): self.aa.clear() for y in range(0, 18): if self.breakup: radius = 8 + max(0, beat - y) twist = (math.pi * (beat + 2) / 8) - y / 4.0 twist = min(twist, math.pi / 2) else: radius = 8 twist = (math.pi * (beat + 2) / 8) - y / 4.0 dx = math.sin(twist) * radius brightness1 = 0.8 + math.cos(twist) * 0.5 brightness2 = 0.8 - math.cos(twist) * 0.5 x1 = int(9 - dx) x2 = int(9 + dx) if self.breakup: break_radius = radius - 8 break_dx = math.sin(twist) * break_radius x1_break = int(9 - break_dx) x2_break = int(9 + break_dx) draw_link = (y % 4 == 1) if draw_link: link_num = y / 4 link_colour = LINK_COLOURS[link_num] if brightness1 > brightness2: # plot the dimmest (furthest) first self.aa.plot(x2, y, (0, brightness2)) self.aa.plot(x2, y, (0, brightness2)) if draw_link: if self.breakup: draw.line(self.aa.screen, x1, y, x1_break, y, link_colour) draw.line(self.aa.screen, x2, y, x2_break, y, link_colour) else: draw.line(self.aa.screen, x1, y, x2, y, link_colour) self.aa.plot(x1, y, (0, brightness1)) self.aa.plot(x1 - 1, y, (0, brightness1)) else: self.aa.plot(x1, y, (0, brightness1)) self.aa.plot(x1 - 1, y, (0, brightness1)) if draw_link: if self.breakup: draw.line(self.aa.screen, x1, y, x1_break, y, link_colour) draw.line(self.aa.screen, x2, y, x2_break, y, link_colour) else: draw.line(self.aa.screen, x1, y, x2, y, link_colour) self.aa.plot(x2, y, (0, brightness2)) self.aa.plot(x2 + 1, y, (0, brightness2)) self.aa.render()
def main(): sr = 1000 dur = 1.0 #-------------------------------------------------------------------------- # drawn waveforms _3_hz = Constant(3) x = draw.sine(sr, dur, _3_hz) plt.figure() plt.plot(x) plt.grid(True) plt.title('Sine wave: f = %d Hz' % _3_hz()) x = draw.sine(sr, dur, _3_hz, Constant(0.5)) plt.figure() plt.plot(x) plt.grid(True) plt.title('Cosine wave: f = %d Hz' % _3_hz()) f_3_10 = Circular(draw.line(sr, dur, 3, 10)) x = draw.sine(sr, dur, f_3_10) plt.figure() plt.plot(x) plt.grid(True) plt.title('Sine wave: f = 3-10 Hz') phase = Circular(draw.line(sr, dur, 0.0, 1.0)) x = draw.sine(sr, dur, _3_hz, phase) plt.figure() plt.plot(x) plt.grid(True) plt.title('Sine wave: f = 3, phase = 0 - 180 deg') plt.show() #-------------------------------------------------------------------------- # wave table gen Nearest # create a 3 tables each holding 1 cycle _1_hz = Constant(1.0) table_1000 = draw.sine(1000, 1000, _1_hz) table_500 = draw.sine(500, 500, _1_hz) table_250 = draw.sine(250, 250, _1_hz) gen_1000 = wt_oscillators.Nearest(sr, table_1000) gen_500 = wt_oscillators.Nearest(sr, table_500) gen_250 = wt_oscillators.Nearest(sr, table_250) dur = 1.0 x0 = gen_1000.generate(dur, f_3_10) x1 = gen_500.generate(dur, f_3_10) x2 = gen_250.generate(dur, f_3_10) plt.figure() plt.plot(x0, 'b-', label='wt 1000') plt.plot(x1, 'r-', label='wt 500') plt.plot(x2, 'm-', label='wt 250') plt.title('wt_oscillators.Neartest signals') plt.grid(True) plt.legend() # round off error residuals res_500 = x1 - x0 res_250 = x2 - x0 plt.figure() plt.plot(res_500, label='wt 500 error') plt.plot(res_250, label='wt 250 error') plt.title('wt_oscillators.Nearest residual error') plt.grid(True) plt.legend() plt.show() #-------------------------------------------------------------------------- # wave table gen Lininterp gen_1000 = wt_oscillators.Lininterp(sr, table_1000) gen_500 = wt_oscillators.Lininterp(sr, table_500) gen_250 = wt_oscillators.Lininterp(sr, table_250) x0 = gen_1000.generate(dur, f_3_10) x1 = gen_500.generate(dur, f_3_10) x2 = gen_250.generate(dur, f_3_10) plt.figure() plt.plot(x0, 'b-', label='wt 1000') plt.plot(x1, 'r-', label='wt 500') plt.plot(x2, 'm-', label='wt 250') plt.title('wt_oscillators.Lininterp signals') plt.grid(True) plt.legend() # round off error residuals res_500 = x1 - x0 res_250 = x2 - x0 plt.figure() plt.plot(res_500, label='wt 500 error') plt.plot(res_250, label='wt 250 error') plt.title('wt_oscillators.Lininterp residual error') plt.grid(True) plt.legend() plt.show() #-------------------------------------------------------------------------- # draw with phase phase = Circular(draw.line(sr, 1.0, 0.0, 1.0)) _3_hz = Constant(3.0) x0 = draw.sine(sr, dur, _3_hz, phase) x1 = gen_250.generate(dur, _3_hz, phase) plt.figure() plt.plot(x0, label='drawn') plt.plot(x1, label='wt 250 interp') plt.title('3 Hz sine with 180 deg phase change') plt.grid(True) plt.legend() res = x1 - x0 plt.figure() plt.plot(res, label='wt 250 interp error') plt.title('Residual error with 180 deg phase change') plt.grid(True) plt.legend() plt.show()
def drawFunc(frame, d, path): frame = draw.start(frame) # bird_anaylze draw.point(frame,(lb-anaylze_bird_pos(draw.cvImg(frame,path)),l3),(0,255,255),5) # static draw.line(frame,(0,d.l2+2),(width,d.l2+2),(255,0,0),1) draw.line(frame,(0,d.l3+2),(width,d.l3+2),(255,0,255),1) draw.line(frame,(0,d.l4+2),(width,d.l4+2),(255,0,0),1) draw.line(frame,(d.la,0),(d.la,height),(255,0,0),1) draw.line(frame,(d.lb,0),(d.lb,height),(255,0,0),1) # draw.line(frame,(d.llight,0),(d.llight,height),(0,255,255),1) # bird draw.point(frame,(d.lb-d.b,l2),(0,0,0),5) draw.line(frame,(d.lb-d.b,0),(d.lb-d.b,height),(0,0,0),1) # pipe draw.line(frame,(d.lb-d.h1,d.l2-d.s),(d.lb,d.l2-d.s),(255,255,0),1) draw.line(frame,(d.lb-d.h1,d.l2-d.s),(d.lb-d.h1,d.l2-d.s-L-Bird_body),(255,255,0),1) # survival draw.line(frame,(d.lb-d.sur-50,d.l2-50),(d.lb-d.sur+50,d.l2+50),(0,255,255),1) draw.end(frame)
def main(): sr = 1000 dur = 1.0 #-------------------------------------------------------------------------- # drawn waveforms _3_hz = Constant(3) x = draw.sine(sr, dur, _3_hz) plt.figure() plt.plot(x) plt.grid(True) plt.title('Sine wave: f = %d Hz' % _3_hz()) x = draw.sine(sr, dur, _3_hz, Constant(0.5)) plt.figure() plt.plot(x) plt.grid(True) plt.title('Cosine wave: f = %d Hz' % _3_hz()) f_3_10 = Circular(draw.line(sr, dur, 3, 10)) x = draw.sine(sr, dur, f_3_10) plt.figure() plt.plot(x) plt.grid(True) plt.title('Sine wave: f = 3-10 Hz') phase = Circular(draw.line(sr, dur, 0.0, 1.0)) x = draw.sine(sr, dur, _3_hz, phase) plt.figure() plt.plot(x) plt.grid(True) plt.title('Sine wave: f = 3, phase = 0 - 180 deg') plt.show() #-------------------------------------------------------------------------- # wave table gen Nearest # create a 3 tables each holding 1 cycle _1_hz = Constant(1.0) table_1000 = draw.sine(1000, 1000, _1_hz) table_500 = draw.sine( 500, 500, _1_hz) table_250 = draw.sine( 250, 250, _1_hz) gen_1000 = wt_oscillators.Nearest(sr, table_1000) gen_500 = wt_oscillators.Nearest(sr, table_500) gen_250 = wt_oscillators.Nearest(sr, table_250) dur = 1.0 x0 = gen_1000.generate(dur, f_3_10) x1 = gen_500.generate(dur, f_3_10) x2 = gen_250.generate(dur, f_3_10) plt.figure() plt.plot(x0, 'b-', label = 'wt 1000') plt.plot(x1, 'r-', label = 'wt 500') plt.plot(x2, 'm-', label = 'wt 250') plt.title('wt_oscillators.Neartest signals') plt.grid(True) plt.legend() # round off error residuals res_500 = x1 - x0 res_250 = x2 - x0 plt.figure() plt.plot(res_500, label = 'wt 500 error') plt.plot(res_250, label = 'wt 250 error') plt.title('wt_oscillators.Nearest residual error') plt.grid(True) plt.legend() plt.show() #-------------------------------------------------------------------------- # wave table gen Lininterp gen_1000 = wt_oscillators.Lininterp(sr, table_1000) gen_500 = wt_oscillators.Lininterp(sr, table_500) gen_250 = wt_oscillators.Lininterp(sr, table_250) x0 = gen_1000.generate(dur, f_3_10) x1 = gen_500.generate(dur, f_3_10) x2 = gen_250.generate(dur, f_3_10) plt.figure() plt.plot(x0, 'b-', label = 'wt 1000') plt.plot(x1, 'r-', label = 'wt 500') plt.plot(x2, 'm-', label = 'wt 250') plt.title('wt_oscillators.Lininterp signals') plt.grid(True) plt.legend() # round off error residuals res_500 = x1 - x0 res_250 = x2 - x0 plt.figure() plt.plot(res_500, label = 'wt 500 error') plt.plot(res_250, label = 'wt 250 error') plt.title('wt_oscillators.Lininterp residual error') plt.grid(True) plt.legend() plt.show() #-------------------------------------------------------------------------- # draw with phase phase = Circular(draw.line(sr, 1.0, 0.0, 1.0)) _3_hz = Constant(3.0) x0 = draw.sine(sr, dur, _3_hz, phase) x1 = gen_250.generate(dur, _3_hz, phase) plt.figure() plt.plot(x0, label = 'drawn') plt.plot(x1, label = 'wt 250 interp') plt.title('3 Hz sine with 180 deg phase change') plt.grid(True) plt.legend() res = x1 - x0 plt.figure() plt.plot(res, label = 'wt 250 interp error') plt.title('Residual error with 180 deg phase change') plt.grid(True) plt.legend() plt.show()
def draw(self): poi = self.poi() if poi: draw.line(self.pos, self.poi(), "red")
def draw(self): draw.line(*self.getLine())
def draw(self): poi = self.poi() if poi: draw.line(self.pos, poi, "red") else: draw.line(*self.getLine())
def draw(self): draw.set_color(*self.color) draw.line(self.x1, self.y1, self.x2, self.y2)