Copy link to clipboard
Copied
I just create actions and I need it to start with creating random lines
is that any way to do that
plz help
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#randomscribble
Copy link to clipboard
Copied
Are you familiar with Illustrator Scripting and JavaScript?
What are the parameters of the line and its randomness?
Copy link to clipboard
Copied
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];
};
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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˚.
Copy link to clipboard
Copied
Salut!
Comme cela ?
De elleere
Copy link to clipboard
Copied
Hi @renél80416020. If you are able to show your code, I would be very much interested in seeing it.
Copy link to clipboard
Copied
+1
the whole world wants to see it.
Copy link to clipboard
Copied
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.)
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);
}
Copy link to clipboard
Copied
looking good!!
Copy link to clipboard
Copied
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
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;
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é...
Copy link to clipboard
Copied
Thanks. There's a lot to unpack in here. I'll try to go though it over the weekend. Thanks again.
Copy link to clipboard
Copied
thanks for sharing Rene!
Copy link to clipboard
Copied
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#randomscribble
Copy link to clipboard
Copied
Very nice.
Copy link to clipboard
Copied
awesome! thanks for sharing!
Copy link to clipboard
Copied
Excellent, this is exactly what I want.
Copy link to clipboard
Copied
Great approach, Sergey.
Thank you.