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

Any easy way to make a random lines like this one

Community Beginner ,
Jul 11, 2021 Jul 11, 2021

I just create actions and I need it to start with creating random lines

is that any way to do that

plz help

2021-07-11 (4).png

TOPICS
Scripting , Tools
3.1K
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

Enthusiast , Jul 29, 2021 Jul 29, 2021

I used your idea and the smoothing script from Hiroyuki Sato. And created another version of the random line generator

https://github.com/creold/illustrator-scripts#randomscribble68747470733a2f2f692e6962622e636f2f6236466674506b2f52616e646f6d2d5363726962626c652e676966.gif

 

Translate
Adobe
Community Expert ,
Jul 11, 2021 Jul 11, 2021

Are you familiar with Illustrator Scripting and JavaScript? 

What are the parameters of the line and its randomness? 

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
Guide ,
Jul 11, 2021 Jul 11, 2021

This can be very complex.  For the simplest case:

 

var points = 5;  // How many points?
var doc = activeDocument;
var w = doc.width;
var h = doc.height;

var line = new Line();
line.drawLine(points);

function Line () {
    this.path1 = doc.pathItems.add();
    this.drawLine = function (points) {
        for (var i = 0; i < points; i++) {
            this.getPoints();
        }
    };
    this.getPoints = function () {
        var p = this.path1.pathPoints.add();
        p.anchor = this.getPoint();
        p.rightDirection = this.getPoint();
        p.leftDirection = this.getPoint();
        return p;
    };
    this.getPoint = function () {
        var x = Math.floor(Math.random() * w);
        var y = - Math.floor(Math.random() * h);
        return [x, 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
Community Expert ,
Jul 11, 2021 Jul 11, 2021

randomLines_femke.PNG

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 ,
Jul 11, 2021 Jul 11, 2021

The example the OP posted looks like they might want curves points, so it might be necessary to additionally lock the angles of leftDirection and rightDirection at 180˚. 

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
Advocate ,
Jul 12, 2021 Jul 12, 2021

Salut!

 Comme cela ?

Capture ar.PNG

De elleere

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
Guide ,
Jul 13, 2021 Jul 13, 2021

Hi @renél80416020.  If you are able to show your code, I would be very much interested in seeing it. 

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 ,
Jul 13, 2021 Jul 13, 2021

+1

 

the whole world wants to see it.

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
Guide ,
Jul 14, 2021 Jul 14, 2021

My attempt at copying René, albeit with equidistant handles:  (I have an idea on how to do non-equidistant handles, but I'm finding implementating it pernickety; I might try again tomorrow.)

Untitled.png

var points = 10;  // How many points?
var doc = app.activeDocument;
var w = doc.width;
var h = doc.height;
var color1 = doc.swatches["Black"].color;
var color2 = doc.swatches["CMYK yellow"].color;

var line = new Line();
line.drawLine(points);

function Line() {
    this.path1 = doc.pathItems.add();
        this.path1.strokeColor = color1;
        this.path1.filled = false;
    this.group1 = doc.groupItems.add();
        this.group1.name = "handles";
    this.drawLine = function (points) {
        for (var i = 0; i < points; i++) {
            this.getPoints();
        }
    };
    this.getPoints = function () {
        var p = this.path1.pathPoints.add();
        p.anchor = this.getPoint();
        var handle = this.getHandle(p.anchor);
        p.rightDirection = handle[0];
        p.leftDirection = handle[1];
        this.drawHandles(handle[0], handle[1]);
        return p;
    };
    this.getPoint = function () {
        var min = 50;
        var x = Math.floor(Math.random() * ((w - min) - min + 1)) + min;
        var y = Math.floor(Math.random() * ((- h + min) + min + 1)) - min;
        return [x, y];
    };
    this.getHandle = function (a) {
        var max = 50;
        var min = - max;
        var dx = Math.floor(Math.random() * (max - min + 1)) + min;
        var dy = Math.floor(Math.random() * (max - min + 1)) + min;
        var handle1 = [a[0] + dx, a[1] - dy];
        var handle2 = [a[0] - dx, a[1] + dy];
        return [handle1, handle2];
    };
    // handle line, delete if unneeded
    this.drawHandles = function (handle1, handle2) {
        var path1 = doc.pathItems.add();
        path1.setEntirePath([handle1, handle2]);
        path1.strokeColor = color2;
        path1.moveToEnd(this.group1);
    };
}

// text, delete if unneeded
line.path1.selected = true;
var group1 = doc.groupItems.add();
group1.name = "text";
for (var i = 0; i < selection[0].pathPoints.length; i++) {
    var x = selection[0].pathPoints[i].anchor[0];
    var y = selection[0].pathPoints[i].anchor[1];
    var text1 = doc.textFrames.pointText( [x, y - 10] );
    text1.contents = "p" + i;
    text1.textRange.paragraphAttributes.justification = Justification.CENTER;
    text1.textRange.characterAttributes.size = 5;
    text1.moveToEnd(group1);
}
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 ,
Jul 14, 2021 Jul 14, 2021

looking good!!

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
Advocate ,
Jul 16, 2021 Jul 16, 2021

Bonjour!

J'ai utilisé un script existant de 2013, où je me suis contenté d'ajouté la construction d'un tracé aléatoire composé de segments de droite, avec en plus en prévision quelques aménagements, et d'autres choses difficiles à expliquer ici...

Je n'ai malheureusement pas le temps en ce moment de finaliser.

Mais pour faire au plus court, si cela peut aider, je donne une partie des ajouts au script à insérer au début juste après la ligne 43 fin de la zone INIT.

  var closed  = true;
  var poinths = 10;  // How many points?
  var bordure = 40;
  var doc = activeDocument;
  var Origin = doc.rulerOrigin;
  var w = doc.width;
  var h = doc.height;
  var origX = -Origin[0];
  var origY = -Origin[1];
      w -= bordure*2;
      h -= bordure*2;
  var line = doc.pathItems.add();
  var pxy;
        for (var i = 0; i < poinths; i++) {
          pxy = getPoint(w,h);
          pointSuivant(origX+pxy[0]+bordure,origY+pxy[1]+bordure,line);
        }
      line.filled = false;
      line .srtokewidth = 1;
      line.strokeColor = macmykColor(0,20,0,100);
      line.closed = closed;
      line.selected = true;
// ----
function getPoint (w,h) {
  return [Math.floor(Math.random()*w), Math.floor(Math.random()*h)];
}
// ----
function pointSuivant(x,y,line)
{//Ajoute un point à un tracé
  var newPoint = line.pathPoints.add();
    with(newPoint){
      anchor = [x,y];
      leftDirection = anchor;
      rightDirection = anchor;
      pointType = PointType.CORNER;
    }
}

Voici le lien vers l'article que j'ai publié à l'époque sur Sriptodedia où vous pourrez télécharger le script.

https://www.scriptopedia.org/js-illustrator/162-arrondir-les-angles.html

 

Ce script propose deux méthodes:
1 Si la variable fixe = false, n doit saisir le Rapport ligne directrice / segment, par exemple 0.25.
Mon intention est d'ajouter la possibilité de saisir une plage par exemple entre 0.2,0.45

Cette option est réalisée et donne le résultat suivant

boite 2.PNG

boite 4.PNG

2 si la variable fixe = true les lignes directrices sont de même longueur (exprimée en pts)
Je voudrais ajouter la possibilité de saisir une plage par exemple entre 10,30
Cette option n'est pas encore réalisée, donc avec une seule valeur le résultat est le suivant
exemple lg = 30;

boite 5.PNG

De plus, ce serait bien d'ajouter la possibilité de faire plusieurs essais sans être obligé relancer l'exécution du script.

A plus tard René...

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
Guide ,
Jul 16, 2021 Jul 16, 2021

Thanks.  There's a lot to unpack in here.  I'll try to go though it over the weekend.  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
Community Expert ,
Jul 16, 2021 Jul 16, 2021

thanks for sharing Rene!

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
Enthusiast ,
Jul 29, 2021 Jul 29, 2021

I used your idea and the smoothing script from Hiroyuki Sato. And created another version of the random line generator

https://github.com/creold/illustrator-scripts#randomscribble68747470733a2f2f692e6962622e636f2f6236466674506b2f52616e646f6d2d5363726962626c652e676966.gif

 

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
Guide ,
Jul 29, 2021 Jul 29, 2021

Very nice.

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 ,
Jul 29, 2021 Jul 29, 2021

awesome! thanks for sharing!

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 Beginner ,
Aug 04, 2021 Aug 04, 2021
LATEST

Excellent, this is exactly what I want.

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 ,
Jul 29, 2021 Jul 29, 2021

Great approach, Sergey.

 

Thank you.

 

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