Reputation: 357
I have a shape (a quarter circle) that I've created using the html canvas function:
moveTo
LineTo
QuadraticCurveTo
How do I go about exploding the shape into particles and then return them to form a circle?
Upvotes: 2
Views: 398
Reputation: 63862
I'm not going to write the code for you because it will take some time, and I'm sure you can find examples on the web, but I'll tell you the theory you need to know in order to make such a thing.
document.createElement('canvas')
) that will never be seen on the page. This canvas must be at least as large as your object. I'm going to assume it is exactly as large as your object. We'll call this tempCanvas
and it has tempCtx
So to do the explosion:
ctx.drawImage(tempCanvas, x, y)
so the user sees something[20][30]
to correspond.[x][y]
and use ctx.drawImage(tempCanvas, x, y, 1, 1, newX, newY, 1, 1)
where x and y are the same as the pixel's [x][y]
and the newX and newY are calculated using the vector and finding what the next point would be along its line.The result will be each pixel of the image being drawn in a location that is slightly more away from the original click point. If you continue to do this frame after frame it will look as if the object has exploded.
That's the general idea, anyway. Let me know if any of it is unclear.
note 1: Most likely your normal canvas won't be the same size as the to-explode object. Maybe the object is placed at 100,100 so you really clicked on 110, 115 instead of 10,15. I'm omitting that offset just for the sake of simplicity.
Upvotes: 1