//As a kid, I loved a mac paint feature that drew a mirror image of your line as you drew it. I haven't seen anything like it
//since. Don't laugh at the code, I'm fairly new to this programming stuff.
//Keegan

var docsize;
var axis, group, mainpath, rpathx, rpathy, rpathxy;

var values = {
	reflectx: 1,
	reflecty: 1,
	useaxis: 0
};

function onOptions() {
	values = Dialog.prompt("Reflector", {
		reflectx: { description: "Reflect across the X axis on(1) - off(0)"},
		reflecty: { description: "Reflect across the Y axis on(1) - off(0)"},
		useaxis: { description: "Reflect relative to: Artboard (0) - Line(1)"},
	}, values);
}

function onMouseDown(event) {
	group = new Group();
	// set the axis to either the artboard (0) or mouse location (1)
	axis = values.useaxis ? event.point * 2 : new Point(document.size);
	//initialize all nessicary lines
    mainpath = new Path();
	mainpath.moveTo(event.point);
	if (values.reflectx){
		rpathx = new Path();
		group.appendTop(rpathx);
	}
	if (values.reflecty){
		rpathy = new Path();
		group.appendTop(rpathy);
	}
	if (values.reflecty && values.reflectx){
		rpathxy = new Path();
		group.appendTop(rpathxy);
	}
	
	
	group.appendTop(mainpath);

}

function onMouseUp(event) {
    // smooth out the lines
	if(mainpath)
		mainpath.pointsToCurves(1, 10, 10.0, 10.0);
	if(values.reflectx)
		rpathx.pointsToCurves(1, 10, 10.0, 10.0);
	if(values.reflecty)
		rpathy.pointsToCurves(1, 10, 10.0, 10.0);
	if(values.reflecty && values.reflectx)
		rpathxy.pointsToCurves(1, 10, 10.0, 10.0);
}

function onMouseDrag(event) {
	// draws the main line were the mouse moves
	mainpath.lineTo(event.point);
	// reflection across the x axis
	if (values.reflectx){
		rpathx.lineTo(axis.x - event.point.x, event.point.y);
	}
	
	// reflection across the y axis
	if (values.reflecty){
		rpathy.lineTo(event.point.x, axis.y - event.point.y);
	}
	
	// reflection across both
	if (values.reflecty && values.reflectx){
		rpathxy.lineTo(axis - event.point);
	}

}
