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

random stroke weight/thickness script

Explorer ,
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

157

Likes

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.

 

Likes

Translate

Translate
Advisor , 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") {
      
...

Likes

Translate

Translate
Contributor , Nov 07, 2022 Nov 07, 2022

Likes

Translate

Translate
Advisor ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

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

Likes

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
Explorer ,
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

Likes

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
Advisor ,
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;
}

 

Likes

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

Copy link to clipboard

Copied

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

Likes

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
Advisor ,
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;
}

 

Likes

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

Copy link to clipboard

Copied

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

Likes

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.

 

Likes

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
Explorer ,
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

Likes

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.

 

Likes

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
Explorer ,
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

Likes

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

Copy link to clipboard

Copied

Likes

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

Copy link to clipboard

Copied

LATEST

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

Likes

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