Copy link to clipboard
Copied
Hi all, after importing a PNG into Animate and adding it to the stage, I'm trying to discover if there is anyway I can generate a list of random positions within that shape. To give context, the PNG would act like a mask to determine the bounds of an area I'd like to spawn some VFX in - so for example, if I wanted some dust particles automatically placed on a volcano, I'd create an image matching the shape of the volcano mouth and then some coding wizardry would spawn a list of VFX within that shape.
If there's an alternative method which achieves the same goal, I'm all ears!
Thanks for any help!
Thanks for the clarification.
So I guess you'll have to iterate over the vertices of a shape instance and look online for an algorithm that lets you find a random point inside of the polygon defined by them.
var shape = fl.getDocumentDOM().selection[0];
var points = [];
var i;
var total = shape.edges.length;
for (i = 0; i < total; i++)
{
var hEdge = shape.edges[i].getHalfEdge(0);
var vertex = hEdge.getVertex();
points.push({ x: vertex.x, y: vertex.y });
}
Copy link to clipboard
Copied
Hi.
Maybe I'm not getting the issue correctly, but I think you can just get the x, y, width and height of the PNG instance and create random positions based on the bounds defined by them.
Is this what you want?
Please let us know.
Regards,
JC
Copy link to clipboard
Copied
Hey - thanks for the response. So I should have been more specific! I was thinking more non-uniform shapes, not a square or rectangle (as you say I could get their position/height width and calculate what I require). Thanks!
Copy link to clipboard
Copied
Thanks for the clarification.
So I guess you'll have to iterate over the vertices of a shape instance and look online for an algorithm that lets you find a random point inside of the polygon defined by them.
var shape = fl.getDocumentDOM().selection[0];
var points = [];
var i;
var total = shape.edges.length;
for (i = 0; i < total; i++)
{
var hEdge = shape.edges[i].getHalfEdge(0);
var vertex = hEdge.getVertex();
points.push({ x: vertex.x, y: vertex.y });
}
Copy link to clipboard
Copied
@JoãoCésarAppreciate the response and that's a great starting point, thanks again!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now