Skip to content

Commit eb131b9

Browse files
authored
20240526-committ
1 parent db81bd9 commit eb131b9

File tree

6 files changed

+1557
-0
lines changed

6 files changed

+1557
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
var doc = app.activeDocument;
2+
3+
var masterIndex = 0;
4+
var masterSpreadLeft = doc.masterSpreads.item(masterIndex).pages.item(0);
5+
var masterSpreadRight = doc.masterSpreads.item(masterIndex).pages.item(1);
6+
7+
var pageHeight = Math.round(doc.documentPreferences.pageHeight * 10) / 10;
8+
var pageWidth = Math.round(doc.documentPreferences.pageWidth * 10) / 10;
9+
var pageRatio;
10+
if (pageHeight >= pageWidth) {
11+
pageRatio = pageWidth / pageHeight;
12+
} else if (pageWidth > pageHeight) {
13+
pageRatio = pageHeight / pageWidth;
14+
}
15+
16+
var marginTop, marginBottom, marginLeft, marginRight;
17+
var areasRatio = 1 - pageRatio;
18+
19+
var shortSideSubdivisions = 4;
20+
var gutter = 5;
21+
22+
clearAllGuides();
23+
IKissedASquareAndILikedIt(areasRatio, shortSideSubdivisions, gutter);
24+
25+
26+
27+
28+
29+
function IKissedASquareAndILikedIt(areasRatio, shortSideSubdivisions, gutter) {
30+
var pageShortSide, pageLongSide;
31+
if (pageHeight >= pageWidth) {
32+
pageShortSide = pageWidth;
33+
pageLongSide = pageHeight;
34+
} else if (pageHeight < pageWidth) {
35+
pageShortSide = pageHeight;
36+
pageLongSide = pageWidth;
37+
}
38+
39+
40+
// assign the short side margins value
41+
var shortSideMargins = Math.round(pageShortSide * areasRatio);
42+
if (pageHeight >= pageWidth) {
43+
marginLeft = shortSideMargins / 2;
44+
marginRight = shortSideMargins / 2;
45+
} else if (pageHeight < pageWidth) {
46+
marginTop = shortSideMargins / 2;
47+
marginBottom = shortSideMargins / 2;
48+
}
49+
50+
// define the width = height for the subsivisios to fit in the short side
51+
var subdivisionsLenght = (pageShortSide - shortSideMargins - gutter * (shortSideSubdivisions - 1)) / shortSideSubdivisions;
52+
53+
// calculate a draft for the long side margins lenght
54+
var longSideMarginsDraft = Math.round(pageLongSide * areasRatio);
55+
var longSideMargins;
56+
// calculate a draft for the number of subdivisions of the long side, then refine it considering the gutters
57+
var longSideSubdivisionsDraft = (pageLongSide - longSideMarginsDraft) / subdivisionsLenght;
58+
var longSideSubdivisions = Math.round((pageLongSide - longSideMarginsDraft - gutter * (longSideSubdivisionsDraft - 1)) / subdivisionsLenght);
59+
// check if the inner part of the long side (defined by the margins) is divisible by the subdivisions lenght
60+
// if it's not, recalculate the long side margins accordingly
61+
if ((pageLongSide - longSideMarginsDraft) % subdivisionsLenght !== 0) {
62+
longSideMargins = pageLongSide - (subdivisionsLenght * longSideSubdivisions) - gutter * (longSideSubdivisions - 1);
63+
}
64+
65+
// assign the long side margins value
66+
if (pageHeight >= pageWidth) {
67+
marginTop = longSideMargins / 2;
68+
marginBottom = longSideMargins / 2;
69+
} else if (pageHeight < pageWidth) {
70+
marginLeft = longSideMargins / 2;
71+
marginRight = longSideMargins / 2;
72+
}
73+
74+
75+
if (pageHeight >= pageWidth) {
76+
// set a loop to draw the long side guides
77+
for (var i = 0; i < shortSideSubdivisions; i++) {
78+
var xPosition = marginLeft + i * (subdivisionsLenght + gutter);
79+
80+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: xPosition });
81+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: xPosition + subdivisionsLenght });
82+
83+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: pageWidth + xPosition });
84+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: pageWidth + xPosition + subdivisionsLenght });
85+
}
86+
87+
// set a loop to draw the short side guides
88+
for (var j = 0; j < longSideSubdivisions; j++) {
89+
var yPosition = marginTop + j * (subdivisionsLenght + gutter);
90+
91+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition });
92+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition + subdivisionsLenght });
93+
94+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition });
95+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition + subdivisionsLenght });
96+
}
97+
}
98+
99+
else if (pageHeight < pageWidth) {
100+
// set a loop to draw the long side guides
101+
for (var i = 0; i < longSideSubdivisions; i++) {
102+
var yPosition = marginLeft + i * (subdivisionsLenght + gutter);
103+
104+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: yPosition });
105+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: yPosition + subdivisionsLenght });
106+
107+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: pageWidth + yPosition });
108+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: pageWidth + yPosition + subdivisionsLenght });
109+
}
110+
111+
// set a loop to draw the short side guides
112+
for (var j = 0; j < shortSideSubdivisions; j++) {
113+
var xPosition = marginTop + j * (subdivisionsLenght + gutter);
114+
115+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: xPosition });
116+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: xPosition + subdivisionsLenght });
117+
118+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: xPosition });
119+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: xPosition + subdivisionsLenght });
120+
}
121+
}
122+
123+
124+
masterSpreadLeft.marginPreferences.properties = {
125+
right: marginRight,
126+
top: marginTop,
127+
left: marginLeft,
128+
bottom: marginBottom,
129+
};
130+
masterSpreadRight.marginPreferences.properties = {
131+
right: marginRight,
132+
top: marginTop,
133+
left: marginLeft,
134+
bottom: marginBottom,
135+
};
136+
}
137+
138+
139+
140+
141+
142+
function clearAllGuides(){
143+
var numGuides = doc.guides.length;
144+
if (numGuides == 0) return;
145+
146+
for (var i = numGuides -1; i >=0; i--)
147+
{
148+
doc.guides[i].remove();
149+
}
150+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
var doc = app.activeDocument;
2+
3+
var masterIndex = 0;
4+
var masterSpreadLeft = doc.masterSpreads.item(masterIndex).pages.item(0);
5+
var masterSpreadRight = doc.masterSpreads.item(masterIndex).pages.item(1);
6+
7+
var pageHeight = Math.round(doc.documentPreferences.pageHeight);
8+
var pageWidth = Math.round(doc.documentPreferences.pageWidth);
9+
var pageRatio;
10+
if (pageHeight >= pageWidth) {
11+
pageRatio = pageWidth / pageHeight;
12+
} else if (pageWidth > pageHeight) {
13+
pageRatio = pageHeight / pageWidth;
14+
}
15+
16+
var marginTop, marginBottom, marginLeft, marginRight;
17+
var areasRatio = 1 - pageRatio;
18+
19+
clearAllGuides();
20+
everythingEverywhereAllAtPageRatio(areasRatio, 5);
21+
22+
23+
24+
25+
26+
function everythingEverywhereAllAtPageRatio(areasRatio, columns) {
27+
// calculate the total width of vertical margins and the total height of horizontal margins
28+
// by picking a custom percentage of the page width and height (default: same ratio of the page short to long side)
29+
var marginWidth = pageWidth * areasRatio;
30+
var marginHeight = pageHeight * areasRatio;
31+
32+
marginTop = marginHeight / 2;
33+
marginBottom = marginHeight / 2;
34+
marginLeft = marginWidth / 2;
35+
marginRight = marginWidth / 2;
36+
37+
38+
// calculate a draft for the columns width
39+
var columnsWidth = (pageWidth - marginWidth) / columns;
40+
// calculate the gutters width as a portion of the draft columns width
41+
// with the same ratio with the column width as the total margins width and height to the page width and height
42+
var guttersWidth = (pageWidth * areasRatio) / (2 * columns);
43+
// adjust the columns width to suit the gutters width
44+
columnsWidth = (pageWidth - marginWidth - guttersWidth * (columns - 1)) / columns;
45+
46+
// calculate a the rows height so that the module of the grid has the same proportions of the page and the rectangle defined by the margins
47+
// columnsWidth : (pageWidth - marginsWidth) = x : (pageHeight - marginsHeight) -> x = columnsWidth * (pageHeight - marginsHeight) / (pageWidth - marginsWidth)
48+
var rowsHeight = columnsWidth * (pageHeight - marginHeight) / (pageWidth - marginWidth);
49+
// Calculate the gutters height as a portion of the draft columns height
50+
// with the same ratio with the column height as the total margins width and height to the page width and height
51+
var guttersHeight = (pageHeight * areasRatio) / (2 * columns)
52+
53+
54+
// set a loop to draw the vertical guides
55+
for (var i = 0; i < columns; i++) {
56+
var xPosition = marginLeft + i * (columnsWidth + guttersWidth);
57+
58+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: xPosition });
59+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: xPosition + columnsWidth });
60+
61+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: pageWidth + xPosition });
62+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: pageWidth + xPosition + columnsWidth });
63+
}
64+
// set a loop to draw the horizontal guides
65+
for (var j = 0; j < columns; j++) {
66+
var yPosition = marginTop + j * (rowsHeight + guttersHeight);
67+
68+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition });
69+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition + rowsHeight });
70+
71+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition });
72+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition + rowsHeight });
73+
}
74+
75+
76+
// apply the margin values
77+
masterSpreadLeft.marginPreferences.properties = {
78+
right: marginRight,
79+
top: marginTop,
80+
left: marginLeft,
81+
bottom: marginBottom,
82+
};
83+
masterSpreadRight.marginPreferences.properties = {
84+
right: marginRight,
85+
top: marginTop,
86+
left: marginLeft,
87+
bottom: marginBottom,
88+
};
89+
}
90+
91+
92+
93+
94+
95+
function clearAllGuides(){
96+
var numGuides = doc.guides.length;
97+
if (numGuides == 0) return;
98+
99+
for (var i = numGuides -1; i >=0; i--)
100+
{
101+
doc.guides[i].remove();
102+
}
103+
}

Functions/fibonacciDreams.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
var doc = app.activeDocument;
2+
3+
var masterIndex = 0;
4+
var masterSpreadLeft = doc.masterSpreads.item(masterIndex).pages.item(0);
5+
var masterSpreadRight = doc.masterSpreads.item(masterIndex).pages.item(1);
6+
7+
var pageHeight = Math.round(doc.documentPreferences.pageHeight);
8+
var pageWidth = Math.round(doc.documentPreferences.pageWidth);
9+
var pageRatio;
10+
if (pageHeight >= pageWidth) {
11+
pageRatio = pageWidth / pageHeight;
12+
} else if (pageWidth > pageHeight) {
13+
pageRatio = pageHeight / pageWidth;
14+
}
15+
16+
var marginTop, marginBottom, marginLeft, marginRight;
17+
var areasRatio = 1 - pageRatio;
18+
19+
var flippingPreferences = ['horizontallyFlipped', 'verticallyStandard'];
20+
var columnsNumber = 5;
21+
var rowsNumber = 3;
22+
23+
24+
25+
26+
27+
clearAllGuides();
28+
fibonacciDreams(flippingPreferences, columnsNumber, rowsNumber);
29+
30+
31+
32+
33+
34+
function fibonacciDreams(flippingPreferences, columnsNumber, rowsNumber) {
35+
var pageDivider = columnsNumber - 1 + 2 + 3 + 5 * columnsNumber;
36+
var module = pageWidth / pageDivider;
37+
var subdivisionsLenght = module * 5;
38+
39+
40+
// get the user's flipping preferences and set the margins accordingly
41+
if (flippingPreferences[0] == 'horizontallyStandard') {
42+
marginRight = module * 2;
43+
marginLeft = module * 3;
44+
} else if (flippingPreferences[0] == 'horizontallyFlipped') {
45+
marginLeft = module * 2;
46+
marginRight = module * 3;
47+
}
48+
49+
if (flippingPreferences[1] == 'verticallyStandard') {
50+
marginTop = module * 2;
51+
marginBottom = module * 3;
52+
} else if (flippingPreferences[1] == 'verticallyFlipped') {
53+
marginBottom = module * 3;
54+
marginTop = module * 2;
55+
}
56+
57+
58+
var newPageHeight = marginTop + (module * 5) * rowsNumber + module * (rowsNumber - 1) + marginBottom;
59+
doc.documentPreferences.pageHeight = newPageHeight
60+
61+
// set a loop to draw the long side guides on the left page
62+
for (var i = 0; i < columnsNumber; i++) {
63+
var xPosition = marginLeft + i * (subdivisionsLenght + module);
64+
65+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: xPosition });
66+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: xPosition + subdivisionsLenght });
67+
}
68+
69+
// set a loop to draw the long side guides on the right page
70+
for (var j = 0; j < columnsNumber; j++) {
71+
var xPosition = marginRight + j * (subdivisionsLenght + module);
72+
73+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: pageWidth + xPosition });
74+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.vertical, location: pageWidth + xPosition + subdivisionsLenght });
75+
}
76+
77+
// set a loop to draw the short side guides
78+
for (var k = 0; k < rowsNumber; k++) {
79+
var yPosition = marginTop + k * (subdivisionsLenght + module);
80+
81+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition });
82+
masterSpreadLeft.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition + subdivisionsLenght });
83+
84+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition });
85+
masterSpreadRight.guides.add(undefined, { orientation: HorizontalOrVertical.horizontal, location: yPosition + subdivisionsLenght });
86+
}
87+
88+
89+
// apply the margin values
90+
masterSpreadLeft.marginPreferences.properties = {
91+
right: marginLeft,
92+
top: marginTop,
93+
left: marginRight,
94+
bottom: marginBottom,
95+
};
96+
masterSpreadRight.marginPreferences.properties = {
97+
right: marginLeft,
98+
top: marginTop,
99+
left: marginRight,
100+
bottom: marginBottom,
101+
};
102+
}
103+
104+
105+
106+
107+
108+
function clearAllGuides(){
109+
var numGuides = doc.guides.length;
110+
if (numGuides == 0) return;
111+
112+
for (var i = numGuides -1; i >=0; i--)
113+
{
114+
doc.guides[i].remove();
115+
}
116+
}

0 commit comments

Comments
 (0)