Python cairo.LINE_CAP_ROUND Examples
The following are 16
code examples of cairo.LINE_CAP_ROUND().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cairo
, or try the search function
.
Example #1
Source File: drawing.py From xy with MIT License | 7 votes |
def render(self, scale=96/25.4, margin=10, line_width=0.5): import cairo x1, y1, x2, y2 = self.bounds width = int(scale * self.width + margin * 2) height = int(scale * self.height + margin * 2) surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height) dc = cairo.Context(surface) dc.set_line_cap(cairo.LINE_CAP_ROUND) dc.translate(margin, height - margin) dc.scale(scale, -scale) dc.translate(-x1, -y1) dc.set_line_width(line_width) dc.set_source_rgb(1, 1, 1) dc.paint() # dc.arc(0, 0, 3.0 / scale, 0, 2 * math.pi) # dc.set_source_rgb(1, 0, 0) # dc.fill() dc.set_source_rgb(0, 0, 0) for path in self.paths: dc.move_to(*path[0]) for x, y in path: dc.line_to(x, y) dc.stroke() return surface
Example #2
Source File: un_deux_trois.py From generative-art with MIT License | 6 votes |
def lines(ctx, colors, x, y, width, height, num_steps, line_width): ctx.save() ctx.translate(x + width / 2, y + height / 2) ctx.rotate(random.uniform(- math.pi / 2, math.pi / 2)) ctx.translate(-width/2, -height/2) step_size = max(width, height) // num_steps current_x = 0 while current_x < width: ctx.move_to(current_x, 0) ctx.line_to(current_x, height) ctx.set_source_rgb(*palettes.hex_to_tuple(random.choice(colors))) ctx.set_line_width(line_width) ctx.set_line_cap(cairo.LINE_CAP_ROUND) ctx.stroke() current_x += step_size ctx.restore()
Example #3
Source File: thick_diagonals.py From generative-art with MIT License | 6 votes |
def diagonal(ctx, color, line_width): if random.random() < 0.5: start_x = -line_width start_y = random.randint(IMG_HEIGHT // 3, IMG_HEIGHT - line_width) ctx.move_to(start_x, start_y) else: start_x = random.randint(-line_width, IMG_WIDTH // 3) start_y = IMG_HEIGHT + line_width ctx.move_to(start_x, start_y) end_x = random.randint(start_x + 2 * line_width, IMG_WIDTH) end_y = random.randint(0, start_y - 2*line_width) ctx.line_to(end_x, end_y) ctx.set_source(gradient(color, start_x, start_y, end_x, end_y)) ctx.set_line_width(line_width) ctx.set_line_cap(cairo.LINE_CAP_ROUND) ctx.stroke()
Example #4
Source File: scribble.py From pympress with GNU General Public License v2.0 | 6 votes |
def draw_scribble(self, widget, cairo_context): """ Perform the drawings by user. Args: widget (:class:`~Gtk.DrawingArea`): The widget where to draw the scribbles. cairo_context (:class:`~cairo.Context`): The canvas on which to render the drawings """ ww, wh = widget.get_allocated_width(), widget.get_allocated_height() cairo_context.set_line_cap(cairo.LINE_CAP_ROUND) for color, width, points in self.scribble_list: points = [(p[0] * ww, p[1] * wh) for p in points] cairo_context.set_source_rgba(*color) cairo_context.set_line_width(width) cairo_context.move_to(*points[0]) for p in points[1:]: cairo_context.line_to(*p) cairo_context.stroke()
Example #5
Source File: editor.py From runsqlrun with MIT License | 6 votes |
def do_draw(self, cr, background_area, cell_area, start, end, state): in_statement, is_current = self._in_statement(start) if not in_statement: return style = self.buffer.get_style_scheme() ref_style = style.get_style('line-numbers') if ref_style is not None: ok, col_default = Gdk.Color.parse( ref_style.get_property('foreground')) else: ok, col_default = Gdk.Color.parse('#1565C0') ok, col_highlight = Gdk.Color.parse('#1565C0') cr.move_to(cell_area.x, cell_area.y) cr.line_to(cell_area.x, cell_area.y + cell_area.height) cr.set_line_width(10) cr.set_line_cap(cairo.LINE_CAP_ROUND) if is_current: cr.set_source_rgb(*col_highlight.to_floats()) else: cr.set_source_rgb(*col_default.to_floats()) cr.stroke()
Example #6
Source File: tile.py From Tiling with MIT License | 6 votes |
def render( self, dual=False, background_color=BACKGROUND_COLOR, margin=MARGIN, show_labels=SHOW_LABELS, line_width=LINE_WIDTH): surface = cairo.ImageSurface( cairo.FORMAT_RGB24, self.width, self.height) dc = cairo.Context(surface) dc.set_line_cap(cairo.LINE_CAP_ROUND) dc.set_line_join(cairo.LINE_JOIN_ROUND) dc.set_line_width(line_width) dc.set_font_size(18.0 / self.scale) dc.translate(self.width / 2, self.height / 2) dc.scale(self.scale, self.scale) dc.set_source_rgb(*color(background_color)) dc.paint() shapes = self.dual() if dual else self.lookup.values() if show_labels: for shape in shapes: shape.render_edge_labels(dc, margin - 0.25) for shape in shapes: shape.render(dc, margin) if show_labels: for index, shape in enumerate(self.shapes): if shape in shapes: shape.render_label(dc, index) return surface
Example #7
Source File: cairo_backend.py From symbolator with MIT License | 5 votes |
def cairo_line_cap(line_cap): if line_cap == 'round': return cairo.LINE_CAP_ROUND elif line_cap == 'square': return cairo.LINE_CAP_SQUARE else: return cairo.LINE_CAP_BUTT
Example #8
Source File: schlib-render.py From kicad-schlib with Creative Commons Zero v1.0 Universal | 5 votes |
def render_cairo(self, ctx, origx, origy): ctx.set_line_width(max(self.thickness, MIN_WIDTH)) ctx.set_line_cap(cairo.LINE_CAP_ROUND) p = self.points[0] ctx.move_to (origx + p[0], origy - p[1]) for p in self.points[1:]: ctx.line_to (origx + p[0], origy - p[1]) if self.fill == "f": ctx.close_path() ctx.set_source_rgb(*COLOR_FG) ctx.stroke_preserve() ctx.set_source_rgb(*COLOR_BG) ctx.fill() elif self.fill == "F": ctx.close_path() ctx.set_source_rgb(*COLOR_FG) ctx.stroke_preserve() ctx.set_source_rgb(*COLOR_FG) ctx.fill() else: ctx.set_source_rgb(*COLOR_FG) ctx.stroke() minx = min(i[0] for i in self.points) + origx maxx = max(i[0] for i in self.points) + origx miny = min(-i[1] for i in self.points) + origy maxy = max(-i[1] for i in self.points) + origy return BoundingBox(minx, maxx, miny, maxy)
Example #9
Source File: schlib-render.py From kicad-schlib with Creative Commons Zero v1.0 Universal | 5 votes |
def render_cairo(self, ctx, origx, origy): ctx.set_line_width(max(self.thickness, MIN_WIDTH)) ctx.set_line_cap(cairo.LINE_CAP_ROUND) sx = self.startx + origx sy = -self.starty + origy ex = self.endx + origx ey = -self.endy + origy ctx.move_to(sx, sy) ctx.line_to(sx, ey) ctx.line_to(ex, ey) ctx.line_to(ex, sy) ctx.close_path() if self.fill == "f": ctx.set_source_rgb(*COLOR_FG) ctx.stroke_preserve() ctx.set_source_rgb(*COLOR_BG) ctx.fill() elif self.fill == "F": ctx.set_source_rgb(*COLOR_FG) ctx.stroke_preserve() ctx.set_source_rgb(*COLOR_FG) ctx.fill() else: ctx.set_source_rgb(*COLOR_FG) ctx.stroke() minx = min(self.startx, self.endx) + origx maxx = max(self.startx, self.endx) + origx miny = min(-self.starty, -self.endy) + origy maxy = max(-self.starty, -self.endy) + origy return BoundingBox(minx, maxx, miny, maxy)
Example #10
Source File: main.py From pywonderland with MIT License | 5 votes |
def main(hexagon_size, imgsize): surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, imgsize, imgsize) ctx = cairo.Context(surface) # we will put the center of the hexagon at the origin a, b, c = hexagon_size ctx.translate(imgsize / 2.0, imgsize / 2.0) extent = max(c, a * HALFSQRT3, b * HALFSQRT3) + 1 ctx.scale(imgsize / (extent * 2.0), -imgsize / (extent * 2.0)) ctx.translate(-b * HALFSQRT3, -c / 2.0) # paint background ctx.set_source_rgb(1, 1, 1) ctx.paint() ctx.set_line_cap(cairo.LINE_CAP_ROUND) ctx.set_line_join(cairo.LINE_JOIN_ROUND) T = LozengeTiling(hexagon_size) sample = run_cftp(T) for key, val in T.get_tiles(sample).items(): for verts in val: A, B, C, D = square_to_hex(verts) ctx.move_to(A[0], A[1]) ctx.line_to(B[0], B[1]) ctx.line_to(C[0], C[1]) ctx.line_to(D[0], D[1]) ctx.close_path() if key == "T": ctx.set_source_rgb(*TOP_COLOR) elif key == "L": ctx.set_source_rgb(*LEFT_COLOR) else: ctx.set_source_rgb(*RIGHT_COLOR) ctx.fill_preserve() ctx.set_line_width(LINE_WIDTH) ctx.set_source_rgb(*EDGE_COLOR) ctx.stroke() surface.write_to_png("random_lozenge_tiling.png")
Example #11
Source File: fractaltree.py From pywonderland with MIT License | 5 votes |
def main(): surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT) ctx = cairo.Context(surface) ctx.set_line_cap(cairo.LINE_CAP_ROUND) ctx.set_line_join(cairo.LINE_JOIN_ROUND) ctx.set_source_rgb(1, 1, 1) ctx.paint() fractal_tree(ctx, ITERATIONS, ROOT, TRUNK_LEN, RATIO, THETA, ANGLE, PERTURB) surface.write_to_png("random_fractal_tree.png")
Example #12
Source File: just_shapes.py From generative-art with MIT License | 5 votes |
def line(ctx, color, line_width): x1 = random.randint(0, IMG_WIDTH) y1 = random.randint(0, IMG_HEIGHT) x2 = random.randint(0, IMG_WIDTH) y2 = random.randint(0, IMG_HEIGHT) ctx.move_to(x1, y1) ctx.line_to(x2, y2) # Make lines more transparent, they tend to overtake things because they're long. alpha = random.uniform(0.09, 0.4) ctx.set_source_rgba(*color, alpha) ctx.set_line_width(line_width) ctx.set_line_cap(cairo.LINE_CAP_ROUND) ctx.stroke()
Example #13
Source File: esses.py From generative-art with MIT License | 5 votes |
def make_curve(ctx, points, color, line_width): ctx.move_to(*points[0]) ctx.curve_to(*points[1], *points[2], *points[3]) ctx.set_line_width(line_width) ctx.set_line_cap(cairo.LINE_CAP_ROUND) ctx.set_source_rgb(*color) ctx.stroke()
Example #14
Source File: line.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def draw(self, context): if self.parent and self.parent.moving: return def draw_line_end(pos, angle, port, draw): cr.save() cr.translate(*pos) cr.rotate(angle) draw(context, port) cr.restore() self.line_width = self._calc_line_width() cr = context.cairo cr.set_line_cap(LINE_CAP_ROUND) cr.set_line_width(self.line_width) # Draw connection tail (line perpendicular to from_port) start_segment_index = 0 if self.from_port: draw_line_end(self._handles[0].pos, self._head_angle, self.from_port, self.draw_tail) start_segment_index = 1 # Draw connection head (line perpendicular to to_port) end_segment_index = len(self._handles) if self.to_port: draw_line_end(self._handles[-1].pos, self._tail_angle, self.to_port, self.draw_head) end_segment_index -= 1 # Draw connection line from waypoint to waypoint cr.move_to(*self._handles[start_segment_index].pos) for h in self._handles[start_segment_index+1:end_segment_index]: cr.line_to(*h.pos) cr.set_source_rgba(*self._line_color) cr.stroke() if self.name and (isinstance(self.from_port, LogicPortView) or global_gui_config.get_config_value("SHOW_NAMES_ON_DATA_FLOWS", default=True)): self._draw_name(context)
Example #15
Source File: ChainVBox.py From pychess with GNU General Public License v3.0 | 5 votes |
def draw(self, context): allocation = self.get_allocation() x_loc = allocation.x y_loc = allocation.y width = allocation.width - 1 height = allocation.height context.set_source_rgb(.2, .2, .2) # context.rectangle(0, 0, width, height) # context.fill() context.move_to( self.__toAHalf(x_loc + width / 2.) - LONG_LINE, self.__toAHalf(y_loc + height / 2.)) context.line_to( self.__toAHalf(x_loc + width / 2.), self.__toAHalf(y_loc + height / 2.)) if self.position == CHAIN_TOP: context.line_to( self.__toAHalf(x_loc + width / 2.), self.__toAHalf(float(y_loc + height))) else: context.line_to( self.__toAHalf(x_loc + width / 2.), self.__toAHalf(y_loc + 0.)) context.set_line_width(1.0) context.set_line_cap(cairo.LINE_CAP_ROUND) context.set_line_join(cairo.LINE_JOIN_ROUND) context.stroke()
Example #16
Source File: draw_mod.py From agg-kicad with MIT License | 5 votes |
def draw_line(ctxs, draw): layer = [n for n in draw if n[0] == "layer"][0][1] if layer in ctxs: ctx = ctxs[layer] rgba = colours[layer] width = [n for n in draw if n[0] == "width"][0][1] ctx.set_source_rgba(*rgba) ctx.set_line_width(float(width)) ctx.set_line_cap(cairo.LINE_CAP_ROUND) if draw[0] == "fp_line": start = [n for n in draw if n[0] == "start"][0] end = [n for n in draw if n[0] == "end"][0] ctx.move_to(float(start[1]), float(start[2])) ctx.line_to(float(end[1]), float(end[2])) elif draw[0] == "fp_circle": center = [n for n in draw if n[0] == "center"][0] end = [n for n in draw if n[0] == "end"][0] dx = float(end[1]) - float(center[1]) dy = float(end[2]) - float(center[2]) r = math.sqrt(dx**2 + dy**2) ctx.new_sub_path() ctx.arc(float(center[1]), float(center[2]), r, 0, 2*math.pi) elif draw[0] == "fp_arc": start = [n for n in draw if n[0] == "start"][0] end = [n for n in draw if n[0] == "end"][0] angle = [n for n in draw if n[0] == "angle"][0] dx = float(end[1]) - float(start[1]) dy = float(end[2]) - float(start[2]) r = math.sqrt(dx**2 + dy**2) a_start = math.atan2(dy, dx) a_end = a_start + float(angle[1]) * (math.pi / 180.0) ctx.new_sub_path() ctx.arc(float(start[1]), float(start[2]), r, a_start, a_end) ctx.stroke()