def paintClock(player): clock_y = rect.height / 2. clock_x = clock_y + rect.width / 2. * player + 1 rec = rect.height / 2. - 3.5 context.arc(clock_x, clock_y, rec - 1, 0, 2 * pi) linear = cairo.LinearGradient(clock_x - rec * 2, clock_y - rec * 2, clock_x + rec * 2, clock_y + rec * 2) linear.add_color_stop_rgba(0, 1, 1, 1, 0.3) linear.add_color_stop_rgba(1, 0, 0, 0, 0.3) # context.set_source_rgba( 0, 0, 0, .3) context.set_source(linear) context.fill() linear = cairo.LinearGradient(clock_x - rec, clock_y - rec, clock_x + rec, clock_y + rec) linear.add_color_stop_rgba(0, 0, 0, 0, 0.5) linear.add_color_stop_rgba(1, 1, 1, 1, 0.5) context.arc(clock_x, clock_y, rec, 0, 2 * pi) context.set_source(linear) context.set_line_width(2.5) context.stroke() starttime = float(self.model.getInitialTime()) or 1 used = self.model.getPlayerTime(player) / starttime if used > 0: if used > 0: context.arc(clock_x, clock_y, rec - .8, -(used + 0.25) * 2 * pi, -0.5 * pi) context.line_to(clock_x, clock_y) context.close_path() elif used == 0: context.arc(clock_x, clock_y, rec - .8, -0.5 * pi, 1.5 * pi) context.line_to(clock_x, clock_y) radial = cairo.RadialGradient(clock_x, clock_y, 3, clock_x, clock_y, rec) if player == 0: # radial.add_color_stop_rgb(0, .73, .74, .71) radial.add_color_stop_rgb(0, .93, .93, .92) radial.add_color_stop_rgb(1, 1, 1, 1) else: # radial.add_color_stop_rgb(0, .53, .54, .52) radial.add_color_stop_rgb(0, .18, .20, .21) radial.add_color_stop_rgb(1, 0, 0, 0) context.set_source(radial) context.fill() x_loc = clock_x - cos((used - 0.25) * 2 * pi) * (rec - 1) y_loc = clock_y + sin((used - 0.25) * 2 * pi) * (rec - 1) context.move_to(clock_x, clock_y - rec + 1) context.line_to(clock_x, clock_y) context.line_to(x_loc, y_loc) context.set_line_width(0.2) if player == 0: context.set_source_rgb(0, 0, 0) else: context.set_source_rgb(1, 1, 1) context.stroke()
def __init__(self, *args, gradienttype='linear'): if gradienttype == 'linear': self._pattern = cairo.LinearGradient(*args) elif gradienttype == 'radial': self._pattern = cairo.RadialGradient(*args) else: raise NotImplementedError
def paint(self, cr): angle = 2 * math.pi / self.numHist for i, hbuf in zip(range(0, self.numHist), self._historyBuffers): self.paint_slice(cr, i * angle, (i + 1) * angle, hbuf, i == self._active) def_active = self._active is None radInner = self.RADIUS_INNER mask_grad = cairo.RadialGradient(self._x, self._y, radInner * 0.6, self._x, self._y, radInner * 0.9) mask_grad.add_color_stop_rgba(0, 1, 1, 1, 1) mask_grad.add_color_stop_rgba(1, 1, 1, 1, 0) cr.push_group() if def_active: cr.set_source_rgb(1, 1, 1) else: cr.set_source_rgb(0.9, 0.9, 0.9) cr.arc(self._x, self._y, self.RADIUS_INNER, 0, math.pi * 2) cr.fill() Gdk.cairo_set_source_pixbuf(cr, self._selBuffer, self._x - self.RADIUS_INNER, self._y - self.RADIUS_INNER) cr.mask(mask_grad) cr.pop_group_to_source() cr.paint_with_alpha(1 if def_active else 0.75)
def paint_slice(self, cr, angle_s, angle_e, prevImg, active): x = self._x y = self._y mid_angle = angle_s + (angle_e - angle_s) / 2 cx = x + math.cos(mid_angle) * (self.RADIUS_INNER + self.RADIUS_OUTER / 2) cy = y + math.sin(mid_angle) * (self.RADIUS_INNER + self.RADIUS_OUTER / 2) outerhalf = self.RADIUS_OUTER / 2 mask_grad = cairo.RadialGradient(cx, cy, outerhalf * 0.6, cx, cy, outerhalf * 0.9) mask_grad.add_color_stop_rgba(0, 1, 1, 1, 1) mask_grad.add_color_stop_rgba(1, 1, 1, 1, 0) cr.push_group() if active: cr.set_source_rgb(1, 1, 1) else: cr.set_source_rgb(0.9, 0.9, 0.9) cr.arc(x, y, self.RADIUS_INNER, angle_s, angle_e) cr.arc_negative(x, y, self.RADIUS_INNER + self.RADIUS_OUTER, angle_e, angle_s) cr.close_path() cr.fill_preserve() cr.clip() Gdk.cairo_set_source_pixbuf(cr, prevImg, cx - outerhalf, cy - outerhalf) cr.mask(mask_grad) cr.reset_clip() cr.pop_group_to_source() cr.paint_with_alpha(0.75 if not active else 1)
def radial_pattern(color: Color) -> cairo.RadialGradient: pattern = cairo.RadialGradient( 0.5, 0.5, 0.05, 0.5, 0.5, 0.25) r, g, b = color.r, color.g, color.b pattern.add_color_stop_rgba(0, r, g, b, 0.5) pattern.add_color_stop_rgba(1, r, g, b, 0) return pattern
def draw_gradient2(self, cr): r2 = cairo.RadialGradient(0, 0, 10, 0, 0, 40) r2.add_color_stop_rgb(0, 1, 1, 0) r2.add_color_stop_rgb(0.8, 0, 0, 0) cr.set_source(r2) cr.arc(0, 0, 40, 0, math.pi * 2) cr.fill()
class BlueSky(DrawThing): R = cairo.RadialGradient(0, 200, 0, 0, 200, 400) R.add_color_stop_rgb(0, 1, 1, 1) R.add_color_stop_rgb(1, *SKYBLUE) def draw(self, ctx, fr): ctx.set_source(BlueSky.R) ctx.paint()
def to_pattern(self, x: float, y: float, size: float, start_radius: float = 1.0): pat = cairo.RadialGradient(x, y, start_radius, x, y, size) for i, stop in enumerate(self.stops): pat.add_color_stop_rgba(i, stop.r, stop.g, stop.b, stop.a) return pat
def expose(self, widget, cr): context = self.get_style_context() self.activeColor = self._getColor(context, "success_color", "question_bg_color") self.activeColor.alpha *= 0.9 allocation = self.get_allocation() cr.set_antialias(cairo.ANTIALIAS_SUBPIXEL) middleX = allocation.width // 2 middleY = allocation.height // 2 pat = cairo.RadialGradient(middleX, middleY, 0, middleX, middleY, middleX) pat.add_color_stop_rgb(.2, .25, .25, .25) pat.add_color_stop_rgb(1, .15, .15, .15) cr.set_source(pat) cr.rectangle(0, 0, allocation.width, allocation.height) cr.fill() cr.set_line_width(1) cornerSize = 50 self._setCornerColor(cr, 0) cr.move_to(0, 0) cr.line_to(cornerSize, 0) cr.arc(0, 0, cornerSize, _0_DEG, _90_DEG) cr.fill() self._setCornerColor(cr, 1) cr.move_to(allocation.width, 0) cr.line_to(allocation.width, cornerSize) cr.arc(allocation.width, 0, cornerSize, _90_DEG, _180_DEG) cr.fill() self._setCornerColor(cr, 2) cr.move_to(0, allocation.height) cr.line_to(0, allocation.height - cornerSize) cr.arc(0, allocation.height, cornerSize, _270_DEG, _0_DEG) cr.fill() self._setCornerColor(cr, 3) cr.move_to(allocation.width, allocation.height) cr.line_to(allocation.width - cornerSize, allocation.height) cr.arc(allocation.width, allocation.height, cornerSize, _180_DEG, _270_DEG) cr.fill() cr.set_source_rgba(0, 0, 0, 1) cr.rectangle(0, 0, allocation.width, allocation.height) cr.stroke() return True
def draw_ceiling(color_main, color_dark, paths_l, paths_r, prev_paths_l, prev_paths_r): """Draw a ceiling linking the current and the previous arc.""" if prev_paths_l is None: return # ceiling lighting path = [path[0] for path in paths_l] path += [path[0] for path in paths_r[::-1]] path += [path[0] for path in prev_paths_r] path += [path[0] for path in prev_paths_l[::-1]] width = paths_l[0][0][0] - paths_r[0][0][0] # main gradient pattern = cairo.RadialGradient(paths_r[8][0][0] + width / 2, paths_r[8][0][1], width / 4.1, paths_r[6][0][0] + width / 2, paths_r[6][0][1], width / 1.6) pattern.add_color_stop_rgba(0, *color_dark) pattern.add_color_stop_rgba(0.6, *color_main) pattern.add_color_stop_rgba(1, *color_dark) ctx.set_source(pattern) draw_path(ctx, path) ctx.fill() # shadow gradient pattern = cairo.RadialGradient(paths_r[9][0][0] + width / 2, paths_r[9][0][1], width / 8, paths_r[9][0][0] + width / 2, paths_r[9][0][1], width / 4) pattern.add_color_stop_rgba(0, 0, 0, 0, 0.3) pattern.add_color_stop_rgba(1, 0, 0, 0, 0) ctx.set_source(pattern) draw_path(ctx, path) ctx.fill() # ceiling bricks for i, _ in enumerate(paths_l): ctx.move_to(*paths_r[i][0]) ctx.line_to(*prev_paths_r[i][0]) ctx.stroke() if i > 0: ctx.set_source_rgba(*opaque(lighten(color_main, -0.5), -0.7)) ctx.move_to(*paths_l[i - 1][0]) ctx.line_to(*prev_paths_l[i - 1][0]) ctx.stroke()
def update(self): if self.gradient is cairo.Gradient: del(self.gradient) if self.type == LINEAR: ###ToDo two type!!! self.gradient = cairo.LinearGradient(self.x, self.y, self.width, self.height) elif self.type == RADIAL: self.gradient = cairo.RadialGradient(self.x, self.y, self.width, self.height, 10, 100) else: raise BaseException for color in self.colors: self.gradient.add_color_stop_rgba(float(color.position), color.red, color.green, color.blue, color.alpha)
def draw_radial_gradient_rect(self, ctx): x0, y0 = 0.3, 0.3 x1, y1 = 0.5, 0.5 r0 = 0 r1 = 1 pattern = cairo.RadialGradient(x0, y0, r0, x1, y1, r1) pattern.add_color_stop_rgba(0, 1, 1, 0.5, 1) pattern.add_color_stop_rgba(1, 0.2, 0.4, 0.1, 1) ctx.rectangle(0, 0, 1, 1) ctx.set_source(pattern) ctx.fill()
def CreateRadialGradientBrush(self, xo, yo, xc, yc, radius, oColour, cColour): """ Creates a brush with a radial gradient originating at (xo,yo) with colour oColour and ends on a circle around (xc,yc) with radius r and colour cColour. """ oColour = _makeColour(oColour) cColour = _makeColour(cColour) pattern = cairo.RadialGradient(xo, yo, 0.0, xc, yc, radius) pattern.add_color_stop_rgba(0.0, *_colourToValues(oColour)) pattern.add_color_stop_rgba(1.0, *_colourToValues(cColour)) return GraphicsBrush.CreateFromPattern(pattern)
def do_draw(self, cr): # get actual widget size width = self.get_allocated_width() height = self.get_allocated_height() # calculate center and radius of the clock center = (width / 2, height / 2) radius = min(center) # setup gradients for clock background to get a smooth border bg_lg = cairo.RadialGradient( center[0], center[1], 0, center[0], center[1], radius) bg_lg.add_color_stop_rgba(0.0, 0, 0, 0, 1.0) bg_lg.add_color_stop_rgba(0.9, 0, 0, 0, 1.0) bg_lg.add_color_stop_rgba(1.0, 0, 0, 0, 0.0) # paint background cr.set_source(bg_lg) cr.arc(center[0], center[1], radius, 0, 2 * math.pi) cr.fill() local_time = time.localtime(self.last_draw_time) # draw ticks for every second for tick in range(0, 60): # fade out seconds in future and highlight past seconds if tick > local_time.tm_sec: cr.set_source_rgb(0.2, 0.3, 0.01) else: cr.set_source_rgb(0.764, 0.804, 0.176) # calculate tick position angle = tick * math.pi / 30 pos = (center[0] + math.sin(angle) * radius * 0.8, center[1] - math.cos(angle) * radius * 0.8) # draw tick cr.arc(pos[0], pos[1], radius / 40, 0, 2 * math.pi) cr.fill() # draw persistant ticks every five seconds cr.set_source_rgb(0.764, 0.804, 0.176) for tick in range(0, 12): # calculate tick position angle = tick * math.pi / 6 pos = (center[0] + math.sin(angle) * radius * 0.9, center[1] - math.cos(angle) * radius * 0.9) # draw tick cr.arc(pos[0], pos[1], radius / 40, 0, 2 * math.pi) cr.fill() # set a reasonable font size cr.set_font_size(cr.user_to_device_distance(0, height / 5)[1]) # format time into a string text = time.strftime("%H:%M") # get text drawing extents (xbearing, ybearing, textwidth, textheight, xadvance, yadvance) = cr.text_extents(text) # draw time cr.move_to(center[0] - textwidth / 2, center[1] + textheight / 2) cr.show_text(text)
def _do_draw_shadow(self, context, rect): if not self._shadow: return center = rect.width / 2, rect.height / 2 radius = int(0.4 * min(rect.width, rect.height)) gradient = cairo.RadialGradient(center[0], center[1], radius, center[0], center[1], radius + 10) gradient.add_color_stop_rgba(0, 0, 0, 0, 0.5) gradient.add_color_stop_rgba(0.5, 0, 0, 0, 0) context.set_source(gradient) context.arc(center[0], center[1], radius + 10, 0, 2 * math.pi) context.fill()
def init_tex(square_size): # White stones Stone.white_tex = LW.CairoTexture.new(square_size, square_size) cr = Stone.white_tex.cairo_create() pattern = cairo.RadialGradient(square_size / 3, square_size / 3, square_size / 8, square_size / 3, square_size / 3, square_size) pattern.add_color_stop_rgba(0, 0.9, 0.9, 0.9, 1) pattern.add_color_stop_rgba(1, 0.6, 0.6, 0.6, 1) cr.set_source(pattern) cr.arc(square_size / 2, square_size / 2, square_size / 2 - 2, 0, 2 * math.pi) cr.fill() cr.set_source_rgba(0.6, 0.6, 0.6, 1) cr.arc(square_size / 2, square_size / 2, square_size / 2 - 2, 0, 2 * math.pi) cr.stroke() Stone.white_tex.update() Stone.white_tex.enable() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) Stone.white_tex.disable() # Black stones Stone.black_tex = LW.CairoTexture.new(square_size, square_size) cr = Stone.black_tex.cairo_create() pattern = cairo.RadialGradient(square_size / 3, square_size / 3, square_size / 8, square_size / 3, square_size / 3, square_size) pattern.add_color_stop_rgba(0, 0.3, 0.3, 0.3, 1) pattern.add_color_stop_rgba(1, 0, 0, 0, 1) cr.set_source(pattern) cr.arc(square_size / 2, square_size / 2, square_size / 2 - 2, 0, 2 * math.pi) cr.fill() cr.set_source_rgba(0.1, 0.1, 0.1, 1) cr.arc(square_size / 2, square_size / 2, square_size / 2 - 2, 0, 2 * math.pi) cr.stroke() Stone.black_tex.update() Stone.black_tex.enable() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) Stone.black_tex.disable()
def draw_quadrant_shadow(self, ctx, x, y, from_r, to_r, quad, col): gradient = cairo.RadialGradient(x, y, from_r, x, y, to_r) gradient.add_color_stop_rgba(0, col[0], col[1], col[2], col[3]) gradient.add_color_stop_rgba(1, col[0], col[1], col[2], 0) ctx.set_source(gradient) ctx.new_sub_path() if quad == 0: ctx.arc(x, y, to_r, -math.pi, -math.pi / 2) elif quad == 1: ctx.arc(x, y, to_r, -math.pi / 2, 0) elif quad == 2: ctx.arc(x, y, to_r, math.pi / 2, math.pi) elif quad == 3: ctx.arc(x, y, to_r, 0, math.pi / 2) ctx.line_to(x, y) ctx.close_path() ctx.fill()
def draw_overlay_cb(self, overlay, duration, user_data): # for iter in detected.begin(), detected.end(): # print() self.linear = cairo.LinearGradient(0, 0, 1, 1) self.linear.add_color_stop_rgb(0, 0, 0.3, 0.8) self.linear.add_color_stop_rgb(1, 0, 0.8, 0.3) self.radial = cairo.RadialGradient(0.5, 0.5, 0.25, 0.5, 0.5, 0.75) self.radial.add_color_stop_rgba(0, 0, 0, 0, 1) self.radial.add_color_stop_rgba(0.5, 0, 0, 0, 0) cairo.Context.set_source(self.linear) print()
def draw_lamp(x, y, width, height, color_main, color_dark): """Draw a lamp from the ceiling.""" if color_main is None: return wireframe_color = saturate(lighten(color_dark, -0.5), -0.3) glass_color = opaque(lighten(color_main, 0), -0.7) light_color = lighten(color_main, 0.5) # light yl = y + height * 3 / 4 r = width * 0.8 pattern = cairo.RadialGradient(x, yl, 0, x, yl, r) pattern.add_color_stop_rgba(0, *lighten(light_color, 1)) pattern.add_color_stop_rgba(0.2, *light_color) pattern.add_color_stop_rgba(1, *opaque(light_color, -1)) ctx.set_source(pattern) ctx.rectangle(x - r, yl - r, r * 2, r * 2) ctx.fill() # mount ctx.set_source(cairo.SolidPattern(*wireframe_color)) draw_path(ctx, ( (x - width / 8, y), (x + width / 8, y), (x, y - r), )) ctx.fill() ctx.rectangle(x - width / 16, y, width / 8, height / 2) ctx.fill() # top r = abs(width / 2) ctx.arc(x, y + height / 2 + r, r, math.pi, 0) ctx.fill() # body pattern = cairo.LinearGradient(x - r, y, x + r, y) pattern.add_color_stop_rgba(0.03, *wireframe_color) pattern.add_color_stop_rgba(0.125, *glass_color) pattern.add_color_stop_rgba(0.27, *wireframe_color) pattern.add_color_stop_rgba(0.5, *glass_color) pattern.add_color_stop_rgba(0.73, *wireframe_color) pattern.add_color_stop_rgba(0.855, *glass_color) pattern.add_color_stop_rgba(0.97, *wireframe_color) ctx.set_source(pattern) ctx.rectangle(x - r, y + height / 2 + r, r * 2, height / 2 - r * 2) ctx.fill() # bottom ctx.set_source(cairo.SolidPattern(*wireframe_color)) draw_path(ctx, ( (x - r, y + height - r), (x + r, y + height - r), (x, y + height + r * 0.4), )) ctx.fill()
def draw_background(self, ctx): """ Draw the background """ ctx.save() ctx.rotate(math.radians(self.rotate_value)) delta = (self.rootangle_rad_asc[0] - self.rootangle_rad_desc[1]) / 2.0 % math.pi ctx.move_to(0, 0) radius_gradient_asc = 1.5 * self.maxradius_asc(self.generations_asc) gradient_asc = cairo.RadialGradient(0, 0, self.CENTER, 0, 0, radius_gradient_asc) color = hex_to_rgb(self.grad_end) gradient_asc.add_color_stop_rgba(0.0, color[0] / 255, color[1] / 255, color[2] / 255, 0.5) gradient_asc.add_color_stop_rgba(1.0, 1, 1, 1, 0.0) start_rad, stop_rad = (self.rootangle_rad_asc[0] - delta, self.rootangle_rad_asc[1] + delta) ctx.set_source(gradient_asc) ctx.arc(0, 0, radius_gradient_asc, start_rad, stop_rad) ctx.fill() ctx.move_to(0, 0) radius_gradient_desc = 1.5 * self.maxradius_desc(self.generations_desc) gradient_desc = cairo.RadialGradient(0, 0, self.CENTER, 0, 0, radius_gradient_desc) color = hex_to_rgb(self.grad_start) gradient_desc.add_color_stop_rgba(0.0, color[0] / 255, color[1] / 255, color[2] / 255, 0.5) gradient_desc.add_color_stop_rgba(1.0, 1, 1, 1, 0.0) start_rad, stop_rad = (self.rootangle_rad_desc[0] - delta, self.rootangle_rad_desc[1] + delta) ctx.set_source(gradient_desc) ctx.arc(0, 0, radius_gradient_desc, start_rad, stop_rad) ctx.fill() ctx.restore()
def _draw_dot(self, ctx, start_pos, end_pos, curve_offset): self._update_phase() t, _ = math.modf(self.phase) # t is in [0..1] cur_pos = curve_position(t, *start_pos, start_pos.x + curve_offset, start_pos.y, end_pos.x - curve_offset, end_pos.y, *end_pos) pattern = cairo.RadialGradient(*cur_pos, 0, *cur_pos, self.DOT_RADIUS) pattern.add_color_stop_rgba(0, *self.DOT_COLOR, 1) pattern.add_color_stop_rgba(1, *self.DOT_COLOR, 0) ctx.set_source(pattern) ctx.arc(*cur_pos, self.DOT_RADIUS, 0, 2 * math.pi) ctx.fill()
def draw_gradient(surface, node, name): """Gradients colors.""" gradient_node = surface.gradients[name] transform(surface, gradient_node.get("gradientTransform")) if gradient_node.get("gradientUnits") == "userSpaceOnUse": width_ref, height_ref = "x", "y" diagonal_ref = "xy" else: x = float(size(surface, node.get("x"), "x")) y = float(size(surface, node.get("y"), "y")) width = float(size(surface, node.get("width"), "x")) height = float(size(surface, node.get("height"), "y")) width_ref = height_ref = diagonal_ref = 1 if gradient_node.tag == "linearGradient": x1 = float(size(surface, gradient_node.get("x1", "0%"), width_ref)) x2 = float(size(surface, gradient_node.get("x2", "100%"), width_ref)) y1 = float(size(surface, gradient_node.get("y1", "0%"), height_ref)) y2 = float(size(surface, gradient_node.get("y2", "0%"), height_ref)) gradient_pattern = cairo.LinearGradient(x1, y1, x2, y2) elif gradient_node.tag == "radialGradient": r = float(size(surface, gradient_node.get("r", "50%"), diagonal_ref)) cx = float(size(surface, gradient_node.get("cx", "50%"), width_ref)) cy = float(size(surface, gradient_node.get("cy", "50%"), height_ref)) fx = float(size(surface, gradient_node.get("fx", str(cx)), width_ref)) fy = float(size(surface, gradient_node.get("fy", str(cy)), height_ref)) gradient_pattern = cairo.RadialGradient(fx, fy, 0, cx, cy, r) if gradient_node.get("gradientUnits") != "userSpaceOnUse": gradient_pattern.set_matrix( cairo.Matrix(1 / width, 0, 0, 1 / height, -x / width, -y / height)) gradient_pattern.set_extend( getattr(cairo, "EXTEND_%s" % node.get("spreadMethod", "pad").upper())) offset = 0 for child in gradient_node.children: offset = max(offset, size(surface, child.get("offset"), 1)) stop_color = color(child.get("stop-color", "black"), float(child.get("stop-opacity", 1))) gradient_pattern.add_color_stop_rgba(offset, *stop_color) gradient_pattern.set_extend( getattr(cairo, "EXTEND_%s" % gradient_node.get("spreadMethod", "pad").upper())) surface.context.set_source(gradient_pattern)
def expose(self, widget, event): cr = widget.window.cairo_create() sensitive = self.flags() & gtk.PARENT_SENSITIVE if not sensitive: alpha = .3 else: alpha = 1 cr.set_line_width(3) cr.set_source_rgba(0, 0, 0, alpha) if self.is_on: if self._blink_active == False or self._blink_active == True and self._blink_state == True: color = self._on_color else: color = self._off_color else: color = self._off_color # square led if self.led_shape == 2: self.set_size_request(self._dia * 2 + 5, self._dia * 2 + 5) w = self.allocation.width h = self.allocation.height cr.translate(w / 2, h / 2) cr.rectangle(-self._dia, -self._dia, self._dia * 2, self._dia * 2) # oval led elif self.led_shape == 1: self.set_size_request(self._dia * 2 + 5, self._dia * 2) w = self.allocation.width h = self.allocation.height cr.translate(w / 2, h / 2) cr.scale(1, 0.7) cr.arc(0, 0, self._dia, 0, 2 * math.pi) # round led else: self.set_size_request(self._dia * 2 + 5, self._dia * 2 + 5) w = self.allocation.width h = self.allocation.height cr.translate(w / 2, h / 2) lg2 = cairo.RadialGradient(0, 0, self._dia - 2, 0, 0, self._dia + 1) lg2.add_color_stop_rgba(0.0, 0., 0., 0., 0.) lg2.add_color_stop_rgba(.99, 0., 0., 0., 1.) lg2.add_color_stop_rgba(1.0, 0., 0., 0., 0.) cr.arc(0, 0, self._dia, 0, 2 * math.pi) cr.mask(lg2) cr.stroke_preserve() cr.set_source_rgba(color.red / 65535., color.green / 65535., color.blue / 65535., alpha) cr.fill() return False
def draw(cr, width, height): cr.scale(width, height) cr.set_line_width(0.04) pattern = cairo.LinearGradient(0, 0, 1, 1) pattern.add_color_stop_rgb(0, 0, 0.3, 0.8) pattern.add_color_stop_rgb(1, 0, 0.8, 0.3) mask = cairo.RadialGradient(0.5, 0.5, 0.25, 0.5, 0.5, 0.5) mask.add_color_stop_rgba(0, 0, 0, 0, 1) mask.add_color_stop_rgba(0.5, 0, 0, 0, 0) cr.set_source(pattern) cr.mask(mask)
def GenCircle(y,x): data = np.zeros((64, 64, 4), dtype=np.uint8) surface = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_ARGB32, 64, 64) cr = cairo.Context(surface) cr.set_source_rgb(0.8, 0.8, 0.8) cr.paint() r2 = cairo.RadialGradient(x, y, 0, x, y, 10) r2.add_color_stop_rgb(0, 0, 0, 0) r2.add_color_stop_rgb(0.8, 1, 1, 1) cr.set_source(r2) cr.arc(x, y, 6, 0, math.pi * 2) cr.fill() return data[:,:,0]
def draw_segment(self, ctx): r1, g1, b1, a1 = self.color1 r2, g2, b2, a2 = self.color2 r3, g3, b3, a3 = self.color3 pat = cairo.RadialGradient(16, 16, 16, 8, 8, 4) pat.add_color_stop_rgba(1, r3, g3, b3, a3) pat.add_color_stop_rgba(0.9, r2, g2, b2, a2) pat.add_color_stop_rgba(0, r1, g1, b1, a1) ctx.arc(16, 16, 12, 0, PI * 2) ctx.close_path() ctx.set_source(pat) ctx.fill()
def draw_shadow(self, ctx): self._update_phase() ctx.save() ctx.translate(self.x + self.orig_width * 0.5, self.y) ctx.scale(1, 0.2) p = cairo.RadialGradient(0, 0, 0, 0, 0, self.orig_width * 0.5) p.add_color_stop_rgba(0, 0, 0, 0, 0.6) p.add_color_stop_rgba(0.5, 0, 0, 0, 0.6) p.add_color_stop_rgba(1, 0, 0, 0, 0) ctx.set_source(p) ctx.rectangle(-0.6 * self.orig_width, -0.6 * self.orig_height, 1.2 * self.orig_width, 1.2 * self.height) ctx.fill() ctx.restore()
def update_gradient(self, widget=None, allocation=None): self.gradient_size = int(self.view.overlay.get_allocated_height() * 2.5) self.gradient_surface = cairo.ImageSurface(cairo.Format.ARGB32, self.gradient_size, self.gradient_size) gradient_context = cairo.Context(self.gradient_surface) pattern = cairo.RadialGradient(self.gradient_size / 2, self.gradient_size / 2, 0, self.gradient_size / 2, self.gradient_size / 2, self.gradient_size / 2) pattern.add_color_stop_rgba(0, self.bg_color.red, self.bg_color.green, self.bg_color.blue, self.bg_color.alpha * 0.9) pattern.add_color_stop_rgba(1, self.bg_color.red, self.bg_color.green, self.bg_color.blue, 0) gradient_context.set_source(pattern) gradient_context.move_to(0, 0) gradient_context.line_to(self.gradient_size, 0) gradient_context.line_to(self.gradient_size, self.gradient_size) gradient_context.line_to(0, self.gradient_size) gradient_context.close_path() gradient_context.fill()
def draw_gradient1(self, cr): cr.set_source_rgba(0, 0, 0, 1) cr.set_line_width(12) cr.translate(60, 60) r1 = cairo.RadialGradient(30, 30, 10, 30, 30, 90) r1.add_color_stop_rgba(0, 1, 1, 1, 1) r1.add_color_stop_rgba(1, 0.6, 0.6, 0.6, 1) cr.set_source(r1) cr.arc(0, 0, 40, 0, math.pi * 2) cr.fill() cr.translate(120, 0)
def paint_background(self, c): StylizedFrame.paint_background(self, c) a = self.get_allocation() pattern = self.render_dots() pattern.set_extend(cairo.EXTEND_REPEAT) c.set_source(pattern) c.fill_preserve() g = cairo.RadialGradient(a.width / 2, a.height / 2, 0, a.width / 2, a.height / 2, a.width > a.height and a.width or a.height) g.add_color_stop_rgba(0.00, 1, 1, 1, 1.00) g.add_color_stop_rgba(0.25, 1, 1, 1, 0.75) g.add_color_stop_rgba(0.40, 1, 1, 1, 0.00) c.set_source(g) c.fill_preserve()