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 aggPen(wxPen): if wxPen.GetStyle() == wx.TRANSPARENT: return aggdraw.Pen('Black', 1, 0) else: colour = wxPen.GetColour() return aggdraw.Pen((colour.Red(), colour.Green(), colour.Blue()), wxPen.GetWidth() or 1)
def pageflip(image1, image2, imax, callback): image1 = image1.convert("RGBA") image2 = image2.convert("RGBA") rect_right = [[640, 0], [1280, 0], [1280, 720], [640, 720]] rect_left = [[0, 0], [640, 0], [640, 720], [0, 720]] imax = imax / 2 for i in range(0, imax): om1 = Image.new("RGBA", (1280, 720), "white") om2 = Image.new("RGBA", (1280, 720), "white") rad = -i / (2.0 * imax) * math.pi dz = 640 * math.sin(rad) C = 2000 dx = 640 * math.cos(rad) * C / (C + dz) dy = 360 * C / (C + dz) pa = [[640, 0], [640 + dx, 360 - dy], [640 + dx, 360 + dy], [640, 720]] data = helpers.find_coeffs(pa, rect_right).tolist() tm = image1.transform((1280, 720), Image.PERSPECTIVE, data, Image.BICUBIC).crop((640, 0, 1280, 720)) rad = -i / (2.0 * imax) * math.pi dz = 640 * math.sin(rad) C = 2000 dx = 640 * math.cos(rad) * C / (C + dz) dy = 360 * C / (C + dz) pa = [[640 - dx, 360 - dy], [640, 0], [640, 720], [640 - dx, 360 + dy]] data = helpers.find_coeffs(pa, rect_left).tolist() tm2 = image2.transform((1280, 720), Image.PERSPECTIVE, data, Image.BICUBIC).crop((0, 0, 640, 720)) om1.paste(image1.crop((0, 0, 640, 720)), (0, 0)) om1.paste(image2.crop((640, 0, 1280, 720)), (640, 0)) if i == 0: om = om1.copy() d = aggdraw.Draw(om) p = aggdraw.Pen("black", 0.5) d.line((640, 0, 640, 720), p) d.flush() callback(om, imax) om2.paste(om1, (0, 0)) om1.paste(tm, (640, 0), tm) d = aggdraw.Draw(om1) p = aggdraw.Pen("black", 0.5) d.line((640 + dx, 0, 640 + dx, 720), p) d.flush() om2.paste(tm2, (0, 0), tm2) d = aggdraw.Draw(om2) p = aggdraw.Pen("black", 0.5) d.line((640 - dx, 0, 640 - dx, 720), p) d.flush() callback(om1, i) callback(om2, 2 * imax - i)
def render(self, trace=None, smooth=True): """Renders the figure (and optionally a provided participant tracing) to a numpy array texture that can be drawn to the screen. Args: trace (list, optional): A list of (x, y) tuples containing a participant tracing to be drawn on top of the figure. smooth (bool, optional): A flag indicating whether to draw the figure smoothly or by drawing lines between the frames from the last prepare_animation call. Defaults to True. """ # Initialize drawing surface canvas = Image.new("RGBA", P.screen_x_y, (0, 0, 0, 255)) surf = aggdraw.Draw(canvas) # Draw figure to surface if smooth: s = segments_to_symbol(self.raw_segments) surf.symbol((0, 0), s, aggdraw.Pen(P.stimulus_feedback_color, 1, 255)) else: path = frames_to_path(self.a_frames, unique=True) surf.path(path, aggdraw.Pen(P.stimulus_feedback_color, 1, 255)) # If tracing, draw trace to surface too if trace: path = frames_to_path(trace, unique=True) surf.path(path, aggdraw.Pen(P.response_feedback_color, 1, 255)) # Render to numpy array and return surf.flush() self.rendered = np.asarray(canvas) return self.rendered
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(self, im): if self.counter < self.startTime or self.counter > self.stopTime: return d = aggdraw.Draw(im) p = aggdraw.Pen("black", 2.5) color = int(255 - (255 * self.flipFlop.getCount()) / self.timeA) p = aggdraw.Pen((color, color, color), 2.5) if self.flipFlop.getState(): d.ellipse((self.pos_x - self.radius, self.pos_y - self.radius, self.pos_x + self.radius, self.pos_y + self.radius), p) d.flush()
def __call__(self, img): w, h = img.size r = self.radius d = r * 2 circle = Image.new('L', (d, d)) draw = aggdraw.Draw(circle) pen = aggdraw.Pen(255) brush = aggdraw.Brush(255) draw.ellipse((1, 1, d - 1, d - 1), pen, brush) draw.flush() # Cut it in to four pieces tl = circle.crop((0, 0, r, r)) # Top left tr = circle.crop((r, 0, d, r)) # Top right bl = circle.crop((0, r, r, d)) # Bottom left br = circle.crop((r, r, d, d)) # Bottom right # Create an alpha image with the four pieces at the corners alpha = Image.new('L', img.size, 255) alpha.paste(tl, (0, 0)) alpha.paste(tr, (w - r, 0)) alpha.paste(bl, (0, h - r)) alpha.paste(br, (w - r, h - r)) # Replace the alpha with our new image img = img.convert('RGBA') img.putalpha(alpha) if self.border is None: return img # Draw a border with curved corners draw = aggdraw.Draw(img) pen = aggdraw.Pen(self.border) # The +.5s are so that agg doesn't draw over pixel boundries draw.arc((0.5, 0.5, d - .5, d - .5), 90, 180, pen) draw.line((r, .5, w - r, .5), pen) draw.arc((w - d + .5, 0.5, w - .5, d - .5), 0, 90, pen) draw.line((w - .5, r, w - .5, h - r), pen) draw.arc((w - d + .5, h - d + .5, w - .5, h - .5), 270, 360, pen) draw.line((w - r, h - .5, r, h - .5), pen) draw.arc((0.5, h - d + .5, d - .5, h - .5), 180, 270, pen) draw.line((0.5, h - r, 0.5, r), pen) draw.flush() return img
def draw(self, frame, image): if frame < self.startTime or frame >= self.stopTime: return d = aggdraw.Draw(image) p = aggdraw.Pen("black", 2.5) idx = frame - self.startTime color = int(255 - (255 * idx) / self.duration) p = aggdraw.Pen((color, color, color), 2.5) d.ellipse((self.pos_x - self.radius, self.pos_y - self.radius, self.pos_x + self.radius, self.pos_y + self.radius), p) d.flush()
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 draw(self, im): if self.counter < self.startTime: return if self.stopTime != None and self.stopTime < self.counter: return d = aggdraw.Draw(im) p = aggdraw.Pen("black", 2.5) color = max(0, int(255 - (255 * (self.counter - self.startTime)) / 10)) p = aggdraw.Pen((int(color * 248 / 255.), int( color * 240 / 255.), int(color * 118 / 255.)), 2.5) d.ellipse((self.pos_x - self.radius, self.pos_y - self.radius, self.pos_x + self.radius, self.pos_y + self.radius), p) d.flush()
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 drawPoints(list_xy): print("drawPoints") print(list_xy) pen = aggdraw.Pen((0, 0, 0)) brush = aggdraw.Brush((0, 0, 0)) outline = aggdraw.Pen((0, 0, 0), 5) for xy_order in range(0, (len(list_xy))): p_x = list_xy[xy_order]["x"] p_y = list_xy[xy_order]["y"] draw.ellipse((p_x - 10, p_y - 10, p_x + 10, p_y + 10), brush) draw.flush() drawTime(list_xy) #im.show() im.save('draw\\result\\out.png')
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 _draw_connector(draw, start_node, end_node, color, width): pen = aggdraw.Pen(color, width) x1 = start_node.x2 y1 = start_node.y1 + (start_node.y2 - start_node.y1) / 2 x2 = end_node.x1 y2 = end_node.y1 + (end_node.y2 - end_node.y1) / 2 draw.line([x1, y1, x2, y2], pen)
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 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 Grid(self, deltas, pen=aggdraw.Pen('silver', 1.0)): """ Draw grid. Arguments: deltas -- distances between adjacent lines, pen -- pen. """ (min_x, min_y, max_x, max_y) = self.DrawArea (gx, gy) = deltas gx_cur = gx while gx_cur <= max_x: if gx_cur >= min_x: self.Line((gx_cur, min_y), (gx_cur, max_y), pen=pen) gx_cur = gx_cur + gx gx_cur = -gx while gx_cur >= min_x: if gx_cur <= max_x: self.Line((gx_cur, min_y), (gx_cur, max_y), pen=pen) gx_cur = gx_cur - gx gy_cur = gy while gy_cur <= max_y: if gy_cur >= min_y: self.Line((min_x, gy_cur), (max_x, gy_cur), pen=pen) gy_cur = gy_cur + gy gy_cur = -gy while gy_cur >= min_y: if gy_cur <= max_y: self.Line((min_x, gy_cur), (max_x, gy_cur), pen=pen) gy_cur = gy_cur - gy
def __init__(self, size, weight): self.size = size scale = math.sqrt(size[0] / 1920 * size[1] / 1080 * 5 / weight) self.hh = round(20 * scale) self.stick = 10 * scale self.bulbsize = 3 * self.stick self.knottobulb = self.stick + 2 / 3 * self.bulbsize self.lightspacing = 50 * scale bulbsrc_initheight = 4 * (2 * self.bulbsize) bulbsrc_new_size = (round(bulbsrc_initheight * gbulb_unlit.size[0] / gbulb_unlit.size[1]), round(bulbsrc_initheight)) self.bulb_unlit = gbulb_unlit.resize(bulbsrc_new_size) self.bulb_lightonly = gbulb_lightonly.resize(bulbsrc_new_size) self.bulb_scale = self.bulbsize / (self.bulb_unlit.size[1] / 2) self.slinger_core_pen = aggdraw.Pen(255, 4.0 * scale, linecap=2) self.blotsize = 100 * scale self.bigblot_side = round(4 * self.blotsize) self.blot_scale = self.blotsize / self.bigblot_side blotkernel = gkern2d(self.bigblot_side, 3) blotkernel = np.round(blotkernel * (255 / np.max(blotkernel))) blotdata = np.zeros((self.bigblot_side, self.bigblot_side), dtype=np.uint8) blotdata[:, :] = blotkernel self.bigblot = Image.fromarray(blotdata, 'L')
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_hierarchical_tree(ht, deltas=(10, 40), margins=(12, 12), pen=aggdraw.Pen('orange', 2.0), drawing_type=ClusteringDrawingType.Orthogonal, filename=None): """ Draw hierarchical tree. Arguments: ht -- hierarchical tree, deltas -- distances between nodes, margins -- margins, pen -- pen, drawing_type -- drawing type. """ # Create image. img = Image.new('RGB', TreeSizes(ht, deltas, margins), color=(255, 255, 255)) c = aggdraw.Draw(img) c.setantialias(True) # Recursive draw. draw_hierarchical_tree_on_img(ht, c, deltas, margins, pen, drawing_type) # Flush, save and show. c.flush() if filename != None: img.save(filename) img.show()
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 construct_cue(self): self.cue_seg_len = deg_to_px(1.7) self.cue_seg_thick = deg_to_px(0.4) canvas_size = [self.cue_seg_len, self.cue_seg_len] canvas = Image.new('RGBA', canvas_size, (0, 0, 0, 0)) surface = aggdraw.Draw(canvas) pen = aggdraw.Pen(WHITE, self.cue_seg_len) # Regardless of orientation, two segments remain the same xy = [(0, 0, 0, self.cue_seg_len), (0, 0, self.cue_seg_len, 0)] # Add missing segment, dependent on orientation if self.box_alignment == VERTICAL: xy.append((self.cue_seg_len, self.cue_seg_len, 0, self.cue_seg_len)) else: xy.append((self.cue_seg_len, 0, self.cue_seg_len, self.cue_seg_len)) for seg in xy: surface.line(seg, pen) surface.flush() return np.asarray(canvas)
def stitch(im, pixelation=12): im = im.convert('RGB') im = util.resize_jam_background(im) width, height = im.size # pixelate im = im.resize((int(math.ceil(width / float(pixelation))), int(math.ceil(height / float(pixelation))))) pix = im.load() # random bg colour colours = util.get_dominant_colours(im, 2) colours = map(tuple, colours) colours += [(0, 0, 0), (255, 255, 255)] bg_index = random.randint(0, len(colours) - 1) width, height = im.size new = Image.new('RGB', (width * pixelation, height * pixelation), colours[bg_index]) draw = aggdraw.Draw(new) width, height = new.size # draw stitches for y in xrange(0, height, pixelation): for x in xrange(0, width, pixelation): pen = aggdraw.Pen(pix[x / pixelation, y / pixelation], 2) draw.line((x, y, x + pixelation - 3, y + pixelation - 3), pen) draw.line((x + pixelation - 3, y, x, y + pixelation - 3), pen) draw.flush() return new
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 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 _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 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 create_noise_curve(image, number): w, h = image.size while number: x1 = random.randint(0, int(w / 5)) x2 = random.randint(int(w / 5), int(4 * w / 5)) x3 = random.randint(int(4 * w / 5), w) y1 = random.randint(0, int(2 * h / 5)) y2 = random.randint(int(2 * h / 5), h) y3 = random.randint(0, int(2 * h / 5)) points = [x1, y1, x2, y2, x3, y3] draw = aggdraw.Draw(image) # 2 is the outlinewidth in pixels color = random_color(10, 200, random.randint(220, 225)) outline = aggdraw.Pen(color, 2) # the pathstring: c for bezier curves (all lowercase letters for relative path) pathstring = "c" coord_len = len(points) for coord in points: if points.index(coord) == (coord_len - 1): pathstring += str(coord) else: pathstring += str(coord) + " " # xy position to place symbol xy = (x1, y1) symbol = aggdraw.Symbol(pathstring) draw.symbol(xy, symbol, outline) draw.flush() number -= 1 return image
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(self, color, linewidth=1): # if hasattr(self, 'linestyle'): # if self.linestyle == 'dash': # cr.set_dash([ 3.0, 4.0, 6.0, 4.0], 5.0) p = agg.Pen(self.get_color(color), width=linewidth) return p