numTeeth 	= 25;
radius		= 50;
thinning	= 0.2;
depth		= 6;

function onMouseUp( event ) {
	center 	= event.point;
	path 	= new Path();
	
	var rad, x, y, p;
	for( var tooth = 0; tooth <= numTeeth * 2; ++tooth ) {
		if( !( tooth % 2 ) ) {
			// Right
			rad = radius - depth;
			x 	= center.x + Math.sin( ( tooth + 0 ) / numTeeth * Math.PI  ) * rad;
			y 	= center.y + Math.cos( ( tooth + 0 ) / numTeeth * Math.PI  ) * rad;
			p 	= new Point( x, y );
			if( tooth == 0 ) {
				path.moveTo( p );
			} else {
				path.lineTo( p );
			}
			
			// Up
			rad = radius;
			x 	= center.x + Math.sin( ( tooth + thinning ) / numTeeth * Math.PI  ) * rad;
			y 	= center.y + Math.cos( ( tooth + thinning ) / numTeeth * Math.PI  ) * rad;
			p 	= new Point( x, y );
			path.lineTo( p );
			
			// Right
			rad = radius;
			x 	= center.x + Math.sin( ( tooth + 1 - thinning ) / numTeeth * Math.PI  ) * rad;
			y 	= center.y + Math.cos( ( tooth + 1 - thinning ) / numTeeth * Math.PI  ) * rad;
			p 	= new Point( x, y );
			path.lineTo( p );
			
			// Down
			rad = radius - depth;
			x 	= center.x + Math.sin( ( tooth + 1 ) / numTeeth * Math.PI  ) * rad;
			y 	= center.y + Math.cos( ( tooth + 1 ) / numTeeth * Math.PI  ) * rad;
			p 	= new Point( x, y );
			path.lineTo( p );
		} else {
			rad = radius - depth;
			x 	= center.x + Math.sin( tooth / numTeeth * Math.PI  ) * rad;
			y 	= center.y + Math.cos( tooth / numTeeth * Math.PI  ) * rad;
			p 	= new Point( x, y );
			path.lineTo( p );
		}
	}
}

function onOptions() {
	var values = Dialog.prompt("Gears:", [
		{ value: numTeeth, 	description: "Teeth Count", width: 50 },
		{ value: radius, 	description: "Radius", 		width: 50 },
		{ value: thinning, 	description: "Thinning", 	width: 50 },
		{ value: depth, 	description: "Teeth depth", width: 50 }
	]);
	if (values) {
		numTeeth 	= values[0];
		radius 		= values[1];
		thinning 	= values[2];
		depth 		= values[3];
	}
}