Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Anyway for JSFL to read PNG data or anything else that can define bounds!

Explorer ,
Feb 11, 2025 Feb 11, 2025

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!

322
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 11, 2025 Feb 11, 2025

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 });
}

 

 

Translate
Community Expert ,
Feb 11, 2025 Feb 11, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2025 Feb 11, 2025

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2025 Feb 11, 2025

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 });
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2025 Feb 13, 2025
LATEST

@JoãoCésarAppreciate the response and that's a great starting point, thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines