def line(draw, data, color="black", width=1, arrow="both", arrowshape=(8, 10, 3)): data = list(data) last = first = None if arrow == "first" or arrow == "both": lxy, first = arrowhead((data[0], data[1]), (data[2], data[3]), width, arrowshape) data[0], data[1] = lxy[0], lxy[1] if arrow == "last" or arrow == "both": lxy, last = arrowhead((data[-2], data[-1]), (data[-4], data[-3]), width, arrowshape) data[-2], data[-1] = lxy[0], lxy[1] draw.line(data, aggdraw.Pen(color, width)) if first: draw.polygon(first, aggdraw.Brush(color)) if last: draw.polygon(last, aggdraw.Brush(color))
def rendr(self): self.frame.unbind('<Button-1>') self.frame.grid_forget() self.dib.clear() if self.tp == 'sp': leaf(self.dib, 'red', 67) leaf(self.dib, 'red', 157) leaf(self.dib, 'red', 247) leaf(self.dib, 'red', 337) leaf(self.dib, 'blue', 22) leaf(self.dib, 'blue', 112) leaf(self.dib, 'blue', 202) leaf(self.dib, 'blue', 292) self.dib.ellipse((43, 43, 57, 57), agg.Pen("black", 1), agg.Brush("red")) if self.bid['c'] == 'D' or self.bid['c'] == 'B': if self.bid['c'] == 'D': x = '#fff' col = 'white' else: x = '#000' col = 'black' self.dib.ellipse((20, 20, 80, 80), agg.Brush(col)) if self.tp == 'bg' or self.tp == 'ed': dotmap(self.dib, self.q) if x == rnumb.trn: self.frame.bind( '<Button-1>', lambda eff: klyk(eff, self.bid['n'], rnumb.a, iface)) self.frame.bind("<Expose>", lambda e: self.dib.expose(hwnd=e.widget.winfo_id())) self.frame.grid(column=self.x, row=self.y)
def draw_image(self, fpath=None): """ Draws a png image of the individual. Returns: image: A png image of the individual. """ image = Image.new("RGB", self.size, color="white") draw = aggdraw.Draw(image) for poly, color, height in zip(self.polygons, self.colors, self.heights): # get x, y sequence of coordinates for each polygon xy = poly.exterior.xy coords = np.dstack((xy[1], xy[0])).flatten() # create a brush according to each polygon color if(height == 0.0): brush = aggdraw.Brush((255, 255, 255), opacity=255) else: brush = aggdraw.Brush((color[0], color[1], color[2]), opacity=255) draw.polygon(coords, brush) image = Image.frombytes("RGB", self.size, draw.tobytes()).rotate(90) if(fpath): image.save(fpath) return image
def draw_eye(self, idx, image): eye_base = self.eye_base.copy() # center = (17, 35) canvas = aggdraw.Draw(eye_base) pen = aggdraw.Pen("black", 0) brush = aggdraw.Brush("black", 255) if idx > 70: canvas.ellipse( (55 / 2. - 12, 63 / 2. - 12, 55 / 2. + 12, 63 / 2. + 12), pen, brush) else: canvas.ellipse((17 - 12, 35 - 12, 17 + 12, 35 + 12), pen, brush) pen = aggdraw.Pen("black", 1) brush = aggdraw.Brush((240, 240, 240), 255) if idx > 70: lev = 44 * math.sin(max(0, 5 - (idx - 70)) / 3.) else: lev = 44 * math.sin(min(5, max(idx - 50, 0)) / 3.) canvas.ellipse( (27.5 - 100, -90 + lev - 100, 27.5 + 100, -90 + lev + 100), pen, brush) canvas.flush() eye_left = eye_base.copy() eye_left.paste(self.eye_left, (0, 0), self.eye_left) eye_right = eye_base eye_right.paste(self.eye_right, (0, 0), self.eye_right) image.paste(eye_left, (747, 258)) image.paste(eye_right, (607, 256))
def draw(self, draw: ImageDraw): pen, brush = self._get_pen_brush() if hasattr(self, 'de') and self.de > 0: brush_s1 = aggdraw.Brush(fade_color(self.fill, self.shade)) brush_s2 = aggdraw.Brush(fade_color(self.fill, 2 * self.shade)) draw.line([ self.x1 + self.de, self.y1 - self.de, self.x1 + self.de, self.y2 - self.de ], pen) draw.line([self.x1 + self.de, self.y2 - self.de, self.x1, self.y2], pen) draw.line([ self.x1 + self.de, self.y2 - self.de, self.x2 + self.de, self.y2 - self.de ], pen) draw.polygon([ self.x1, self.y1, self.x1 + self.de, self.y1 - self.de, self.x2 + self.de, self.y1 - self.de, self.x2, self.y1 ], pen, brush_s1) draw.polygon([ self.x2 + self.de, self.y1 - self.de, self.x2, self.y1, self.x2, self.y2, self.x2 + self.de, self.y2 - self.de ], pen, brush_s2) draw.rectangle([self.x1, self.y1, self.x2, self.y2], pen, brush)
def roundCorner(image, radius): """ Generate the rounded corner image for orgimage. """ image = image.convert('RGBA') # generate the mask image mask = Image.new('RGBA', image.size, (0, 0, 0, 0)) draw = aggdraw.Draw(mask) brush = aggdraw.Brush('black') width, height = mask.size draw.rectangle((0, 0, mask.size[0], mask.size[1]), aggdraw.Brush('white')) # north-west corner draw.pieslice((0, 0, radius * 2, radius * 2), 90, 180, None, brush) # north-east corner draw.pieslice((width - radius * 2, 0, width, radius * 2), 0, 90, None, brush) # south-west corner draw.pieslice((0, height - radius * 2, radius * 2, height), 180, 270, None, brush) # south-east corner draw.pieslice((width - radius * 2, height - radius * 2, width, height), 270, 360, None, brush) # center rectangle draw.rectangle((radius, radius, width - radius, height - radius), brush) # four edge rectangle draw.rectangle((radius, 0, width - radius, radius), brush) draw.rectangle((0, radius, radius, height - radius), brush) draw.rectangle((radius, height - radius, width - radius, height), brush) draw.rectangle((width - radius, radius, width, height - radius), brush) draw.flush() del draw return ImageChops.add(mask, image)
def draw_outliers(ps, outliers, ok, pic_size=(640, 480), is_axis=True, grid=None, filename=None): """ Draw outliers. Arguments: ps -- points, outliers -- list of outliers, ok -- outliers count (leaders), pic_size -- picture size, is_axis -- need to draw axis, grid -- grid lines characteristics, filename -- file name for picture. """ # Points characteristics. min_coords = reduce(lambda p1, p2: (min(p1[0], p2[0]), min(p1[1], p2[1])), ps[1:], ps[0]) max_coords = reduce(lambda p1, p2: (max(p1[0], p2[0]), max(p1[1], p2[1])), ps[1:], ps[0]) # Drawer ini. D = Drawer(draw_area=min_coords + max_coords, pic_size=pic_size) # Axis. if is_axis: D.Axis() # Grid. if grid != None: D.Grid(grid) # Draw points. red_pen = aggdraw.Pen('red', 1.0) red_brush = aggdraw.Brush('red') for p in ps: D.Point(p, 3, red_pen, red_brush) # Draw outliers. black_pen = aggdraw.Pen('black', 2.0) steelblue_brush = aggdraw.Brush('steelblue') for outlier in outliers[ok:]: (r, p) = outlier D.Point(p, 3 * r, black_pen) for outlier in outliers[:ok]: (r, p) = outlier D.Point(p, 3 * r, black_pen, steelblue_brush) D.Point(p, 3, red_pen, red_brush) # Flush save and show. D.FSS(filename=filename)
def draw_hierarchical_tree_on_img(ht, c, deltas, margins, pen, drawing_type): """ Draw hierarchical tree on image. Arguments: ht -- hierarchical tree, c -- canvas, deltas -- distances between nodes, margins -- margins, pen -- pen, drawing_type -- drawing type. """ # Pens and brushes. mark_pen = aggdraw.Pen('red', 2.0) brush = aggdraw.Brush('silver') # Change color for subtree. if ht.Mark: pen = aggdraw.Pen(pretty_color(ht.KN), 2.0) # Coordinates. p = NodeCoordinates(ht, deltas, margins) # Draw children. for ch in ht.Children: chp = NodeCoordinates(ch, deltas, margins) # Define line pen. line_pen = pen if ht.IsOutlier and ch.IsOutlier: line_pen = aggdraw.Pen('black', 1.0) if drawing_type == ClusteringDrawingType.Lines: c.line(p + chp, line_pen) elif drawing_type == ClusteringDrawingType.Orthogonal: (px, py) = p (chpx, chpy) = chp c.line((px, py, chpx, py, chpx, chpy), line_pen) else: raise Exception('wrong drawing type : %s' % str(drawing_type)) draw_hierarchical_tree_on_img(ch, c, deltas, margins, pen, drawing_type) # Draw point. if ht.IsOutlier: c.ellipse(expand_to_circle(p, 5), aggdraw.Pen('black', 2.0), aggdraw.Brush('black')) else: c.ellipse(expand_to_circle(p, 3), pen, brush) if ht.Mark: c.ellipse(expand_to_circle(p, 10), mark_pen)
def showImage(_list_xy): im = Image.open(path).convert("RGBA") drawT = ImageDraw.Draw(im) draw = aggdraw.Draw(im) print(_list_xy) pen = aggdraw.Pen((0, 0, 0)) brush = aggdraw.Brush((0, 0, 0)) outline = aggdraw.Pen((0, 0, 0), 5) flag = 0 for xy_order in range(0, int((len(_list_xy) - 1) / 3)): #ezier = "m 0,0 t" for coordintes in range(0, 3): if (flag == 0): flag = 1 p0x = _list_xy[xy_order * 3]["x"] p0y = _list_xy[xy_order * 3]["y"] p0_x = _list_xy[xy_order * 3]["x"] p0_y = _list_xy[xy_order * 3]["y"] p1_x = _list_xy[xy_order * 3 + 1]["x"] p1_y = _list_xy[xy_order * 3 + 1]["y"] p2_x = _list_xy[xy_order * 3 + 2]["x"] p2_y = _list_xy[xy_order * 3 + 2]["y"] p3_x = _list_xy[xy_order * 3 + 3]["x"] p3_y = _list_xy[xy_order * 3 + 3]["y"] draw.ellipse((p0_x - 10, p0_y - 10, p0_x + 10, p0_y + 10), brush) p0 = str(p0_x) + "," + str(p0_y) p1 = str(_list_xy[xy_order * 3 + 1]["x"] - p0_x) + "," + str(_list_xy[xy_order * 3 + 1]["y"] - p0_y) + "," p2 = str(_list_xy[xy_order * 3 + 2]["x"] - p0_x) + "," + str(_list_xy[xy_order * 3 + 2]["y"] - p0_y) + "," p3 = str(_list_xy[xy_order * 3 + 3]["x"] - p0_x) + "," + str(_list_xy[xy_order * 3 + 3]["y"] - p0_y) draw.ellipse((p0_x - 3, p0_y - 3, p0_x + 3, p0_y + 3), pen) draw.ellipse((p3_x - 10, p3_y - 10, p3_x + 10, p3_y + 10), brush) draw.ellipse((p3_x - 3, p3_y - 3, p3_x + 3, p3_y + 3), pen) bezier = "m " + p0 + "c " + p1 + p2 + p3 print(bezier) symbol = aggdraw.Symbol(bezier) draw.symbol((0, 0), symbol, outline) spen = aggdraw.Pen((120, 120, 120)) sbrush = aggdraw.Brush((120, 120, 120)) draw.ellipse((p0x - 10, p0y - 10, p0x + 10, p0y + 10), sbrush) draw.ellipse((p0x - 3, p0y - 3, p0x + 3, p0y + 3), spen) draw.flush() #drawTime(_list_xy) im.save('draw\\result\\out.png')
def draw_lines(self, coords, **options): """ Connect a series of flattened coordinate points with one or more lines. """ path = aggdraw.Path() def traverse_ring(coords): # begin coords = grouper(coords, 2) startx, starty = next(coords) path.moveto(startx, starty) # connect to each successive point for nextx, nexty in coords: path.lineto(nextx, nexty) # get drawing tools from options args = [] if options["outlinecolor"]: pen = aggdraw.Pen(options["outlinecolor"], options["outlinewidth"]) args.append(pen) if options["fillcolor"]: brush = aggdraw.Brush(options["fillcolor"]) args.append(brush) # draw the constructed path self.drawer.path((0, 0), path, *args)
def fill_region(self, points, color='blue', opacity=128): brush = aggdraw.Brush(color, opacity) pen = aggdraw.Pen(color, width=0, opacity=0) corrected_points = [] for p in points: corrected_points.extend([p[0], p[1]]) self.draw.polygon(corrected_points, pen, brush)
def round_corner_jpg(image, radius): """generate round corner for image""" mask = Image.new('L', image.size) # filled with black by default draw = aggdraw.Draw(mask) brush = aggdraw.Brush('white') width, height = mask.size # upper-left corner draw.pieslice((0, 0, radius * 2, radius * 2), 90, 180, None, brush) # upper-right corner draw.pieslice((width - radius * 2, 0, width, radius * 2), 0, 90, None, brush) # bottom-left corner draw.pieslice((0, height - radius * 2, radius * 2, height), 180, 270, None, brush) # bottom-right corner draw.pieslice((width - radius * 2, height - radius * 2, width, height), 270, 360, None, brush) # center rectangle draw.rectangle((radius, radius, width - radius, height - radius), brush) # four edge rectangle draw.rectangle((radius, 0, width - radius, radius), brush) draw.rectangle((0, radius, radius, height - radius), brush) draw.rectangle((radius, height - radius, width - radius, height), brush) draw.rectangle((width - radius, radius, width, height - radius), brush) draw.flush() image = image.convert('RGBA') image.putalpha(mask) return image
def _draw_ellipse(self, draw, coordinates, **kwargs): """Draw ellipse.""" pen = aggdraw.Pen(kwargs['outline']) fill_opacity = kwargs.get('fill_opacity', 255) brush = aggdraw.Brush(kwargs['fill'], fill_opacity) draw.ellipse(coordinates, brush, pen)
def _draw_rectangle(self, draw, coordinates, **kwargs): """Draw rectangle.""" pen = aggdraw.Pen(kwargs['outline']) fill_opacity = kwargs.get('fill_opacity', 255) brush = aggdraw.Brush(kwargs['fill'], fill_opacity) draw.rectangle(coordinates, pen, brush)
def _drawTemplate(self): """Draw the target on the base template""" img = Image.new(mode='RGBA', size=(self._template_size, self._template_size), color=(0, 0, 0, 0)) ctx = aggdraw.Draw(img) brush = aggdraw.Brush(self._color, 255) # # Draw the form of the target # self._drawForm(ctx, brush) # # Add letter. # if self._letter is not None: self._drawLetter(ctx) # # Flush to apply drawing. # ctx.flush() img = np.array(img) self._templateImg, self._templateAlpha = img[ ..., :3], img[..., 3].astype(np.float32) / 255
def __init__(self, unit): self.black_pen = aggdraw.Pen("black", 1, opacity=255) self.thick_black_pen = aggdraw.Pen("black", 1.5, opacity=255) self.highlight_pen = aggdraw.Pen("#ffff00", 6, opacity=255) self.white_brush = aggdraw.Brush("white", opacity=255) self.affected_brush = aggdraw.Brush("#bbbbbb", opacity=255) self.black_brush = aggdraw.Brush("black", opacity=255) self.margin = (unit * 3) / 5 self.width = (unit + 2 * self.margin) self.height = (unit + 2 * self.margin) self.left = self.margin + 0.5 self.top = self.margin + 0.5 self.right = unit + self.margin + 0.5 self.bottom = unit + self.margin + 0.5
def render(out_file, contours, size): s = "" for contour in contours: for i, curve in enumerate(contour): for j, pair in enumerate(curve): pair = pair * size * 0.8 pair = pair.astype(np.int32) if (i == 0) and (j == 0): s += "M{:d},{:d} ".format(pair[0], pair[1]) elif j == 1: s += "Q{:d},{:d}".format(pair[0], pair[1]) elif j == 2: s += ",{:d},{:d} ".format(pair[0], pair[1]) img = Image.new("RGB", (size, size)) draw = aggdraw.Draw(img) outline = aggdraw.Pen("white", 1) fill = aggdraw.Brush("white") symbol = aggdraw.Symbol(s) pos = int(.1 * size) xy = (pos, pos) draw.symbol(xy, symbol, outline, fill) draw.flush() img = img.transpose(Image.FLIP_TOP_BOTTOM) img.save(out_file)
def _draw_rectangle(self, draw, xys, outline='white', bg='white', bg_opacity=255, outline_width=1, outline_opacity=255, **kwargs): import aggdraw pen = aggdraw.Pen(outline, width=outline_width, opacity=outline_opacity) brush = aggdraw.Brush(bg, opacity=bg_opacity) # draw bg and outline # bg unaliased (otherwise gaps between successive bgs) if bg is not None: draw.setantialias(False) draw.rectangle(xys, None, brush) draw.setantialias(True) # adjust to correct for outline exceeding requested area, # due to outline width expanding outwards. xys[0] += outline_width / 2.0 xys[1] += outline_width / 2.0 xys[2] -= outline_width / 2.0 xys[3] -= outline_width / 2.0 if outline is not None: draw.rectangle(xys, pen, None)
def draw(self, frame, image, b=None): if frame < self.startTime: return if b is None: b = aggdraw.Brush("white", 255) idx = frame - self.startTime y = int(self.pos_y + .2 * idx) if self.hover else self.pos_y - 2 * idx x = self.pos_x - 2 * self.randomShift * math.sqrt(idx) radius = int(max(self.radius - 2 * idx / 2., 5)) hdx = min(int(self.radius + 8 * idx / 2.), (self.image.size[0] + radius) / 2) hdy = min(int(self.radius + 8 * idx / 4.), (self.image.size[1] + radius) / 2) d = aggdraw.Draw(image) p = aggdraw.Pen("black", 2.5) RCRectengular.draw(d, (x - hdx, y - hdy, x + hdx, y + hdy), radius, p, b) d.flush() textbox = self.image.resize( (2 * hdx - 2 * radius, 2 * hdy - 2 * radius), Image.ANTIALIAS) textMask = Image.new("L", textbox.size, "black") color = idx * 10 textMask.paste((color), (0, 0), textbox) image.paste("black", (int(x) - hdx + radius, y - hdy + radius), textMask)
def get_pen_and_fill(self, vmobject): pen = aggdraw.Pen(self.color_to_hex_l(self.get_stroke_color(vmobject)), max(vmobject.stroke_width, 0)) fill = aggdraw.Brush(self.color_to_hex_l( self.get_fill_color(vmobject)), opacity=int(255 * vmobject.get_fill_opacity())) return (pen, fill)
def generate_mask(self): # Set mask size canvas_size = deg_to_px(1) # Set cell size cell_size = canvas_size / 5 # Mask comprised of 16 smaller cells arranged 4x4 # Each cell has a black outline cell_outline_width = deg_to_px(.05) # Initialize canvas to be painted w/ mask cells canvas = Image.new('RGBA', [canvas_size, canvas_size], (0, 0, 0, 0)) surface = aggdraw.Draw(canvas) # Initialize pen to draw cell outlines transparent_pen = aggdraw.Pen((0, 0, 0), cell_outline_width) # Generate cells, arranged in 4x4 array for row in [0, 1, 2, 3, 4]: for col in [0, 1, 2, 3, 4]: # Randomly select colour for each cell cell_colour = const_lum[random.randrange(0, 360)] # Brush to apply colour colour_brush = aggdraw.Brush(tuple(cell_colour[:3])) # Determine cell boundary coords top_left = (row * cell_size, col * cell_size) bottom_right = ((row + 1) * cell_size, (col + 1) * cell_size) # Create cell surface.rectangle((top_left[0], top_left[1], bottom_right[0], bottom_right[1]), transparent_pen, colour_brush) # Apply cells to mask surface.flush() return np.asarray(canvas)
def draw(d, rec, radius, p, b=None): if b == None: b = aggdraw.Brush("white", 255) d.rectangle((rec[0] + radius, rec[1], rec[2] - radius, rec[3]), None, b) d.rectangle( (rec[0], rec[1] + radius, rec[0] + radius, rec[3] - radius), None, b) d.rectangle( (rec[2], rec[1] + radius, rec[2] - radius, rec[3] - radius), None, b) d.pieslice((rec[0], rec[1], rec[0] + 2 * radius, rec[1] + 2 * radius), 90, 180, None, b) d.pieslice((rec[2] - 2 * radius, rec[1], rec[2], rec[1] + 2 * radius), 0, 90, None, b) d.pieslice((rec[0], rec[3] - 2 * radius, rec[0] + 2 * radius, rec[3]), 180, 270, None, b) d.pieslice((rec[2] - 2 * radius, rec[3] - 2 * radius, rec[2], rec[3]), 270, 360, None, b) d.line((rec[0] + radius, rec[1], rec[2] - radius, rec[1]), p) d.line((rec[0] + radius, rec[3], rec[2] - radius, rec[3]), p) d.line((rec[0], rec[1] + radius, rec[0], rec[3] - radius), p) d.line((rec[2], rec[1] + radius, rec[2], rec[3] - radius), p) d.arc((rec[0], rec[1], rec[0] + 2 * radius, rec[1] + 2 * radius), 90, 180, p) d.arc((rec[2] - 2 * radius, rec[1], rec[2], rec[1] + 2 * radius), 0, 90, p) d.arc((rec[0], rec[3] - 2 * radius, rec[0] + 2 * radius, rec[3]), 180, 270, p) d.arc((rec[2] - 2 * radius, rec[3] - 2 * radius, rec[2], rec[3]), 270, 360, p)
def rounded_rectangle(draw, x, y, w, h, corner_radius, fill=None, outline=None): fill = aggdraw.Brush(fill) if w < corner_radius: corner_radius = w if h < corner_radius: corner_radius = h w = w + x h = h + y draw.rectangle((x, y + corner_radius, w, h - corner_radius), fill, outline) draw.rectangle((x + corner_radius, y, w - corner_radius, h), fill, outline) draw.pieslice([x, y, x + corner_radius * 2, y + corner_radius * 2], 180, 270, fill, outline) draw.pieslice([w - corner_radius * 2, h - corner_radius * 2, w, h], 0, 90, fill, outline) draw.pieslice([x, h - corner_radius * 2, x + corner_radius * 2, h], 90, 180, fill, outline) draw.pieslice([w - corner_radius * 2, y, w, y + corner_radius * 2], 270, 360, fill, outline)
def generate_mask(self): # Set mask size canvas_size = deg_to_px(1) # Set cell size cell_size = canvas_size / 8 # Mask comprised of 64 smaller cells arranged 8x8 # Each cell has a black outline cell_outline_width = deg_to_px(.01) # Initialize canvas to be painted w/ mask cells canvas = Image.new('RGBA', [canvas_size, canvas_size], (0,0,0,0)) surface = aggdraw.Draw(canvas) # Initialize pen to draw cell outlines transparent_pen = aggdraw.Pen((0,0,0),cell_outline_width) # Generate cells for row in range(0,15): for col in range(0,15): # Randomly select colour for each cell cell_fill = random.choice([WHITE, BLACK]) # Brush to apply colour fill_brush = aggdraw.Brush(tuple(cell_fill[:3])) # Determine cell boundary coords top_left = (row * cell_size, col * cell_size) bottom_right = ((row+1) * cell_size, (col+1) * cell_size) # Create cell surface.rectangle( (top_left[0], top_left[1], bottom_right[0], bottom_right[1]), transparent_pen, fill_brush) # Apply cells to mask surface.flush() return np.asarray(canvas)
def _create_lane_connections_image(node: Node) -> Image: """Generate image showing lane connections on a node.""" image = Image.new('RGBA', (RESOLUTION, RESOLUTION)) draw = aggdraw.Draw(image) colors = dict(zip(node.oriented_ways, cycle(COLORS))) for lanes, points in node.intersection.iterate_connections_curve_points(): start, crossing, end = map(Vector.y_flipped, (p * PPM + MIDDLE for p in points)) vector = lanes[1].way.direction_from_node(node, lanes[1].endpoint) vector = vector.normalized().rotated(pi * 1.125).y_flipped() * 32.0 path = aggdraw.Path() path.moveto(*start) path.curveto(*start, *crossing, *end) path.lineto(*(end + vector)) draw.path( path, aggdraw.Pen(colors[lanes[0].oriented_way.flipped()], 0.25 * PPM, 224)) pen = aggdraw.Pen('black', 1, 192) brush = { ConflictPointType.DIVERGE: aggdraw.Brush('green', 192), ConflictPointType.MERGE: aggdraw.Brush('yellow', 192), ConflictPointType.CROSSING: aggdraw.Brush('white', 192) } cpoints = set(p for _, p in chain.from_iterable( c.conflict_points for c in node.intersection.curves.values())) for cpoint in cpoints: point = (cpoint.point * PPM + MIDDLE).y_flipped() draw.ellipse(point.enclosing_rect(0.25 * PPM), pen, brush[cpoint.type]) text = str(cpoint.id) width, height = draw.textsize(text, FONT) draw.text((point.x - width / 2, point.y - height / 2), text, FONT) pen = aggdraw.Pen('black', 1, 32) for cpoint in cpoints: for neighbor in cpoint.neighbors: points = ((p.point * PPM + MIDDLE).y_flipped() for p in (cpoint, neighbor)) draw.line(tuple(chain.from_iterable(points)), pen) draw.flush() # image.show() return image
def create() -> Image: """Generate the texture.""" image = Image.new('RGBA', (1, 1)) draw = aggdraw.Draw(image) draw.rectangle((0, 0, 1, 1), None, aggdraw.Brush((131, 150, 73))) draw.flush() # image.show() return image
def draw(self, caller, image): canvas = aggdraw.Draw(image) pen = aggdraw.Pen("black", 0) regions = [[2, aggdraw.Brush("grey", 255)]] regions.append([3, aggdraw.Brush((221, 63, 35), 255)]) regions.append([4, aggdraw.Brush((170, 136, 0), 255)]) regions.append([5, aggdraw.Brush((33, 181, 0), 255)]) for region in regions: brush = region[1] area = self.parser.get_path(region[0]) path = [] for coord in area: cc = caller([-100 + coord[0], 0, 100 - coord[1]]) path.append(cc[0]) path.append(cc[1]) canvas.polygon(path, pen, brush) canvas.flush()
def draw(self): draw = aggdraw.Draw('RGBA', IMAGE_SIZE, 0x0) for poly in self.dna: draw.ellipse(poly['ellipse'], aggdraw.Brush(poly['color'])) draw.flush() return Image.fromstring('RGBA', IMAGE_SIZE, draw.tostring())
def __init__(self, startTime, images, pos_x): self.lenguage = languages.ENGLISH self.images = images self.bubble1 = TimedBubble(pos_x, 358, 10, startTime, 30) self.bubble2 = TimedBubble(pos_x, 318, 15, startTime + 10, 20) self.bubble3 = TimedBubble(pos_x, 268, 20, startTime + 20, 10) self.rectangualar = MorphingTextBox(images[languages.ENGLISH], pos_x, 268, 20, startTime + 30) self.brush = aggdraw.Brush((248, 240, 118), 255)
def leaf(zgz, c, d): d -= 40 d2 = d + 180 rad = (d / 180) * mth.pi rad2 = ((d + 80) / 180) * mth.pi chordstartx = mth.cos(rad) * 35 chordstarty = mth.sin(rad) * 35 chordendx = mth.cos(rad2) * 35 chordendy = mth.sin(rad2) * 35 zgz.chord((15 - chordstartx, 15 + chordstarty, 85 - chordstartx, 85 + chordstarty), d, d + 80, agg.Pen(c, 0), agg.Brush(c)) zgz.chord((15 + chordendx, 15 - chordendy, 85 + chordendx, 85 - chordendy), d2, d2 + 80, agg.Pen(c, 0), agg.Brush(c))