////////////////////////////////////////////////////////////////////////////////
// Note from the Scriptographer.org Team
//
// In Scriptographer 2.9, we switched to a top-down coordinate system and
// degrees for angle units as an easier alternative to radians.
// 
// For backward compatibility we offer the possibility to still use the old
// bottom-up coordinate system and radians for angle units, by setting the two
// values bellow. Read more about this transition on our website:
// http://scriptographer.org/news/version-2.9.064-arrived/

script.coordinateSystem = 'bottom-up';
script.angleUnits = 'radians';

var totalSides = 6;
var randomizeSides = false;

var radius = 20;
var randomizeRadius = false;

var valC = 0;
var randC = false;

var valM = 0;
var randM = false;

var valY = 0;
var randY = false;

var valK = 0;
var randK = false;

var specificRotate = 0;
var rotateArt = true;

var scatter = false;
var scatterOffset = 100;

function onOptions()
{
    var values = Dialog.prompt("Art Tests:", [
                                              
        {value:totalSides,description:"Total Sides:",width:100},
		{value:randomizeSides,description:"Random:",width:100},
		
		{value:radius,description:"Radius:",width:100},
		{value:randomizeRadius,description:"Random:",width:100},
		
		{value:valC,description:"Cyan",width:100},
		{value:randC,description:"Randomize",width:100},
		
		{value:valM,description:"Magenta",width:100},
		{value:randM,description:"Randomize",width:100},
		
		{value:valY,description:"Yellow",width:100},
		{value:randY,description:"Randomize",width:100},
		
		{value:valK,description:"Black",width:100},
		{value:randK,description:"Randomize",width:100},
		
		{value:specificRotate,description:"Specific Rotate",width:100},
		{value:rotateArt,description:"Random Rotate",width:100},
		
		{value:scatter,description:"Random Scatter",width:100},
		{value:scatterOffset,description:"Scatter Offset",width:100}
        
    ]);
    
    if(values != null)
    {
        totalSides     	= values[0];    
        randomizeSides 	= values[1];
		radius			= values[2];
		randomizeRadius	= values[3];
	
		valC 			= values[4];
		randC 			= values[5];
	
		valM 			= values[6];
		randM 			= values[7];
		
		valY 			= values[8];
		randY 			= values[9];
		
		valK 			= values[10];
		randK 			= values[11];
		
		specificRotate 	= values[12];
		rotateArt 		= values[13];
		
		scatter 		= values[14];
		scatterOffset 	= values[15];
    }
    
}

function onMouseDrag(event)
{
	var radiusResetValue = radius;
	var totalSidesResetValue = totalSides;
	
	var cyan 	= randC ? Math.random() : valC;
	var magenta = randM ? Math.random() : valM;
	var yellow 	= randY ? Math.random() : valY;
	var key 	= randK ? Math.random() : valK;
	
	var clr = new CMYKColor(cyan,magenta,yellow,key);
	var fll = new FillStyle(clr,false);
	
	if(randomizeSides)
	{
		totalSides = Math.max(3,Math.ceil(Math.random()*totalSides));
	}
	
    var mousePoint = event.point;
    var rads = 360/totalSides*(Math.PI/180);
	
	if(randomizeRadius)
	{
		radius = Math.random() * radius;
	}

	var path = new Path();
	path.closed = true;
	path.fillColor = clr;
	
	for(var i = 1; i <= totalSides; i++)
	{
		var point = mousePoint + new Point(Math.cos(rads * i), Math.sin(rads * i)) * radius;
		if(scatter) {
			point += new Point(Math.random() * scatterOffset, Math.random() * scatterOffset);
		}
		path.lineTo(point);
	}
    

	
	if(rotateArt)
	{
		path.rotate(Math.random()*360, mousePoint);
	}
	else
	{
		path.rotate(specificRotate, mousePoint);
	}
	
	radius = radiusResetValue;
    totalSides = totalSidesResetValue;
} 




