Skip to content

Instantly share code, notes, and snippets.

@Moelf
Created July 2, 2022 21:06
Show Gist options
  • Save Moelf/e380d20b307901a6947881dc163a6c62 to your computer and use it in GitHub Desktop.
Save Moelf/e380d20b307901a6947881dc163a6c62 to your computer and use it in GitHub Desktop.
## header to provide surface and context
using Cairo, LinearAlgebra
c = CairoRGBSurface(256,256);
cr = CairoContext(c);
rectangle(cr,0.0,0.0,256.0,256.0); # background
save(cr);
set_source_rgb(cr,0.8,0.8,0.8); # light gray
fill(cr);
restore(cr);
## original example, following here
b = Cairo.Colors.ARGB32(Cairo.Colors.colorant"black")
w = Cairo.Colors.ARGB32(Cairo.Colors.colorant"white")
N = 10
image = fill(w, N, N)
for i = 1:N
image[N+1-i, i] = b
end
image = CairoImageSurface(image)
w = N
h = N
pattern = CairoPattern(image);
pattern_set_extend(pattern, Cairo.EXTEND_REPEAT);
arc(cr, 128.0, 128.0, 76.8, 0, 2*pi);
clip(cr);
rectangle(cr, 0, 0, 256.0, 256.0);
set_source(cr, pattern);
fill(cr);
set_source_surface(cr, image, 0, 0);
paint(cr);
write_to_png(c,"sample_clip_image.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment