R
R
Ragtime Kitty2019-04-16 13:26:56
JavaScript
Ragtime Kitty, 2019-04-16 13:26:56

How to cut a polygon from canvas?

Hello.
I want to cut out a polygon from the canvas and draw it in a different place.
Like this:
5cb5ab0740b3c427795132.png
I tried to do it through such a sequence

ctx.getImageData()
ctx.clearRect()
ctx.putImageData()

And it seems to work, but getImageData only accepts rectangles as coordinates, and I need a polygon :(

There was an idea to rotate the context before getting the imageData, but apparently it doesn't work that way.
More or less like this
5cb5ac9e11399049423951.png

Can you please tell me how to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GreatRash, 2019-04-16
@Ragtime_Kitty

https://jsfiddle.net/pL2jxnds/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question