Skip to content

Does drawsvg provide utilities for boolean operations? #116

Answered by cduck
Argmaster asked this question in Q&A
Discussion options

You must be logged in to vote

This is possible with SVG masks:

import drawsvg as draw

d = draw.Drawing(200, 200)

# Example based on https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/mask#example
# A mask is a black-and-white image and the black parts specify where to cut
# holes in the target image
hole_mask = draw.Mask()
# First make everything white, adjust coordinates to match your drawing
hole_mask.append(draw.Rectangle(0, 0, 200, 200, fill='white'))
# Add black shape(s) to define the hole, in this case a star-shaped hole
hole_mask.append(draw.Lines(
        100, 46, 132, 143, 47, 83, 152, 83, 67, 143,
        closed=True,
        fill='black'))

d.append(draw.Circle(100, 100, 36, fill='SkyBlue'))
d.append

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Argmaster
Comment options

Answer selected by cduck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants