The Golden Ratio

to come

A Golden Ratio Series

If we are designing with a series of shapes then one approach is to start with a series of shapes that are sized based on the size of the canvas and the golden ratio. We can use this series of circles like a color palette or musical scale, picking out the circle sizes that meet the goals of our creative project.

Draw Golden Ratio Shapes

Drawing a series of golden ratio shapes is a great job for AppleScript because it involves a lot of math and repetitive chores.

tell application "Adobe Illustrator"
activate
set theSizeDialogPrompt to "Size in points for the largest shape in the golden ratio series:"
try
set theDefaultSizeAnswer to the height of the current document
on error
set theDefaultSizeAnswer to "1000"
end try
display dialog theSizeDialogPrompt default answer theDefaultSizeAnswer buttons {"Cancel", "OK"} default button "OK" with title (the name as text) giving up after 60
if the button returned of the result is equal to "OK" then
set theSizeAnswer to the text returned of the result
set theShapeSize to round (theSizeAnswer as number)
set theDocumentWidth to theShapeSize
set theDocumentHeight to theShapeSize
set theCenterWidth to theDocumentWidth / 2
set theCenterHeight to theDocumentHeight / 2
set theShapeChoicePrompt to "Choose a shape to make:"
set theShapeChoices to {"circle", "square", "roundrect", "polygon", "star"}
set theDefaultShapeChoice to item 1 of theShapeChoices
try
choose from list theShapeChoices with title (the name as text) with prompt theShapeChoicePrompt default items theDefaultShapeChoice without multiple selections allowed and empty selection allowed
set theShapeChoice to the result as text
on error
set theShapeChoice to ""
end try
if theShapeChoice is not equal to "" then
set theGoldenRatioLongerSection to 0.618033
set theMinimumShapeSize to 2
make new document with properties {color space:RGB, default filled:true, height:theDocumentHeight, width:theDocumentWidth}
if theShapeChoice is equal to "circle" then
repeat while theShapeSize is greater than theMinimumShapeSize
make new ellipse in document 1 with properties {bounds:{theCenterWidth - theShapeSize / 2, theCenterHeight + theShapeSize / 2, theCenterWidth + theShapeSize / 2, theCenterHeight - theShapeSize / 2}}
set theShapeSize to round (theShapeSize * theGoldenRatioLongerSection)
end repeat
else if theShapeChoice is equal to "square" then
repeat while theShapeSize is greater than theMinimumShapeSize
make new rectangle in document 1 with properties {bounds:{theCenterWidth - theShapeSize / 2, theCenterHeight + theShapeSize / 2, theCenterWidth + theShapeSize / 2, theCenterHeight - theShapeSize / 2}}
set theShapeSize to round (theShapeSize * theGoldenRatioLongerSection)
end repeat
else if theShapeChoice is equal to "roundrect" then
repeat while theShapeSize is greater than theMinimumShapeSize
make new rounded rectangle in document 1 with properties {bounds:{theCenterWidth - theShapeSize / 2, theCenterHeight + theShapeSize / 2, theCenterWidth + theShapeSize / 2, theCenterHeight - theShapeSize / 2}, horizontal radius:theShapeSize / (theGoldenRatioLongerSection * 100), vertical radius:theShapeSize / (theGoldenRatioLongerSection * 100)}
set theShapeSize to round (theShapeSize * theGoldenRatioLongerSection)
end repeat
else if theShapeChoice is equal to "polygon" then
set theSidesChoicePrompt to "Number of polygon sides:"
set theSidesChoices to {"randomize", "5", "6", "7", "8", "9", "10", "11", "12"}
set theDefaultSidesChoice to item 1 of theSidesChoices
try
choose from list theSidesChoices with title (the name as text) with prompt theSidesChoicePrompt default items theDefaultSidesChoice without multiple selections allowed and empty selection allowed
set theSidesChoice to the result as text
on error
set theSidesChoice to ""
end try
if theSidesChoice is not equal to "" then
if theSidesChoice is equal to "randomize" then
repeat while theShapeSize is greater than theMinimumShapeSize
make new polygon in document 1 with properties {center point:{theCenterWidth, theCenterHeight}, radius:theShapeSize / 2, sides:(random number from 5 to 12)}
set theShapeSize to round (theShapeSize * theGoldenRatioLongerSection)
end repeat
else
repeat while theShapeSize is greater than theMinimumShapeSize
make new polygon in document 1 with properties {center point:{theCenterWidth, theCenterHeight}, radius:theShapeSize / 2, sides:(theSidesChoice as number)}
set theShapeSize to round (theShapeSize * theGoldenRatioLongerSection)
end repeat
end if
end if
else if theShapeChoice is equal to "star" then
set thePointsChoicePrompt to "Number of star points:"
set thePointsChoices to {"randomize", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}
set theDefaultPointsChoice to item 1 of thePointsChoices
try
choose from list thePointsChoices with title (the name as text) with prompt thePointsChoicePrompt default items theDefaultPointsChoice without multiple selections allowed and empty selection allowed
set thePointsChoice to the result as text
on error
set thePointsChoice to ""
end try
if thePointsChoice is not equal to "" then
if thePointsChoice is equal to "randomize" then
repeat while theShapeSize is greater than theMinimumShapeSize
make new star in document 1 with properties {center point:{theCenterWidth, theCenterHeight}, inner radius:((theShapeSize / 2) * theGoldenRatioLongerSection), radius:theShapeSize / 2, point count:(random number from 3 to 16)}
set theShapeSize to round (theShapeSize * theGoldenRatioLongerSection)
end repeat
else
repeat while theShapeSize is greater than theMinimumShapeSize
make new star in document 1 with properties {center point:{theCenterWidth, theCenterHeight}, inner radius:((theShapeSize / 2) * theGoldenRatioLongerSection), radius:theShapeSize / 2, point count:(thePointsChoice as number)}
set theShapeSize to round (theShapeSize * theGoldenRatioLongerSection)
end repeat
end if
end if
end if
end if
end if
end tell

Example Scripts

Code Reuse

The blocks of example code on this page and the attached example scripts are open source software that everyone can use and modify and customize for their own purposes under MIT License.

(*
Copyright 2014 Simon White http://simonwhite.com/
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*)