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

random stroke weight/thickness script

Participant ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Hello everyone, do you know if there is a free script to vary the thickness of the strokes randomly or in a parametric way? so far not found ... Thank you very much

TOPICS
Scripting , Tools

Views

1.1K

Translate

Translate

Report

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 3 Correct answers

Community Expert , Nov 03, 2022 Nov 03, 2022

That should work as well if you enable the "Scale Strokes and Effects" option and disable the "Transform Objects" option at the bottom of the Transform Each dialog.

 

Votes

Translate

Translate
Guide , Nov 03, 2022 Nov 03, 2022

Alternatively, you could try random normal distribution.  Again, select items. You can change mean and standard deviation in the first line.

var mean = 5, SD = 1;
var y2 = 0;
var array = [];
function push(items) {
    for (var i = 0; i < items.length; i++) {
        if (items[i].typename == "PathItem") {
            array.push(items[i]);
        } else if (items[i].typename == "GroupItem") {
            push(items[i].pageItems);
        } else if (items[i].typename == "CompoundPathItem") {
      
...

Votes

Translate

Translate
Enthusiast , Nov 07, 2022 Nov 07, 2022

Votes

Translate

Translate
Adobe
Guide ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Do you mean vary the thickness of the strokes from item to item? 

Votes

Translate

Translate

Report

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
Participant ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Hi, I mean that I have a series of strokes and I would like each one to have different thicknesses ... either randomly or by setting some range (min -max), thanks

Votes

Translate

Translate

Report

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
Guide ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Select items.  You can change min and max in the first line.

var min = 1, max = 5;
var array = [];
function push(items) {
    for (var i = 0; i < items.length; i++) {
        if (items[i].typename == "PathItem") {
            array.push(items[i]);
        } else if (items[i].typename == "GroupItem") {
            push(items[i].pageItems);
        } else if (items[i].typename == "CompoundPathItem") {
            push(items[i].pathItems);
        }
    }
}
push(app.selection);
for (var i = 0; i < array.length; i++) {
    if (array[i].stroked)
    var x = Math.floor(Math.random() * (max - min + 1)) + min;
    array[i].strokeWidth = x;
}

 

Votes

Translate

Translate

Report

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
Participant ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

a thousand thanks!!!
I'll try it tomorrow

Votes

Translate

Translate

Report

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
Guide ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Alternatively, you could try random normal distribution.  Again, select items. You can change mean and standard deviation in the first line.

var mean = 5, SD = 1;
var y2 = 0;
var array = [];
function push(items) {
    for (var i = 0; i < items.length; i++) {
        if (items[i].typename == "PathItem") {
            array.push(items[i]);
        } else if (items[i].typename == "GroupItem") {
            push(items[i].pageItems);
        } else if (items[i].typename == "CompoundPathItem") {
            push(items[i].pathItems);
        }
    }
}
push(app.selection);
for (var i = 0; i < array.length; i++) {
    if (array[i].stroked)
    var x = randomGaussian(mean, SD);
    array[i].strokeWidth = x;
}
// randomGaussian()
function randomGaussian (tempmean, tempsd) {
    var mean = tempmean || 0;
    var sd = tempsd || 1;
    var y1, x1, x2, w;
    if (this.gaussianprevious) {
        y1 = y2;
        this.gaussianprevious = false;
    } else {
        do {
            x1 = this.Math.random() * 2 - 1;
            x2 = this.Math.random() * 2 - 1;
            w = x1 * x1 + x2 * x2;
        } while (w >= 1);
        w = Math.sqrt(-2 * Math.log(w) / w);
        y1 = x1 * w;
        y2 = x2 * w;
        this.gaussianprevious = true;
    }
    return y1 * sd + mean;
}

 

Votes

Translate

Translate

Report

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
Participant ,
Nov 04, 2022 Nov 04, 2022

Copy link to clipboard

Copied

thank you very much femkeblanco! both work perfectly ... thank you very much again!

Votes

Translate

Translate

Report

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

You may try Object menu > Transform > Transform Each with appropriate random settings.

 

Votes

Translate

Translate

Report

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
Participant ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

thank you, but so I would transform and change the size and length of the strokes while I just want to change the weight / thickness of the lines

Votes

Translate

Translate

Report

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

That should work as well if you enable the "Scale Strokes and Effects" option and disable the "Transform Objects" option at the bottom of the Transform Each dialog.

 

Votes

Translate

Translate

Report

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
Participant ,
Nov 04, 2022 Nov 04, 2022

Copy link to clipboard

Copied

You're right, Kurt also works like this ... I hadn't thought about it.
In any case, the Femkeblanco scripts are very useful.

Thank you all

Votes

Translate

Translate

Report

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
Enthusiast ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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
Participant ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

LATEST

Thanks Sergey, your scripts are always very useful and very well explained!

Votes

Translate

Translate

Report

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