﻿/*  
author: @ce0311
This script returns some cool radial typo flowers
in InDesign. Just play with the following variables 
and have some fun! Tested with InDesign CS6.
*/

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

var _width = 300; //canvas width
var _height = 300; //canvas height

var _boxw = 20; //text box width
var _boxh = 10; //text box height
var _boxwadd = 20; //text box width increase for each iteration
var _boxhadd = 5; //text box height increase for each iteration

var _ts = 30; //text size
var _tsadd = 10; //text size increase every iteration
var _bcont = "8"; //box content

var _numboxes = 15; //number of boxes; flower leaves
var _rotadd = 13; //rotation increase for each iteration

var _numcircles = 25; //number of circles

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

//start magic

var _roff = 0; //rotation starts at 0

var doc = app.documents.add({ //create new document and set width + height
        documentPreferences:{
                pageWidth : _width,
                pageHeight: _height,
                facingPages : false
        }
});

for(var j = 0;j < _numcircles; j++){ // start the loop (cirlces)
    
    var _roff = _roff + _rotadd; //increase rotation

    //calculate box width and height
    var _boxhr = _boxh + _boxhadd *j;
    var _boxwr = _boxw + _boxwadd *j;

    for(var i = 0;i < _numboxes; i++){ //start 2nd loop (flower leaves, or boxes)

            //calculate points of the textbox
    
            var _xa = _width / 2 - _boxwr / 2
            var _ya = _height / 2 - _boxhr / 2
            var _xb = _width / 2 + _boxwr / 2
            var _yb = _height / 2 + _boxhr / 2

            var tb= doc.pages.item(0).textFrames.add({ //add the box to the document
                
                    geometricBounds:[_ya,_xa,_yb,_xb], //set the position
                    contents: _bcont, //box content
                    
                    textFramePreferences:{ //align center
                        verticalJustification: VerticalJustification.CENTER_ALIGN
                    }
            });

            var boxText = tb.paragraphs.item(0); //select the box we just created
            var _tsr = _ts + _tsadd * j; //calculate text size

            boxText.properties = { //set text size, right-align
                    pointSize: _tsr,
                    justification : Justification.RIGHT_ALIGN      
            };
        
            var rotate = app.transformationMatrices.add({counterclockwiseRotationAngle:(360/_numboxes*i + _roff)}); //calculate rotation
            tb.transform(CoordinateSpaces.pasteboardCoordinates, AnchorPoint.centerAnchor, rotate); //rotate

     }; 

 }; 

// the end

