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

“random mountains”script.How to implement in animate?

Contributor ,
Apr 19, 2022 Apr 19, 2022
var arr=[],N=10,H=100,S=25,B=0.1,pts=[];
for(i=0;i<N;i++)arr.push(Math.random()*H);
for(var i=-S;i<=H+S;i++)pts.push([i,f(i)]);
pts.push([H+S,-S],[-S,-S])
app.activeDocument.pathItems.add().setEntirePath(pts)
function f(x){
var d,y=0;
for(var i=0;i<N;i++)if((d=S-Math.abs(arr[i]-x))>0)y+=d*B;
return y;
} // #dtp

 

TOPICS
ActionScript , Code , Exchange extensions
259
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 , Apr 19, 2022 Apr 19, 2022

Hi.

 

A suggestion:

 

var dom = fl.getDocumentDOM();
var arr = [];
var N = 10;
var H = 100;
var S = 25;
var B = 0.1;
var pts = [];
var i, myPath;

function f(x)
{
	var y = 0;
	var d, i;

	for (i = 0; i < N; i++)
		if ((d = S - Math.abs(arr[i] - x)) > 0) y += d * B;

	return y;
}

for (i = 0; i < N; i++)
    arr.push(Math.random() * H);

for (i = -S; i <= H + S; i++)
    pts.push([i, f(i)]);

path = fl.drawingLayer.newPath();

for (i = 0; i < pts.length; i++)
	path.addPoint(-pts[i][0], -pts[i][1]
...
Translate
Contributor ,
Apr 19, 2022 Apr 19, 2022

截屏2022-04-19 下午4.56.18.pngexpand image

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 ,
Apr 19, 2022 Apr 19, 2022

Hi.

 

A suggestion:

 

var dom = fl.getDocumentDOM();
var arr = [];
var N = 10;
var H = 100;
var S = 25;
var B = 0.1;
var pts = [];
var i, myPath;

function f(x)
{
	var y = 0;
	var d, i;

	for (i = 0; i < N; i++)
		if ((d = S - Math.abs(arr[i] - x)) > 0) y += d * B;

	return y;
}

for (i = 0; i < N; i++)
    arr.push(Math.random() * H);

for (i = -S; i <= H + S; i++)
    pts.push([i, f(i)]);

path = fl.drawingLayer.newPath();

for (i = 0; i < pts.length; i++)
	path.addPoint(-pts[i][0], -pts[i][1]);
	
path.addPoint(-pts[0][0], -pts[0][1]);
path.makeShape();

 

 

Just remember to put the code in a .jsfl file.

 

I hope it helps.

 

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
Contributor ,
Apr 19, 2022 Apr 19, 2022

Thankyou, works perfectly.

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 ,
Apr 19, 2022 Apr 19, 2022
LATEST

You're welcome.

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