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

Script to rotate selected objects by random increments of your choice

Engaged ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Just in case anyone's making patterns or something.

 

I wrote this tiny script that rotates all selected objects by random increments of 60 degrees, or 90, or whatever you want. It makes use of modulo for efficiency.

Free to use and share.

 

Please post to this thread anything you create with it as I believe it could produce some interesting patterns, mazes, etc. If you can find a way to do the same thing using just AI native tools please share your technique here.

Any bugs / feedback please also post here so I can improve the script.

 

First, a section of a seamless pattern I made just now using 3 hexagonal tiles and a few tricks (custom line profiles, Roughen filter, etc).

 

Enjoy!

 

Runninghead_Design 2020

 

Screenshot 2020-11-02 at 14.20.11.png

// Script to rotate all selected objects by set increments with the intention that it will be useful for the generation of pattern tiles. Copyright runninghead.com 2020. If you use this script please send me examples of your work, I'd love to see what you can do with it! Any suggestions / bug reports welcome.

// NOTE: Does not currently work through Groupings, so Ungroup your objects before running this script!

aDoc = app.activeDocument;
aSel = aDoc.selection;
nSel = aSel.length;// number of objects currently selected in illustrator
increment = Number(prompt("Rotation degree increments (30, 45, 60, 90, etc?)", 60));

for(i=0; i<nSel; i++)
{
	randomAngle = Math.floor(Math.random()*360);
	rotationAngle = randomAngle - (randomAngle % increment);
	aSel[i].rotate(rotationAngle, rotationAngle);
}

// end of script

 

TOPICS
Scripting

Views

1.5K

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 1 Correct answer

Community Expert , Nov 02, 2020 Nov 02, 2020

I like the pattern! Clever choice of hexagonal cells I think. Would you mind posting a screen shot of the 3 hexes you used?

 

Also, not a bug, but just for seeing different ways of scripting, here's how I would start your script if I wrote it:

 

 

var items = app.activeDocument.selection;

// then, I'd use items.length here 
for (var i=0; i<items.length; i++) {

 

 

 

Also, the rotate method just needs the angle parameter once, eg. pathItem.rotate(60).

 

Thanks for sharing!

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

I like the pattern! Clever choice of hexagonal cells I think. Would you mind posting a screen shot of the 3 hexes you used?

 

Also, not a bug, but just for seeing different ways of scripting, here's how I would start your script if I wrote it:

 

 

var items = app.activeDocument.selection;

// then, I'd use items.length here 
for (var i=0; i<items.length; i++) {

 

 

 

Also, the rotate method just needs the angle parameter once, eg. pathItem.rotate(60).

 

Thanks for sharing!

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 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

And here's another approach to calculating the rotation angle. I've only tested on a calculator, so let me know if it doesn't work right for your use.

 

 

 

// gives a number between 0 and 5 for increment = 60
var rotationIndex = Math.floor(Math.random * (360 / increment - 1));

// so rotation is that many times the increment
var rotationAngle = rotationIndex * increment;

 

 

 

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
Engaged ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Interesting! I'll look in to this ASAP and amend the script (almost midnight here). Thank you @m1b !

As I hope is visible in the screen grab, I used 0% transparency on some line segments to preserve the overall hexagonal shape for the 3 symbols (restored these to 10% for the grab).

 

Roughness provided by a custom line profile.

 

Many Escher tesselations seem to break down to 6 triangles within each hex, triangles that link back in to each other. This affords a powerful method for interlinking of decorative or illustrative artwork. I'll attempt some more patterns soon and post here.

 

Screenshot 2020-11-02 at 23.35.29.png

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 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Thank you, that's excellent!

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

Copy link to clipboard

Copied

The two elements (below) seem identical?

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
Engaged ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

Oops! My bad- in a rush, chose the wrong one. Will correct the grab and repost. Thx

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
Engaged ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

NOTE: Custom line profiles, etc will change the way illustrator calulates teh width of each hex, leading to the need to adjust your math when positioning each hex in the initial group (assuming you're using Transform to duplicate them, then Expand Appearance to leave the many instances of the original symbols).

 

Corrected grab:

 

Screenshot 2020-11-06 at 16.58.33.png

 

Proof of random incremental rotation (top lines all in orange):

Screenshot 2020-11-06 at 17.49.50.png

 

New code (way more sensible, efficient and works exactly the same!):

Screenshot 2020-11-06 at 17.06.58.png

 

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 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Looks good!

 

I still don't think you need the double parameter for the rotate. Is that deliberate?

items[i].rotate(rotationAngle);

 

Also, this is not important in your case, but I would incorporate an unpainted circle as part of the symbol definitions. If you make this circle centred on the centre of the hexagon, and make it at least large enough that it defines the bounding box, then even if you break the link to the symbols later, you can still rotate the items with your script without them wandering around (because a circle at any rotation has the same bounding box).

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
Engaged ,
Nov 07, 2020 Nov 07, 2020

Copy link to clipboard

Copied

Yeah, sorry m1b, I really should spend more time reading (and working on this) before posting- been a bit distracted lately! 😅 

Thank you so much for the excellent help, much appreciated.

the unpainted circumcircle idea is intriguing, it would work well to counteract the way stroke profile/weight get calculated in to the overall width & height of the duplicated symbols but breaking the link to the duplicated symbols is not possible for me because of where I'm taking this project. Wish I could explain more here but this forum's public.

 

Looking at the double parameter later today.

 

tbh- my coding's very rusty as I've been ill for almost a year and I'm only just getting back to the keyboard, so I may have some dumbass, script-kitty questions for you later! 🙂

 

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
Engaged ,
Nov 07, 2020 Nov 07, 2020

Copy link to clipboard

Copied

Ah! I spent an embarrassingly long time staring at the code in your last post before realising that you were referring to my code! 😂
(I'm blaming the morphine 🙂)

items[i].rotate(rotationAngle, rotationAngle);


is now changed to

items[i].rotate(rotationAngle);


Script works the same.

Duplicated parameter was legacy from script to resize symbols by width and height independently.

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
Community Expert ,
Nov 07, 2020 Nov 07, 2020

Copy link to clipboard

Copied

Sorry to hear you been ill for so long. Hope your well on the road to recovery! Don't stress about the code... what you're doing is great. I love it. And making missteps is par for the course.

 

The rotate method takes several parameters. The first is the angle. The next four are the boolean options changePositions, changeFillPatterns, changeFillGradients, changeStrokePattern, and the last is rotateAbout.

 

Passing the angle number in as the second parameter equates to true unless the angle is zero. So in your case it works by chance. 😜

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
Engaged ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

LATEST

Wow that's sone handy info! & thanks @m1b 

Love the extra detail in your reply.

Can't wait to post the next phase of this here. That'll probably happen next week sometime. 

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