Thursday, November 5, 2015 InDesign,Extendscript

Generate Sierpinski Triangle by InDesign Extendscripts

InDesign Extendscripts Art, I try to generate Sierpinski Triangle using InDesign Extendscripts. It is fun.

imac

This is simple, draw many triangles with recursive programming.

var drawTriangle = function( page, counter, startPoint, lengthOfSide ){
    var bottomLeftPoint  = createPoint( startPoint.x - lengthOfSide/2, startPoint.y+lengthOfSide );
    var bottomRightPoint = createPoint( startPoint.x + lengthOfSide/2, startPoint.y+lengthOfSide );

    var pointList = [ startPoint, bottomLeftPoint, bottomRightPoint, startPoint ];
    drawLines( page, pointList );

    if( counter<0 ){
       return ;
    }

    //
    // recursion
    //
    drawTriangle( page, counter-1, startPoint,       lengthOfSide/2 );
    drawTriangle( page, counter-1, bottomLeftPoint,  lengthOfSide/2 );
    drawTriangle( page, counter-1, bottomRightPoint, lengthOfSide/2 );
};

Full source code ... fractal-triangle.js