def make_frame(t): surface = gz.Surface(width, height) progress = t / duration t_floaters = (progress * repetitions + progresses) % 1.0 floaters = np.stack([ x_shifts + amplitudes * np.sin(2 * np.pi * t_floaters * (height / periods)), 50 + (width - 100) * (1 - t_floaters) ]).T d_center = np.sum(np.square(floaters - np.array([width / 2, height / 2])), axis=1) - (width / 2)**2 points = np.concatenate([symbol, floaters[d_center < 0, :]]) d = distance_matrix(symbol, floaters) for i in range(len(symbol)): for j in range(len(floaters)): if d[i, j] <= max_dist: alpha = (1 - d[i, j] / max_dist)**2 gz.polyline(points=[points[i, :], floaters[j, :]], stroke=(1, 1, 1, alpha), stroke_width=1).draw(surface) return surface.get_npimage()
def draw(self, surface: gizeh.Surface) -> None: """Draw the line on the tone clock.""" scale = self._style.marking_scale lower = self.get_mark_point(elevation=-10 * scale) upper = self.get_mark_point(elevation=10 * scale) gizeh.polyline(points=[lower, upper], stroke=BLACK, stroke_width=scale).draw(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 make_frame(t): progress = t / duration p = interval_progresses(progress, 2, 'hermite') center = (width / 2, height / 2) # star surface = gz.Surface(2 * width, 2 * height) n_lines = 24 length = 30 + 5 * (p[0] - p[1]) C = get_circle_coordinates(n_lines, length, center) rotate_around(C, -2 * np.pi * progress / n_lines, center) for i in range(n_lines): gz.polyline(points=[center, C[i, :]], stroke=(1, 1, 1), stroke_width=2).draw(surface) # FFT I = np.fft.fft2(surface.get_npimage()[:, :, 0] / 255) I = np.abs(I).astype(np.float32) I -= 1 I = 1 - np.minimum(1, np.maximum(0, I)) I = resize(I, (width, height)) # border radius = 300 I *= get_circle_mask(width, height, radius) 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=3).draw(surface) return surface.get_npimage()
def make_frame(t): surface = gz.Surface(width, height) progress = t / duration cut = int(progress * len(points_p)) + 430 points = np.concatenate( [points_[cut:], points_[:cut] + (0, 2 * np.pi * n_reps)]) points[:, 1] -= 2 * np.pi * progress points[:, 1] *= stretch r_coefficients = np.power(points[:, 1] / (2 * np.pi * n_reps * stretch), 3) points[:, 0] *= r_coefficients mean_rs = r * r_coefficients points[:, 0] = (points[:, 0] - mean_rs) * stretch + mean_rs points[:, 0] *= 0.8 points[:, 1] += 2 * np.pi * progress - 0.5 * np.pi points = polar_to_cartesian_np(points) + center surface = gz.Surface(width, height) n_segments = 50 for i in range(10, n_segments): color = [1, 1, 1, ((i + 1) / n_segments)**2] gz.polyline(points=points[len(points) * i // n_segments:len(points) * (i + 1) // n_segments + 1], stroke_width=2 * (i + 1) / n_segments, stroke=color).draw(surface) return surface.get_npimage()
def draw(strokes): points = [s for stroke in strokes for s in stroke] xs = map(lambda p: p['x'], points) ys = map(lambda p: p['y'], points) width = max(xs) height = max(ys) surface = gizeh.Surface(width=width, height=height) for stroke in strokes: line = [(p['x'], p['y']) for p in stroke] outline = list(line) outline.reverse() gizeh.polyline(points=line + outline, stroke_width=3, stroke=(1, 1, 1)).draw(surface) #[gizeh.circle(r=9, # xy=(point['x'] - min(xs), point['y'] - min(ys)), # fill=(1,0,0)).draw(surface) # for point in generate_cuts(stroke)] #time_sum = 0 #time_threshold = 0.02 #time_diffs = [0] + map(lambda pair: pair[1]['time'] - pair[0]['time'], zip(points[:-1], points[1:])) #for point, diff in zip(points, time_diffs): # time_sum += diff # if time_sum > time_threshold: # gizeh.circle(r=9,xy=(point['x'] - min(xs), point['y'] - min(ys)), fill=(1,0,1)).draw(surface) # time_sum = 0 surface.write_to_png('a.png') return surface.get_npimage()
def prepare_data(): surface = gz.Surface(1000, 1000) offset = np.array((500, 500)) gz.square(l=1000, xy=offset, fill=(0, 0, 0)).draw(surface) radius, corners, stroke_width = get_extinction_symbol_params(400) gz.circle(r=radius, xy=offset, stroke=(1, 1, 1), stroke_width=stroke_width).draw(surface) gz.polyline(points=corners + offset, close_path=True, fill=None, stroke=(1, 1, 1), stroke_width=stroke_width).draw(surface) surface.write_to_png('extinction_symbol.png') print('STIPPLING EXTINCTION SYMBOL') points = stipple_image_points('extinction_symbol.png', n_points=2500, scale_factor=1, max_iterations=50) np.save('extinction_symbol', points) points = np.load('extinction_symbol.npy') write_tsp('extinction_symbol.tsp', points) run_linkern('extinction_symbol.tsp', 'extinction_symbol.cyc', '../../tools/linkern.exe') postprocess_cyc('extinction_symbol.npy', 'extinction_symbol.cyc', 'extinction_symbol_processed.npy', (width, height), radius=110 / 128, segment_length=5)
def render(self, volume, as_html=False): self._calc_M() surf = gizeh.Surface(width=self.width, height=self.height, bg_color=self.bg_color) ijks = np.asarray(np.nonzero(volume), dtype=np.float) cube = make_prism((0., 0., 0.), (1., 1., 1.)) faces, normals = [], [] for ijk in ijks.T: faces.extend([(face.T + ijk).T for face in cube]) faces = sorted(faces, key=iso_face_depth, reverse=True) normals = map(face_normal, faces) faces_flat = np.concatenate(faces, 1) faces_flat_h = np.vstack((faces_flat, np.ones(faces_flat.shape[1]))) uvs_flat = np.dot(self.M, faces_flat_h).T colors = np.outer(np.dot(normals, self.light_angle), self.base_color) for face_ix in range(0, faces_flat.shape[1], 4): uvs = uvs_flat[face_ix:face_ix + 4] color = colors[face_ix // 4] gizeh.polyline(uvs, stroke=self.stroke_color, stroke_width=self.stroke_width, close_path=True, fill=color).draw(surf) if as_html: return surf.get_html_embed_code() return surf.get_npimage()
def make_frame(t): surface = gz.Surface(width, height) progress = t / duration center = width / 2, height / 2 - 18 circles = [ geo.Point(center).buffer(r, resolution=32) for r in np.arange(5, 0.8 * width, 10) ] p = [ interval_progresses(progress + offset, 6, 'hermite') for offset in np.linspace(0, 1 / 3, len(circles))[::-1] ] angles = [ hermite(hermite(p[i][2] - p[i][5])) * 2 * np.pi for i in range(len(p)) ] arcs = [] for i, c in enumerate(circles): s = xr.intersection(c.exterior) if isinstance(s, geo.LineString): arcs.append((s, angles[i])) elif isinstance(s, geo.MultiLineString): arcs.extend([(arc, angles[i]) for arc in s]) for arc, angle in arcs: coords = np.array(arc.coords) rotate_around(coords, angle, center) gz.polyline(points=coords, stroke=(1, 1, 1), stroke_width=5, line_cap='round').draw(surface) return surface.get_npimage()
def render(self, volume, as_html=False): self._calc_M() surf = gizeh.Surface(width=self.width, height=self.height, bg_color=self.bg_color) ijks = np.asarray(np.nonzero(volume), dtype=np.float) cube = make_prism((0., 0., 0.), (1., 1., 1.)) faces, normals = [], [] for ijk in ijks.T: faces.extend([(face.T+ijk).T for face in cube]) faces = sorted(faces, key=iso_face_depth, reverse=True) normals = map(face_normal, faces) faces_flat = np.concatenate(faces, 1) faces_flat_h = np.vstack((faces_flat, np.ones(faces_flat.shape[1]))) uvs_flat = np.dot(self.M, faces_flat_h).T colors = np.outer(np.dot(normals, self.light_angle), self.base_color) for face_ix in range(0, faces_flat.shape[1], 4): uvs = uvs_flat[face_ix:face_ix+4] color = colors[face_ix//4] gizeh.polyline(uvs, stroke=self.stroke_color, stroke_width=self.stroke_width, close_path=True, fill=color).draw(surf) if as_html: return surf.get_html_embed_code() return surf.get_npimage()
def draw_points(surface, points, left=0, top=0): line = [(p['x'] - left, p['y'] - top) for p in points] outline = list(line) outline.reverse() gizeh.polyline(points=line + outline, stroke_width=3, stroke=(0, 0, 0)).draw(surface) return surface
def make_frame(t): progress = t / duration p = interval_progresses(progress, 15, ['none']*14 + ['hermite',]) p_grow = hermite(sum(p[:-1]) / (len(p)-1)) surface = gz.Surface(width, height) center = np.array((width/2, height/2)) # parameters n_loops = 15 * p_grow r_1 = 0.2 * (1 - p[-1]) # angles for trigonometric functions base_ = np.linspace(-2*n_loops * np.pi, 2*n_loops * np.pi, 2*n_points) # spiral offsets from ring z = r_1 * np.sin(base_) xy = norm(-ring_[:2,:], axis=0) * r_1 * np.cos(base_) xy += norm(-ring_[:2,:], axis=0) * 0.2 * p[-1] # correct for radius problem when r_1 = 0 offset = np.vstack([xy, z, np.zeros(base_.size)]) # smooth between non-matching spiral arms interp = hermite(np.linspace(.5,0,n_points//2)) offset[:,n_points//2 : n_points] = \ (1 - interp) * offset[:,n_points//2 : n_points] + interp * offset[:,-n_points//2 : ] offset[:,-n_points : -n_points//2] = \ (1 - interp[::-1]) * offset[:,-n_points : -n_points//2] + interp[::-1] * offset[:, : n_points//2] offset = offset[:, n_points//2 : -n_points//2] ring = ring_[:, n_points//2 : -n_points//2] # final points points = ring + offset # project to screen C = get_camera_matrix(t_x=np.pi/4, t_z=2*np.pi * hermite(progress), z=1.15) points, z = project(C, points, (width, height)) # switch from points to lines and sort by depth lines = np.array([(points[i], points[(i+1)%len(points)]) for i in range(len(points))]) z_lines = np.array([ (z[i] + z[(i+1)%len(z)]) / 2 for i in range(len(z))]) sort_indices = np.argsort(z_lines) lines = lines[sort_indices] z_lines = z_lines[sort_indices] # relative depth for shading z_min, z_max = z_lines.min(), z_lines.max() z_ratios = (z_lines - z_min) / (z_max - z_min) # draw lines for i in range(len(lines)): gz.polyline(points=lines[i], stroke_width=3 + 3 * z_ratios[i], stroke=[0.3 + 0.7 * z_ratios[i]]*3, line_cap='round').draw(surface) return surface.get_npimage()
def draw(self, surface: gizeh.Surface) -> None: """Draw the pitch's representative angle marking.""" scale = self._style.marking_scale left = self.get_mark_point(elevation=10 * scale, rush=-5 * scale) center = self.get_mark_point(elevation=15 * scale) right = self.get_mark_point(elevation=10 * scale, rush=5 * scale) gizeh.polyline(points=[left, center, right], close_path=False, stroke=BLACK, stroke_width=scale).draw(surface)
def half(t, side="left"): points = gz.geometry.polar_polygon(NFACES, R, NSQUARES) #ipoint = 0 if side=="left" else NSQUARES/2 #points = (points[ipoint:]+points[:ipoint])[::-1] #for point in points: # print point surface = gz.Surface(W,H) centerPoints = [] for (r, th, d) in points: center = W * (0.5 + gz.polar2cart(r, th)) angle = -(6 * np.pi * d + t * np.pi / DURATION) #color= colorsys.hls_to_rgb((2*d+t/DURATION)%1,.5,.5) centerPoints.append(center) color= (0.9, 0.9, 0.9) square = gz.circle(r=4.0, xy= center, fill=color) #square = gz.square(l=0.17*W, xy= center, angle=angle, # fill=color, stroke_width= 0.005*W, stroke=(1,1,1)) square.draw(surface) line = gz.polyline(points=centerPoints, stroke_width=1, stroke=(1, 0, 0)) line.draw(surface) im = surface.get_npimage() return (im[:,:W/2] if (side=="left") else im[:,W/2:])
def rose(d, n): """ Returns a polyline representing a rose of radius 1 """ n_cycles = 1.0 * d / gcd(n,d) # <- number of cycles to close the rose aa = np.linspace(0, 2 * np.pi * n_cycles, 1000) rr = np.cos( n*aa/d) points = gz.polar2cart(rr, aa) return gz.polyline(points, stroke=[0,0,0], stroke_width=.05)
def animation4(t): W = H = 480 WSQ = W/4 a = np.pi/8 points = [(0,0),(1,0),(1-np.cos(a)**2,np.sin(2*a)/2),(0,0)] surface = gz.Surface(W,H) for k, (c1,c2) in enumerate([[(.7,0.05,0.05),(1,0.5,0.5)], [(0.05,0.05,.7),(0.5,0.5,1)]]): grad = gz.ColorGradient("linear",xy1=(0,0), xy2 = (1,0), stops_colors= [(0,c1),(1,c2)]) r = min(np.pi/2,max(0,np.pi*(t-DURATION/3)/DURATION)) triangle = gz.polyline(points,xy=(-0.5,0.5), fill=grad, angle=r, stroke=(1,1,1), stroke_width=.02) square = gz.Group([triangle.rotate(i*np.pi/2) for i in range(4)]) squares = (gz.Group([square.translate((2*i+j+k,j)) for i in range(-3,4) for j in range(-3,4)]) .scale(WSQ) .translate((W/2-WSQ*t/DURATION,H/2))) squares.draw(surface) return surface.get_npimage()
def draw_wavy_lines(size: int, palette: 'models.Palette', count: int = 7, frequency: int = 6) -> gizeh.Surface: """ Draws series of wavy vertical lines. :param size: Width and height of resulting surface. :param palette: The color palette to source colors from. :param count: Number of lines. :param frequency: Frequency of waves per line. :returns: Resulting surface. """ colors = palette.monochromatic(2) surface = gizeh.Surface(width=size, height=size) for idx in range(count + 1): color = colors[idx % len(colors)] points = [ ( # Px (( ((p + p // (frequency + 2)) % 2) / 2 \ + idx + (p // (frequency + 2)) ) - 1) * (size / (count - 1)) \ + (-1 + (p // (frequency + 2)) * 2), # Py (jsin(p, frequency + 2) - 1) * (size / (frequency - 1)) ) for p in range((frequency + 2) * 2) ] line = gizeh.polyline(points=points, fill=color) line.draw(surface) return surface
def half(t, side="left"): points = gz.geometry.polar_polygon(NFACES, R, NSQUARES) #ipoint = 0 if side=="left" else NSQUARES/2 #points = (points[ipoint:]+points[:ipoint])[::-1] #for point in points: # print point surface = gz.Surface(W, H) centerPoints = [] for (r, th, d) in points: center = W * (0.5 + gz.polar2cart(r, th)) angle = -(6 * np.pi * d + t * np.pi / DURATION) #color= colorsys.hls_to_rgb((2*d+t/DURATION)%1,.5,.5) centerPoints.append(center) color = (0.9, 0.9, 0.9) square = gz.circle(r=4.0, xy=center, fill=color) #square = gz.square(l=0.17*W, xy= center, angle=angle, # fill=color, stroke_width= 0.005*W, stroke=(1,1,1)) square.draw(surface) line = gz.polyline(points=centerPoints, stroke_width=1, stroke=(1, 0, 0)) line.draw(surface) im = surface.get_npimage() return (im[:, :W / 2] if (side == "left") else im[:, W / 2:])
def make_frame(t): progress = t / duration p = interval_progresses(progress, 4, 'hermite') surface = gz.Surface(width, height) center = np.array((width/2, height/2)) # first level spiral r_1 = 0.2 * (p[0] - p[2]) spiral_1 = np.array(spiral_0) spiral_1[2] += r_1 * np.sin(base_1) spiral_1[:2] += norm(-spiral_0[:2], axis=0) * r_1 * np.cos(base_1) # second level spiral r_2 = 0.03 * (p[1] + p[2] - 2*p[3]) points = np.array(spiral_1) if r_1 > 0: to_center = norm(spiral_1[:3] - spiral_0[:3], axis=0) else: to_center = norm(spiral_0[:3], axis=0) to_next = norm(np.roll(spiral_1[:3], 1) - spiral_1[:3], axis=0) points[:3] += np.cross(to_next, to_center, axis=0) * r_2 * np.sin(base_2) points[:3] += to_center * r_2 * np.cos(base_2) # project to screen C = get_camera_matrix(t_x=np.pi/4, t_z=2*np.pi * progress * 2 / loops_1, z=1.2) points, z = project(C, points, (width, height)) # switch from points to lines and sort by depth lines = np.array([(points[i], points[(i+1)%len(points)]) for i in range(len(points))]) z_lines = np.array([ (z[i] + z[(i+1)%len(z)]) / 2 for i in range(len(z))]) sort_indices = np.argsort(z_lines) lines = lines[sort_indices] z_lines = z_lines[sort_indices] # relative depth for shading z_min, z_max = z_lines.min(), z_lines.max() z_ratios = (z_lines - z_min) / (z_max - z_min) # draw lines for i in range(len(lines)): gz.polyline(points=lines[i], stroke_width=(3 + 3 * z_ratios[i]) / (1 + 1.5 * (p[1] + p[2] - 2*p[-1])), stroke=[0.3 + 0.7 * z_ratios[i]]*3, line_cap='round').draw(surface) return surface.get_npimage()
def make_frame(t): progress = t / duration p = interval_progresses(progress, 5, ['none'] * 4 + [ 'hermite', ]) p_grow = hermite(sum(p[:-1]) / (len(p) - 1)) surface = gz.Surface(width, height) center = np.array((width / 2, height / 2)) # spiral loops = 30 * p_grow base_ = np.linspace(-loops * np.pi, loops * np.pi, base.size) r = 0.2 * (1 - p[-1]) points = np.array(points_start) points[2, :] += r * np.sin(base_) * r_weight points[:2, :] += norm(-points_start[:2, :], axis=0) * r * np.cos(base_) * r_weight points[:2, :] += norm( -points_start[:2, :], axis=0 ) * 0.2 * p[-1] * r_weight # correct for radius problem when r = 0 # project to screen C = get_camera_matrix(t_x=np.pi / 4, z=1.2) points, z = project(C, points, (width, height)) # switch from points to lines and sort by depth lines = np.array([(points[i], points[(i + 1) % len(points)]) for i in range(len(points))]) z_lines = np.array([(z[i] + z[(i + 1) % len(z)]) / 2 for i in range(len(z))]) sort_indices = np.argsort(z_lines) lines = lines[sort_indices] z_lines = z_lines[sort_indices] # relative depth for shading z_min, z_max = z_lines.min(), z_lines.max() z_ratios = (z_lines - z_min) / (z_max - z_min) # draw lines for i in range(len(lines)): gz.polyline(points=lines[i], stroke_width=3 + 3 * z_ratios[i], stroke=[0.3 + 0.7 * z_ratios[i]] * 3, line_cap='round').draw(surface) return surface.get_npimage()
def prepare_data(): surface = gz.Surface(width, height) offset = np.array((width / 2, height / 2)) gz.square(l=width, xy=offset, fill=(0, 0, 0)).draw(surface) radius, corners, stroke_width = get_extinction_symbol_params(0.35 * width) gz.circle(r=radius, xy=offset, stroke=(1, 1, 1), stroke_width=stroke_width).draw(surface) gz.polyline(points=corners + offset, close_path=True, fill=None, stroke=(1, 1, 1), stroke_width=stroke_width).draw(surface) img = surface.get_npimage()[:, :, 0] img = gaussian_filter(img, sigma=width / 50, truncate=10) imsave(f'extinction_symbol_soft_{width}.png', img)
def make_frame(t): surface = gz.Surface(width=1920, height=1080) line = gz.polyline(points=[(200, max(180, 180 + 100 * t)), (100, max(180, 180 + 100 * t))], stroke_width=25, stroke=(1, 0, 0)) line.draw(surface) return surface.get_npimage(transparent=True)
def make_frame(t): progress = t / duration p = interval_progresses(progress, 4, ['ease_out', 'ease_in', 'ease_out', 'ease_in']) surface = gz.Surface(width, height) center = np.array((width / 2, height / 2)) # calculate 3D point coordinates angles = base * 2 * np.pi * (p[0] - p[1] - p[2] + p[3]) * 5 x = base y = np.cos(angles) * amplitudes z = np.sin(angles) * amplitudes # zip up points points_1 = np.vstack([x, y, z, np.ones(base.size)]) points_2 = np.vstack([-x, -y, z, np.ones(base.size)]) points = np.concatenate([points_1[:, :-1], points_2[:, :-1]], axis=1) # project to screen C = get_camera_matrix(t_z=np.pi / 4, t_x=2 * np.pi * progress) points, z = project(C, points, (width, height)) # switch from points to lines and sort by depth lines = np.array([(points[i], points[(i + 1) % len(points)]) for i in range(len(points))]) z_lines = np.array([(z[i] + z[(i + 1) % len(z)]) / 2 for i in range(len(z))]) sort_indices = np.argsort(z_lines) lines = lines[sort_indices] z_lines = z_lines[sort_indices] # relative depth for shading z_min, z_max = z_lines.min(), z_lines.max() z_middle = (z_min + z_max) / 2 z_ratios = (r + z_lines - z_middle) / (2 * r) # draw lines for i in range(len(lines)): gz.polyline(points=lines[i], stroke_width=3 + 3 * z_ratios[i], stroke=[0.3 + 0.7 * z_ratios[i]] * 3, line_cap='round').draw(surface) return surface.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(width, height) progress = t / duration head = int(round(len(points) * progress)) tail_length = len(points) for i in range(len(points)): i_ = i if (i < head) else (i - len(points)) segment_color = np.ones(3) * (1 - .75 * min(1, (head - i_) / tail_length)**.5) gz.polyline(points=(points[i, :], points[(i + 1) % len(points), :]), stroke=segment_color, stroke_width=4, line_cap='round').draw(surface) return surface.get_npimage()
def slide(self, alpha): """ create gizeh object :param alpha: current alpha :return: gizeh object """ sld = map(lambda x: x * .9, self.color) slider = gizeh.polyline(points=self.slider.curve, stroke_width=self.radius * 2 + 5, stroke=(*sld, alpha * .7), line_cap="round", line_join="round") return slider
def drawpolygon(self, points, style = donpolygon): P = list(points) if P[0] != P[-1]: P.append(P[0]) for s in style: polygon = gizeh.polyline(points=[list(p) for p in P], stroke_width = s.stroke_width, stroke = s.stroke, fill=s.fill) polygon.draw(self.surface)
def draw(self, surface, camera, scale_factor): scaled_vertices = [(scale_factor * v[0], -scale_factor * v[1]) for v in self.vertices] shape = gizeh.polyline( points=scaled_vertices, xy=camera.to_pixel_space( (self.body.position[0], self.body.position[1]), scale_factor), angle=-self.body.angle, fill=self.color) shape.draw(surface)
def make_arrow(surface, spacing, rect_width, arrow_x_offset, rect_x, bar_y, bar_height): arrow_width = spacing / 2 - rect_width / 2 points = [ (arrow_x_offset + rect_x + rect_width / 2, bar_y - bar_height / 2), (arrow_x_offset + rect_x + rect_width / 2 + arrow_width, bar_y - bar_height / 2), (arrow_x_offset + rect_x + spacing - rect_width / 2, bar_y + bar_height / 2), (arrow_x_offset + rect_x + rect_width / 2 + arrow_width, bar_y + bar_height * 3 / 2), (arrow_x_offset + rect_x + rect_width / 2, bar_y + bar_height * 3 / 2), (arrow_x_offset + rect_x + spacing - rect_width / 2 - arrow_width, bar_y + bar_height / 2), ] gz.polyline(points, close_path=True, stroke=[1, 1, 1], stroke_width=5, fill=rgb([251, 3, 1])).draw(surface)
def convert_quickdraw_strokes_to_gizeh_group(strokes, color=[0, 0, 0], stroke_width=5): lines_list = [] for stroke in strokes: x, y = stroke points = list(zip(x, y)) line = gz.polyline(points=points, stroke=color, stroke_width=stroke_width) lines_list.append(line) return gz.Group(lines_list)
def prepare_data(): surface = gz.Surface(2000, 2000) offset = np.array((1000, 1000)) gz.square(l=2000, xy=offset, fill=(0, 0, 0)).draw(surface) radius, corners, stroke_width = get_extinction_symbol_params(800) gz.circle(r=radius, xy=offset, stroke=(1, 1, 1), stroke_width=stroke_width).draw(surface) gz.polyline(points=corners + offset, close_path=True, fill=None, stroke=(1, 1, 1), stroke_width=stroke_width).draw(surface) surface.write_to_png('extinction_symbol.png') print('STIPPLING EXTINCTION SYMBOL') points = stipple_image_points('extinction_symbol.png', n_points=500, scale_factor=1, max_iterations=100) np.save('extinction_symbol', points)
def make_triangles(surface, constants, triangle_x, triangle_width, bar_y, bar_height): # Light triangle gz.polyline([ (triangle_x, bar_y - bar_height / 2), (triangle_x + triangle_width, bar_y + bar_height / 2), (triangle_x, bar_y + bar_height / 2), ], close_path=True, fill=constants.line_color).draw(surface) # Dark triangle if constants.theme.lower() != 'tokyu': color = constants.line_color_dark else: color = constants.line_color gz.polyline([ (triangle_x, bar_y + bar_height / 2), (triangle_x + triangle_width, bar_y + bar_height / 2), (triangle_x, bar_y + bar_height * 3 / 2), ], close_path=True, fill=color).draw(surface)
def export_png(): print dimensions import gizeh width = int(dimensions['maxx'] - dimensions['minx']) height = int(dimensions['maxy'] - dimensions['miny']) print width, height surface = gizeh.Surface(width=width, height=height) # in pixels for shot in shots: line = gizeh.polyline( points=[fix_coord(shot[0]), fix_coord(shot[1])], stroke_width=2, stroke=(0.5,0.5,0.5)) line.draw(surface) for sketchl in sketchlines: color = sketchl[0] points = sketchl[1] line = gizeh.polyline( points=[fix_coord(x) for x in points], stroke_width=1, stroke=colors[color]) line.draw(surface) # gizeh.rectangle(lx=60.3, ly=45, xy=(60,70), fill=(0,1,0), angle=Pi/8) surface.write_to_png("test.png") # export the surface as a PNG
def lines(interval, sw, opacity): #for loop for lines a = -(Pi / 2) interval = (interval / 72) * 2 * Pi while a < (Pi * 2 - (Pi / 2)): xc = w / 2 + ring_rad * 2 * math.cos(a) yc = h / 2 + ring_rad * 2 * math.sin(a) x1 = w / 2 + (radius - 10) * math.cos(a) y1 = h / 2 + (radius - 10) * math.sin(a) line = g.polyline(points=[(x1, y1), (xc, yc)], stroke_width=sw, stroke=(1, 1, 1, opacity)) line.draw(surface) a = a + interval
def make_frame(t): surface = gz.Surface(R, R) background = gz.square(l=R, xy= [R/2,R/2], fill = (1,1,1,1)) background.draw(surface) points = [] a = A * t / DURATION b = B * t / DURATION m = M * t / DURATION n1 = N1 * (t + 1.0) / DURATION n2 = N2 * t / DURATION n3 = N3 * t / DURATION for i in range(NPOINTS): theta = 2 * np.pi * i / NPOINTS r = sf(A, B, M, N1, n2, n3, theta) * R/4 points.append((r * np.cos(theta), r * np.sin(theta))) line = gz.polyline(points, stroke=(0,0,0,1), stroke_width=0.4) line.translate([R/2,R/2]).draw(surface) im = surface.get_npimage() return im
def make_frame(t): surface = gz.Surface(W,H) for k, (c1,c2) in enumerate([[(.7,0.05,0.05),(1,0.5,0.5)], [(0.05,0.05,.7),(0.5,0.5,1)]]): grad = gz.ColorGradient("linear",xy1=(0,0), xy2 = (1,0), stops_colors= [(0,c1),(1,c2)]) r = min(np.pi/2,max(0,np.pi*(t-D/3)/D)) triangle = gz.polyline(points,xy=(-0.5,0.5), fill=grad, angle=r, stroke=(1,1,1), stroke_width=.02) square = gz.Group([triangle.rotate(i*np.pi/2) for i in range(4)]) squares = (gz.Group([square.translate((2*i+j+k,j)) for i in range(-3,4) for j in range(-3,4)]) .scale(WSQ) .translate((W/2-WSQ*t/D,H/2))) squares.draw(surface) return surface.get_npimage()
def make_frame(t): surface = gz.Surface(W,H) centerPoints = [] r = W / 2 * 0.8 for i in range(NFACES*2): th = float(i) * ((2 * np.pi) / float(NFACES * 2)) #center = gz.polar2cart(r, th) #center = gz.polar2cart(r, th) center = polar_ngon_to_cart(NFACES, r, th) print "center",center centerPoints.append(center) color= (0.9, 0.9, 0.9) dot = gz.circle(r=4.0, xy= center, fill=color).translate((W/2, H/2)) dot.draw(surface) line = gz.polyline(points=centerPoints, stroke_width=1, stroke=(1, 0, 0)).translate((W/2, H/2)) line.draw(surface) im = surface.get_npimage() return im
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()
# Let's draw a red circle ! import gizeh surface = gizeh.Surface(width=320, height=260) # in pixels circle = gizeh.circle(r=300, xy= [40,40], fill=(1,0,0)) circle.draw(surface) # draw the circle on the surface points = [] point1 = [10, 10] point2 = [20, 10] point3 = [20, 20] point4 = [50, 40] points.append(point1) points.append(point2) points.append(point3) points.append(point4) polyline = gizeh.polyline(points, stroke=[0,0,0], stroke_width=1) polyline.draw(surface) surface.write_to_png("circle.png") # export the surface as a PNG
query = f.read() os.remove(os.getcwd()+"/target") surface = gizeh.Surface(width=IMAGE_SIZE+IMAGE_BORDER*2, height=IMAGE_SIZE+IMAGE_BORDER*2, bg_color=(1, 1, 1)) g = gizeh.Group([]) line = [] size = random.randint(10, 25) for i in range(2, size): x = random.randint(1, int(sqrt(i-1)))*IMAGE_SIZE/int(sqrt(i)+1) y = random.randint(1, int(sqrt(i-1)))*IMAGE_SIZE/int(sqrt(i)+1) # If now is the time for an arc if random.randint(1, CURVE_CHANCE) == 2 and i>2 and not (old_x == x and old_y == y): # Finish the previous linegroup prevline = gizeh.polyline(line, stroke_width=5) line = [] vx, vy = x-old_x, y-old_y distance = hypot(vx, vy) radius = distance*(random.random()/2 + 0.5) mid_x, mid_y = old_x+vx/2, old_y+vy/2 sgn = random.choice([1, -1]) # 90 degrees rotated, direction random hvx, hvy = -vy*sgn, vx*sgn hlength = sqrt(radius**2 - (distance/2)**2) f = hlength/distance center_x, center_y = mid_x+f*hvx, mid_y+f*hvy arc = gizeh.arc(radius, atan2(old_y-center_y, old_x-center_x), atan2(y-center_y, x-center_x), xy=[center_x+IMAGE_BORDER, center_y+IMAGE_BORDER], stroke_width=5) g = gizeh.Group([g, prevline, arc])
def ray(R, theta, center, **kw): x,y = center dx,dy = gizeh.polar2cart(R, theta) return gizeh.polyline(points=[(x,y), (x+dx,y+dy)], **kw)