/*
this script makes a line or group of lines dashed, with random values within a user defined range
it's kind of fun to use on lots and lots of lines at once. Why not use it with the spiderweb script or wall blazer?
After all, who doesn't love a little randomness?
*/
var values = {
	maxdash: 20, //maxumum dash length
	mindash: 2, //minimum dash length
	maxgap: 20, //maxumum gap length
	mingap: 2  //minimum gap length
};

var dashes = 6 //this seems to be the maximum number of different dashes and gaps illustrator can use.
var dasharray = [] //an array used to give lines their dashes and gaps.


// ----------------------------------------------

var sel = document.getSelectedItems(Path); //puts all selected items in an array called sel

if(!sel.length) {
	Dialog.alert('Please select one or more paths and execute the script again.');	
} else {
	// specify values by prompt
	values = Dialog.prompt('Random Dashes', {
		maxdash: { description:'Maximum Dash (in points)'},
		mindash: { description:'Mimimum Dash (in points)'},
		maxgap: { description:'Maximum Gap (in points)'},
		mingap: { description:'Mimimum Gap (in points)'},
		dashes: { description:'Amount of dashes'},
	}, values);

	for (var i = 0; i < sel.length; i++) { //this loop cycles through all selected items
			var item = sel[i];
			item.dashArray = randomarray(); //apply a random stroke to the line
	}
}


function randomarray(){ //function for making an array of random numbers
	for (var i = 0; i < dashes; i+=2){
		dasharray.push(Math.random() * (values.maxdash - values.mindash) + values.mindash); //random value for the dash, between the numbers mindash and maxdash
		dasharray.push(Math.random() * (values.maxgap - values.mingap) + values.mingap); //random value for the dash, between the numbers mingap and maxgap
	}
	return dasharray;
}
