Skip to content

Instantly share code, notes, and snippets.

@somahargitai
Last active March 1, 2023 23:47
Show Gist options
  • Save somahargitai/19691facb976edc7c0a37a00bf068b8f to your computer and use it in GitHub Desktop.
Save somahargitai/19691facb976edc7c0a37a00bf068b8f to your computer and use it in GitHub Desktop.
Generate random lines
// Generate Random Lines In Adobe Illustrator
// change numberOfLines as you wish
// Run in Illustrator with File / Scripts / Other Script
var myDoc = app.activeDocument;
var numberOfLines = 4000;
// example line
var myLine1 = myDoc.pathItems.add();
myLine1.stroked = true;
myLine1.setEntirePath([
[220, 475],
[375, 300],
[200, 300],
]);
// all the other generated lines
for (var i = 0; i < numberOfLines; i++) {
var startX = Math.random() * 1000;
var startY = Math.random() * 1000;
var endX = Math.random() * 1000;
var endY = Math.random() * 1000;
var myNewLine = myDoc.pathItems.add();
myNewLine.stroked = true;
myNewLine.setEntirePath([
[startX, startY],
[endX, endY],
]);
}
var myDoc = app.activeDocument;
var numberOfLines = 1000;
// generate one long path with 4000 points
const pointArray = [];
for (var i = 0; i < numberOfLines; i++) {
var pointX = Math.random() * 1000;
var pointY = Math.random() * 1000;
pointArray.push([pointX, pointY]);
}
var myNewLine = myDoc.pathItems.add();
myNewLine.setEntirePath(pointArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment