def make_movie(duration_seconds, output_filename): w, h = 500, 100 scale = 50 beamwidth = 8 # beam width in m beamheight = 0.2 coords[0] = 0 # Start position of first pole relative to start of beam coords[1] = 8 # random position of 2nd pole relative to start of beam # TODO: Change like in testfile, start at 0,0, change coords in make_frame file. Also add 1 general textfile that you change # Standard support # To use, translate support in make_frame, it will create a copy support = gz.rectangle(scale * .2, scale * 0.25, xy=[0, 0], stroke_width=1, fill=(0, 1, 0)) # Beam at center of screen beam = gz.rectangle(scale * beamwidth, scale * beamheight, xy=[w / 2, h / 2], stroke_width=1, fill=(1, 1, 0)) # Standard text at 0, 0 text = gz.text(str('placeholder'), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[0, 0]) ''' paal1 = gz.rectangle(scale * .2, scale * 0.25, xy=((coords[0] + 1) * scale, h / 2 + 10), stroke_width=1, fill=(0, 1, 0)) paal2 = gz.rectangle(scale * .2, scale * 0.25, xy=((coords[1] + 1) * scale, h / 2 + 10), stroke_width=1, fill=(0, 1, 0)) pole = gz.rectangle(scale * beamwidth, scale * beamheight, xy=(w / 2, h / 2), stroke_width=1, fill=(1, 1, 0)) ''' def make_frame(t): speed = t * -20 surface = gz.Surface(w, h, bg_color=(1, 1, 1)) x0 = (coords[0] + 1) * scale # change coords with neat x1 = (coords[1] + 1) * scale + speed # change coords with neat and remove +speed height_support = h / 2 + beamheight * 50 support0 = support.translate(xy=[x0, height_support]) group = gz.Group((support0,)) group.draw(surface) support1 = support.translate(xy=[x1, height_support]) group = gz.Group((support1,)) group.draw(surface) group = gz.Group((beam,)) group.draw(surface) # Get the moments momentenfunction(beamwidth) # Draw text text1 = gz.text(str(round(momenten[0])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[x0, 30]) text2 = gz.text(str(round(momenten[1])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[(x0 + x1) / 2, 80]) text3 = gz.text(str(round(momenten[2])), fontfamily="Impact", fontsize=14, fill=(0, 0, 1), xy=[x1, 30]) group = gz.Group((text1, text2, text3)) group.draw(surface) return surface.get_npimage() clip = mpy.VideoClip(make_frame, duration=duration_seconds) clip.write_videofile(output_filename, codec="mpeg4", fps=50)
def piano_surface(midi, size, offset, time): surface = gizeh.Surface(*size) current = midi.second2tick(time) hit_note_colors = { midi.notes[interval[2]]['note']: track_colors[midi.notes[interval[2]]['track'] % 4] for interval in midi.timeline[current] } ivory_params = lambda note: { 'lx' : size[0]/52, 'ly' : size[1], 'xy' : (size[0] * position[note], size[1] / 2), 'fill' : hit_note_colors[note][1] if note in hit_note_colors.keys() else RGB('#CBCFCC'), 'stroke': RGB('#3A3E42'), 'stroke_width': 1 } ebony_params = lambda note: { 'lx' : size[0]/52 * 0.7, 'ly' : size[1] * 2/3, 'xy' : (size[0] * position[note], size[1] / 3), 'fill': hit_note_colors[note][0] if note in hit_note_colors.keys() else RGB('#3A3E42') } for note in filter(is_ivory, range(21, 109)): gizeh.rectangle(**ivory_params(note)).draw(surface) for note in filter(is_ebony, range(21, 109)): gizeh.rectangle(**ebony_params(note)).draw(surface) return surface
def draw(self, *data): chart_color = self.get_visual_token_oig_background(*data) soft_black_color = (0.137, 0.121, 0.125) gizeh.rectangle(xy=(self.width / 2, self.height / 2), lx=self.width, ly=self.height, fill=chart_color).draw(self.surface) self.draw_triangle([self.spine_length] * 3, (1, 1, 1, 0.6), None, 0) spines = [value * self.spine_length / 100 for value in data] self.draw_triangle(spines, soft_black_color, soft_black_color) self.draw_chart_grid(4, chart_color) vertices = self.triangle_vertices(spines) for vertex in vertices: gizeh.polyline( points=[vertex, (self.center['x'], self.center['y'])], stroke_width=1, stroke=(1, 1, 1)).draw(self.surface) for vertex in vertices: gizeh.circle(r=4, xy=vertex, fill=(1, 1, 1)).draw(self.surface) gizeh.circle(r=3, xy=vertex, fill=soft_black_color).draw(self.surface) return self.surface
def prepare(): surface = gz.Surface(width, height) gz.rectangle(lx=width, ly=height, xy=(width / 2, height / 2), fill=(0, 0, 0)).draw(surface) gz.circle(xy=(width / 2, height / 2), r=width / 2 - 10, fill=(1, 1, 1)).draw(surface) gz.circle(xy=(width / 2, height / 2), r=width / 2 - 40, fill=(0, 0, 0)).draw(surface) surface.write_to_png('spiral_ring.png') points = stipple_image_points('spiral_ring.png', n_points=5000, scale_factor=2, max_iterations=50) np.save('spiral_ring.npy', points) write_tsp('spiral_ring.tsp', points) run_linkern('spiral_ring.tsp', 'spiral_ring.cyc', '../../tools/linkern.exe') postprocess_cyc('spiral_ring.npy', 'spiral_ring.cyc', 'spiral_ring_processed.npy', (256, 256), segment_length=5, degree=3, normalize_points=False)
def make_movie(net, force_function, duration_seconds, output_filename): w, h = 300, 100 scale = 300 / 6 cart = gz.rectangle(scale * 0.5, scale * 0.25, xy=(150, 80), stroke_width=1, fill=(0, 1, 0)) pole = gz.rectangle(scale * 0.1, scale * 1.0, xy=(150, 55), stroke_width=1, fill=(1, 1, 0)) sim = CartPole() def make_frame(t): inputs = sim.get_scaled_state() if hasattr(net, 'activate'): action = net.activate(inputs) else: action = net.advance(inputs, sim.time_step, sim.time_step) sim.step(force_function(action)) surface = gz.Surface(w, h, bg_color=(1, 1, 1)) # Convert position to display units visX = scale * sim.x # Draw cart. group = gz.Group((cart,)).translate((visX, 0)) group.draw(surface) # Draw pole. group = gz.Group((pole,)).translate((visX, 0)).rotate(sim.theta, center=(150 + visX, 80)) group.draw(surface) return surface.get_npimage() clip = mpy.VideoClip(make_frame, duration=duration_seconds) clip.write_videofile(output_filename, codec="mpeg4", fps=50)
def make_movie(net, force_function, duration_seconds, output_filename): w, h = 300, 100 scale = 300 / 6 cart = gz.rectangle(scale * 0.5, scale * 0.25, xy=(150, 80), stroke_width=1, fill=(0, 1, 0)) pole = gz.rectangle(scale * 0.1, scale * 1.0, xy=(150, 55), stroke_width=1, fill=(1, 1, 0)) sim = CartPole() def make_frame(t): inputs = sim.get_scaled_state() action = net.serial_activate(inputs) sim.step(force_function(action)) surface = gz.Surface(w, h, bg_color=(1, 1, 1)) # Convert position to display units visX = scale * sim.x # Draw cart. group = gz.Group((cart,)).translate((visX, 0)) group.draw(surface) # Draw pole. group = gz.Group((pole,)).translate((visX, 0)).rotate(sim.theta, center=(150 + visX, 80)) group.draw(surface) return surface.get_npimage() clip = mpy.VideoClip(make_frame, duration=duration_seconds) clip.write_videofile(output_filename, codec="mpeg4", fps=50)
def make_frame(t): surface = gz.Surface(W, H, bg_color=(0, 0, 0)) if t > duration/3: if t < duration*2/3: x = W/2. - length*W/2 + r/2 rect = gz.rectangle(xy=(x, H/2.), lx=r, **s) else: rect = gz.rectangle(xy=(W/2., H/2.), lx=length*W, **s) rect.draw(surface) return surface.get_npimage()
def __init__(self, width = 720, height = 480): self.surface = gizeh.Surface(width=width, height=height) bg = gizeh.rectangle(lx = width, ly = height, xy=(width//2,height//2), fill=(1,1,1)) bg.draw(self.surface)
def make_frame(self, t): """ Creates colored pointer. Background color is the blur color, pointer (rect) color is the color of the pointer. """ surface = gz.Surface(self.width, self.height, bg_color=self.p_glow_color) # rect = gz.rectangle(lx=150, ly=5, xy=(250,250), fill=(0,1,0), angle=3.1415926/(2*t+1)) rect = gz.rectangle( lx=self.p_length, ly=self.p_width, xy=(self.p_rot_center_x + self.p_length * self.p_shift, self.p_rot_center_y), fill=self.p_color) rect = rect.rotate(self.speed2angle(t), center=[self.p_rot_center_x, self.p_rot_center_y]) rect.draw(surface) if self.g_text_visible: txt = gz.text('{0}'.format( int(self.gps_speed[int(t)] * self.unit_conversion_factor)), fontfamily=self.g_text_fontFamily, fontsize=self.g_text_size, xy=(self.g_text_x, self.g_text_y), fill=self.p_color) txt.draw(surface) arr = surface.get_npimage() if self.parent is not None: self.parent.processBarExport(p=1) if self.parent.cancelExport is True: raise TypeError('Canceling...') return arr
def make_frame(self,t): """ Creates colored pointer. Background color is the blur color, pointer (rect) color is the color of the pointer. """ surface = gz.Surface(self.width, self.height, bg_color=self.p_glow_color) # rect = gz.rectangle(lx=150, ly=5, xy=(250,250), fill=(0,1,0), angle=3.1415926/(2*t+1)) rect = gz.rectangle( lx=self.p_length, ly=self.p_width, xy=(self.p_rot_center_x+self.p_length*self.p_shift, self.p_rot_center_y), fill=self.p_color) rect = rect.rotate(self.speed2angle(t), center=[self.p_rot_center_x, self.p_rot_center_y]) rect.draw(surface) if self.g_text_visible: txt = gz.text( '{0}'.format(int(self.gps_speed[int(t)]*self.unit_conversion_factor)), fontfamily=self.g_text_fontFamily, fontsize=self.g_text_size, xy=(self.g_text_x, self.g_text_y), fill=self.p_color) txt.draw(surface) arr = surface.get_npimage() if self.parent is not None: self.parent.processBarExport(p=1) if self.parent.cancelExport is True: raise TypeError('Canceling...') return arr
def make_frame_mask(self, t): """ Creates pointer mask. """ surface = gz.Surface(self.width, self.height, bg_color=(0, 0, 0)) # rect = gz.rectangle(lx=150, ly=5, xy=(250,250), fill=(1,1,1), angle=3.1415926/(2*t+1)) rect = gz.rectangle( lx=self.p_length + 2 * self.p_glow_margin, ly=self.p_width + 2 * self.p_glow_margin, xy=(self.p_rot_center_x + self.p_length * self.p_shift, self.p_rot_center_y), fill=(1, 1, 1)) rect = rect.rotate(self.speed2angle(t), center=[self.p_rot_center_x, self.p_rot_center_y]) rect.draw(surface) if self.g_text_visible: txt = gz.text('{0}'.format( int(self.gps_speed[int(t)] * self.unit_conversion_factor)), fontfamily=self.g_text_fontFamily, fontsize=self.g_text_size, xy=(self.g_text_x, self.g_text_y), fill=(1, 1, 1)) txt.draw(surface) arr = surface.get_npimage() if self.parent is not None and self.parent.cancelExport is True: raise TypeError('Canceling...') return arr
def draw_seconds(seconds): center = numpy.array([40 / 2, 16 / 2]) surface = gizeh.Surface(width=40, height=16, bg_color=(0, 0, 0)) # in pixels image = alpha_to_color(misc.imread('alpaka.png')) alpaka = gizeh.ImagePattern(image, pixel_zero=center) r = gizeh.rectangle(lx=40, ly=16, xy=(24, 8), fill=alpaka) r.draw(surface) text = gizeh.text("{:02d}".format(seconds), fontfamily="DIN Condensed", fontsize=20, fill=(0.99, 0.82, 0.25), xy=(32, 8), angle=0) # Pi/12) text.draw(surface) #surface.write_to_png("circle.png") out = surface.get_npimage() fb = out.tobytes() prepped = prepare_message(fb, unpack=False) send_array(prepped, '100.100.218.106')
def make_bar(surface, constants, bar_width, bar_height, bar_x, bar_y): # Light bar gz.rectangle(lx=bar_width, ly=bar_height, xy=[bar_x, bar_y], fill=constants.line_color).draw(surface) # Dark bar if constants.theme.lower() != 'tokyu': color = constants.line_color_dark else: color = constants.line_color gz.rectangle(lx=bar_width, ly=bar_height, xy=[bar_x, bar_y + bar_height], fill=color).draw(surface)
def foresee_surface(midi, size, offset, time): surface = gizeh.Surface(*size) foresee = 2 current, future = midi.second2tick(time), midi.second2tick(time + foresee) for begin, end, note in midi.timeline[current:future]: future = future or 2 * current - midi.second2tick(time - foresee) begin, end = max(begin, current), min(end, future) note, colors = midi.notes[note]['note'], track_colors[midi.notes[note]['track'] % 4] rect_params = { 'lx' : size[0]/52 if is_ivory(note) else size[0]/52 * 0.7, 'ly' : size[1] * (end - begin) / (future - current) - 5, 'xy' : (size[0] * position[note] + offset[0], size[1] * (future - end/2 - begin/2) / (future - current) + offset[1]), 'fill': colors[1] if is_ivory(note) else colors[0] } gizeh.rectangle(**rect_params).draw(surface) return surface
def create_frame(t): img = gizeh.Surface(videobreite,videohoehe,bg_color=(hgfarbe_r,hgfarbe_g,hgfarbe_b)) text_img = gizeh.text(text, fontfamily=schrift, fontsize=textgroesse, fill=(textfarbe_r,textfarbe_g,textfarbe_b), xy=(videobreite/2,videohoehe/2), angle=winkel) rect_img = gizeh.rectangle(lx=videobreite, ly=videohoehe, xy=(videobreite/2,videohoehe/2+t*videohoehe/videolaenge), fill=(hgfarbe_r,hgfarbe_g,hgfarbe_b), angle=winkel) text_img.draw(img) rect_img.draw(img) return img.get_npimage()
def draw_metro_frames(surface, constants, service_settings): # Draw separator line gz.polyline([(0, constants.sep_height), (constants.width, constants.sep_height)], stroke=Metro.stroke_color, stroke_width=Metro.stroke_width).draw(surface) # Draw background for direction indicator gz.rectangle(lx=constants.width * 2, ly=Metro.rectangle_height, xy=[0, 0], fill=Metro.rectangle_fill).draw(surface) # Draw background for service type gz.rectangle(lx=constants.width / 6, ly=Metro.rectangle_height / 2 - 30, xy=[service_settings.xy[0], service_settings.xy[1]], fill=Metro.service_fill).draw(surface)
def make_frame(t): surface = gz.Surface(W,H, bg_color=(1,1,1)) rect = gz.rectangle(lx = 10, ly = 10, xy=(W/(t+1),H/2), fill =(0,1,0.7)) rect.draw(surface) txt = gz.text(str(t+1), fontfamily="Impact", fontsize=15, fill=(0,0,0),xy=(W/(t+1),H/2)) txt.draw(surface) return surface.get_npimage()
def make_frame(t): surface = gizeh.Surface(W, H, bg_color=(.8, .8, .8)) x = t * W / duration + radius circle = gizeh.circle(r=radius, xy=(x, H / 2), fill=(1, 0, 0)) rect = gizeh.rectangle(lx=1, ly=H, xy=(int(0.7 * W), H / 2), fill=(0, 0, 0)) circle.draw(surface) rect.draw(surface) return surface.get_npimage()
def make_frame(t): surface = gz.Surface(W, H, bg_color=(0, 0, 0)) if t > duration/3: if t < duration*2/3: x = W/2. - length*W/2 else: x = W/2. + length*W/2 rect = gz.rectangle(xy=(x, H/2.), fill=(1, 1, 1), lx=r, ly=r) rect.draw(surface) return surface.get_npimage()
def make_frame(t): progress = t / duration p = interval_progresses(progress, 4, 'hermite') # draw rectangles surface = gz.Surface(2 * width, 2 * height) for i in range(10): d1 = (540 - 27 * i) gz.rectangle(lx=d1, ly=d1, xy=(width, height), fill=(1, 1, 1)).draw(surface) y_thickness = (9 + (p[0] - p[2]) * 9) x_thickness = (9 + (p[1] - p[3]) * 9) gz.rectangle(lx=d1 - x_thickness, ly=d1 - y_thickness, xy=(width, height), fill=(0, 0, 0)).draw(surface) # FFT I = np.fft.fft2(surface.get_npimage()[:, :, 0] / 255) I = np.abs(I).astype(np.float32) I = 1 - np.minimum(1, np.maximum(0, I)) I = resize(I, (width, height)) # border radius = (300 + 15 * (p[0] + p[1] - p[2] - p[3])) I *= get_circle_mask(width, height, radius) I -= np.min(I) I /= np.max(I) I = np.tile(I[:, :, np.newaxis], (1, 1, 4)) * 255 surface = gz.Surface.from_image(I.astype(np.uint8)) gz.circle(xy=(width / 2, height / 2), r=radius, stroke=(1, 1, 1), stroke_width=2).draw(surface) return surface.get_npimage()
def render_keys(keys_down): isdown_layout = set2layout(keys_down) s = gz.Surface(RES[0] + 2 * BORDER, RES[1] + 2 * BORDER) #gz.rectangle(xy=(RES[0]/2, RES[1]/2), lx=RES[0], ly=RES[1], fill=(0,1,0)).draw(s) # greenscreen? gz.rectangle(xy=(RES[0] / 2 + BORDER, RES[1] / 2 + BORDER), lx=RES[0], ly=RES[1], fill=BORDER_RGBA).draw(s) row_height = RES[1] / len(chars_layout) xy = v([BORDER, -row_height / 2 + BORDER]) for row, downs in zip(chars_layout, isdown_layout): xy += v([0, row_height]) # place pen at start pos for row tot_chars = sum([len(col) for col in row]) for col, is_down in zip(row, downs): col_width = RES[0] * len(col) / tot_chars xy += v([col_width / 2, 0]) # advance pen if col != ' ': fill = (0.5, 0.5, 1, ALPHA_PRESSED) if is_down else (0.2, 0.2, 0.4, ALPHA) gz.rectangle(xy=xy, lx=col_width, ly=row_height, fill=fill, stroke=BORDER_RGBA, stroke_width=BORDER).draw(s) gz.text(col, 'Arial', 60, fill=(1, 1, 1, ALPHA), xy=xy).draw(s) xy += v([col_width / 2, 0]) # advance pen xy[0] = BORDER return s
def make_frame(t): surface = gz.Surface(W,H, bg_color=(1,1,1)) #rect = gizeh.rectangle(lx=60.3, ly=45, xy=(60,70), fill=(0,1,0), angle=Pi/8) for i in range(numRects): rect = rects[i] x = i * 15.0 #y = H - rect.height y = H #y = 40 #rectShape = gz.rectangle(lx=10.0, ly=rect.height, xy=(x, y), fill=(0,1,0), angle=0) rectShape = gz.rectangle(lx=10.0, ly=rect.height, fill=(0,1,0), angle=0).translate((x,y)) rectShape.draw(surface) return surface.get_npimage()
def makeslidebox3(t): surface = gizeh.Surface(width=1920, height=1080) if t == 0: iW1 = 10 else: iW1 = iFW3 rect = gizeh.rectangle(lx=(iW1/2 * (t + 1)), ly=(iFH3 + 100), xy=((1920 * t), ((1080 - (iFH3 + 100)) / 2) + ((iFH3 + 50) / 2)), fill=(0, 0, tempdets.templateBGColorB), angle=0) rect.draw(surface) return surface.get_npimage(transparent=True)
def makeslidebox2(t): surface2 = gizeh.Surface(width=1920, height=1080) if t == 0: iW2 = 50 else: iW2 = iFW2 print('t'+str(t)) #print('x' + str(1920 - (100* t))) rect2 = gizeh.rectangle(lx=(iW2 * (t + 1)), ly=(iFH2 + 100), xy=((1920 - (750* t)), ((1080 - (iFH2 + 100)) / 2) + ((iFH2 + 50) / 2)), fill=(0, 0, tempdets.templateBGColorB), angle=0) rect2.draw(surface2) return surface2.get_npimage(transparent=True)
def background_stars(canvas, n_stars=100, color=False): """ Paints a background of stars within the canvas Parameters ---------- canvas: gizeh.Surface Desired canvas for the stars to be painted n_stars: int Number of stars to be painted color: bool If true, stars will be randomly colorized Returns ------- canvas: gizeh.Surface Original canvas updated with stars background """ # Collect canvas main parameters W, H = canvas.width, canvas.height # Generate dark space background dark_background = gizeh.rectangle(lx=2 * W, ly=2 * H, xy=(0, 0), fill=(0, 0, 0)) dark_background.draw(canvas) for _ in range(n_stars): # Generate random location and star size px, py = W * random(), H * random() r_star = random() * 2.5 # Colorize if required if color: RGB = tuple([random() for _ in range(3)]) else: RGB = (1, 1, 1) # Generate star and draw it on canvas dot_star = gizeh.circle(r_star, xy=(px, py), fill=RGB) dot_star.draw(canvas) return canvas
def make_frame(t): surface = gz.Surface(W, H, bg_color=(1, 1, 1)) #rect = gizeh.rectangle(lx=60.3, ly=45, xy=(60,70), fill=(0,1,0), angle=Pi/8) for i in range(numRects): rect = rects[i] x = i * 15.0 #y = H - rect.height y = H #y = 40 #rectShape = gz.rectangle(lx=10.0, ly=rect.height, xy=(x, y), fill=(0,1,0), angle=0) rectShape = gz.rectangle(lx=10.0, ly=rect.height, fill=(0, 1, 0), angle=0).translate((x, y)) rectShape.draw(surface) return surface.get_npimage()
def create_frame(t): img = gizeh.Surface(videobreite, videohoehe, bg_color=(hgfarbe_r, hgfarbe_g, hgfarbe_b)) text_img = gizeh.text(text, fontfamily=schrift, fontsize=textgroesse, fill=(textfarbe_r, textfarbe_g, textfarbe_b), xy=(videobreite / 2, videohoehe / 2), angle=winkel) rect_img = gizeh.rectangle(lx=videobreite, ly=videohoehe, xy=(videobreite / 2, videohoehe / 2 - t * videohoehe / videolaenge), fill=(hgfarbe_r, hgfarbe_g, hgfarbe_b), angle=winkel) text_img.draw(img) rect_img.draw(img) return img.get_npimage()
def draw_vertical_lines(size: int, palette: 'models.Palette', count: int = 7) \ -> gizeh.Surface: """ Draws series of vertical lines. :param size: Width and height of resulting surface. :param palette: The color palette to source colors from. :param count: Number of lines. :returns: Resulting surface. """ colors = palette.monochromatic(2) surface = gizeh.Surface(width=size, height=size) for idx in range(count): color = colors[idx % len(colors)] color_rect = gizeh.rectangle(lx=size / count + 1, ly=size, xy=((size / count) * idx + (size / (count * 2)), size / 2), fill=color) color_rect.draw(surface) return surface
def draw_angled_lines(size: int, palette: 'models.Palette', count: int = 5) \ -> gizeh.Surface: """ Draws series of lines at a 45-degree angle :param size: Width and height of resulting surface. :param palette: The color palette to source colors from. :param count: Number of lines. :returns: Resulting surface. """ colors = palette.monochromatic(2) surface = gizeh.Surface(width=size, height=size) for idx in range(count + 2): idx = idx - 1 color = colors[idx % len(colors)] color_rect = gizeh.rectangle(lx=size * 2, ly=size / (count - 1) + 2, xy=(size / 2, (size / (count - 1)) * idx), fill=color).rotate(45, center=(size // 2, size // 2)) color_rect.draw(surface) return surface
def make_frame_mask(self,t): """ Creates pointer mask. """ surface = gz.Surface(self.width, self.height, bg_color=(0,0,0)) # rect = gz.rectangle(lx=150, ly=5, xy=(250,250), fill=(1,1,1), angle=3.1415926/(2*t+1)) rect = gz.rectangle( lx=self.p_length+2*self.p_glow_margin, ly=self.p_width+2*self.p_glow_margin, xy=(self.p_rot_center_x+self.p_length*self.p_shift, self.p_rot_center_y), fill=(1,1,1)) rect = rect.rotate(self.speed2angle(t), center=[self.p_rot_center_x, self.p_rot_center_y]) rect.draw(surface) if self.g_text_visible: txt = gz.text( '{0}'.format(int(self.gps_speed[int(t)]*self.unit_conversion_factor)), fontfamily=self.g_text_fontFamily, fontsize=self.g_text_size, xy=(self.g_text_x, self.g_text_y), fill=(1,1,1)) txt.draw(surface) arr = surface.get_npimage() if self.parent is not None and self.parent.cancelExport is True: raise TypeError('Canceling...') return arr
def draw_tokyu_frames(surface, constants, service_settings): # Change background color gz.rectangle(lx=constants.width * 2, ly=constants.height * 2, fill=Tokyu.bg_color).draw(surface) # Fill station info in the top with background gz.rectangle(lx=constants.width, ly=constants.sep_height, xy=[constants.width / 2, constants.sep_height / 2], fill=Tokyu.rectangle_fill).draw(surface) # Draw background for service type gz.rectangle(lx=constants.width / 4, ly=Metro.rectangle_height / 2 - 30, xy=[service_settings.xy[0] + 10, service_settings.xy[1]], fill=Tokyu.service_fill).draw(surface)
def draw_jr_frames(surface, constants, _): # Change background color gz.rectangle(lx=constants.width * 2, ly=constants.height * 2, fill=JR.bottom_bg_color).draw(surface) # Fill station info in the top with background gz.rectangle(lx=constants.width, ly=constants.sep_height, xy=[constants.width / 2, constants.sep_height / 2], fill=JR.top_bg_color).draw(surface) # Fill station text with background gz.rectangle(lx=constants.width * JR.box_width_mul, ly=constants.sep_height * JR.box_height_mul, xy=[constants.width / 2, constants.sep_height / 2 + 50], fill=JR.station_bg_color).draw(surface)
def draw_yamanote_frames(surface, constants, service_settings): # Change background color gz.rectangle(lx=constants.width * 2, ly=constants.height * 2, fill=Yamanote.bg_color).draw(surface) # Fill station info in the top with background gz.rectangle(lx=constants.width, ly=constants.sep_height, xy=[constants.width / 2, constants.sep_height / 2], fill=Yamanote.rectangle_fill).draw(surface) # Add line color indicator gz.rectangle(lx=Yamanote.indicator_width, ly=constants.sep_height, xy=[Yamanote.indicator_pos, constants.sep_height / 2], fill=constants.line_color).draw(surface) # Draw background for service type gz.rectangle(lx=(Yamanote.indicator_pos - Yamanote.indicator_width / 2) - 50, ly=Metro.rectangle_height / 2 - 30, xy=[service_settings.xy[0] + 10, service_settings.xy[1]], fill=Yamanote.bg_color).draw(surface)
def epoch_finished(self, epoch): num_words = len(self.words) surface = gizeh.Surface(width=1200, height=self.height) background = gizeh.rectangle(lx=1200, ly=self.height, xy=[600,750], fill=(0,0,0)) background.draw(surface) gizeh.text('%s epoch %s' % (self.title, epoch), fontfamily='Arial', fontsize=20, fill=(.6,.6,.6), xy=(70,40), h_align='left').draw(surface) weights = self.rbm.weights.get_value() for block in range(self.tuplesize): for word in range(num_words): x = 40 y = 70+22*(block*(num_words+2)+word) gizeh.text('%s %s' % (block, self.words[word]), fontfamily='Arial', fontsize=12, fill=(.7,.7,.7), xy=(x,y), h_align='left').draw(surface) for block in range(self.tuplesize): for word in range(num_words): for h in range(self.num_hidden): vis = block*num_words+word w = weights[vis, h] r = math.log(1+abs(w))*4 x = 100+22*h y = 70+22*(block*(num_words+2)+word) col = (1,1,0) if w < 0: col = (.4,.4,.4) circle = gizeh.circle(r=r, xy=[x,y], fill=col) circle.draw(surface) surface.write_to_png("epoch-%03d.png" % epoch)
def draw(shape, pixel, filename=None): resize = pixel / 10 surface = gizeh.Surface(width=pixel, height=pixel, bg_color=(0, 0, 0)) # in pixels if shape[0] == 1: line = gizeh.polyline( points=[(resize * shape[1], resize * shape[2]), (resize * shape[3], resize * shape[4])], stroke_width=1, stroke=(1, 1, 1)) line.draw(surface) if shape[0] == 2: circle = gizeh.circle(r=resize * shape[3], xy=[resize * shape[1], resize * shape[2]], stroke=(1, 1, 1), stroke_width=1) circle.draw(surface) if shape[0] == 3: rect = gizeh.rectangle(lx=resize * shape[3], ly=resize * shape[4], xy=( resize * shape[1] + resize * shape[3] / 2, resize * shape[2] + resize * shape[4] / 2), stroke=(1, 1, 1), stroke_width=1, angle=0) rect.draw(surface) img = surface.get_npimage()[:, :, 0] # returns a (width x height) numpy array if filename is not None: surface.write_to_png(filename + ".png") return img
def drawing(boxes, objs, colors, classes): surface = gz.Surface(width=720, height=560) # in pixels rect = gz.rectangle(lx=720, ly=560, xy=(360, 280), fill=(1, 1, 1)) rect.draw(surface) LABELS = open("yolo/coco.names").read().strip().split("\n") colors = [ colors[i] for i in range(len(colors)) if LABELS[classes[i]] != 'person' ] #print(len(colors)) i = 0 for strokes in objs: lines_list = [] for stroke in strokes['image']: x, y = stroke x = tuple([(z * boxes[i][2]) // 255 for z in x]) y = tuple([(z * boxes[i][3]) // 255 for z in y]) x = tuple([z + boxes[i][0] for z in x]) y = tuple([z + boxes[i][1] for z in y]) points = list(zip(x, y)) line = gz.polyline(points=points, stroke=[0, 0, 0], stroke_width=2, fill=colors[i]) lines_list.append(line) lines = gz.Group(lines_list) lines.draw(surface) i += 1 #surface.write_to_png("gallery/circle.png") return surface
def make_frame(t): amplitude, period = H/3, W background = gz.rectangle(W, H, xy=[W/2,H/2], fill = (1,1,1)) background.draw(surface) slope = 10 offsets = np.linspace(0, slope - 1, NCOMPONENTS) a = float(DURATION)/2 / 4 b = float(DURATION)/2 / 2 L = NCOMPONENTS ycord = waves[0] # ycord = np.zeros(NPOINTS) for index, wave in enumerate(waves[1:]): C = np.clip(slope*abs(((t - a) % b - a)/a) - offsets[index],0,1) * np.sign(np.sin(4*np.pi/DURATION*t)) if index == 2: print t, C, np.sign(np.sin(4*np.pi/DURATION*t)) # print "C: ", C, "index: ", index, "coefficient: ", coefficient ycord += C * wave points = np.array(zip(xcord*period/(2*np.pi), amplitude*ycord)) lines.append( gz.polyline(points, stroke_width=1, stroke=(0,0,0, 0.4), xy=[0,H/2]) ) if(len(lines) > 10): lines.pop(0) grp = gz.Group(lines) grp.draw(surface) return surface.get_npimage()
import gizeh as gz import numpy as np width = 700 height = int(width * 0.65) surface = gz.Surface(width=width, height=height, bg_color=(1,1,1)) # white keys white_count = 7 white_size = (width / white_count, height) for i in range(white_count): w, h = white_size rect = gz.rectangle(lx=w-5, ly=h-5, xy=[(i + 0.5) * w, h / 2], stroke=(0.8, 0.8, 0.8), stroke_width=2) rect.draw(surface) # black keys for i in (0, 1, 3, 4, 5): w, h = white_size[0] * 0.85, (white_size[1] * 0.65) rect = gz.rectangle(lx=w-5, ly=h-5, xy=[(i + 0.5 + 0.5) * white_size[0], h / 2], fill=(0.1, 0.1, 0.1)) rect.draw(surface) for i, label in enumerate(('C', 'D', 'E', 'F', 'G', 'A', 'B')): text = gz.text(label, 'Helvetica', white_size[0]*0.4, xy=[(i + 0.5) * white_size[0], height * 0.85]) text.draw(surface) for i, label in ((0, 'Db'), (1, 'Eb'), (3, 'Gb'), (4, 'Ab'), (5, 'Bb')):
from random import randint import cPickle import numpy as np import gizeh as gz import moviepy.editor as mpy from neat.config import Config from neat.nn import nn_pure as nn from evolve_single_pole import cart_pole, angle_limit W, H = 300, 100 D = 15 # duration in seconds SCALE = 300 / 6 cart = gz.rectangle(SCALE * 0.5, SCALE * 0.25, xy=(150, 80), stroke_width=1, fill=(0, 1, 0)) pole = gz.rectangle(SCALE * 0.1, SCALE * 1.0, xy=(150, 55), stroke_width=1, fill=(1, 1, 0)) # random.seed(0) # load the winner with open('winner_chromosome') as f: c = cPickle.load(f) print 'Loaded chromosome:' print c local_dir = os.path.dirname(__file__) config = Config(os.path.join(local_dir, 'spole_config')) net = nn.create_phenotype(c)