//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

function onInit() {
	doc = Document.getActiveDocument();//this is to find the document size.
	docsize = doc.getSize(); // it works, but scriptographer has to be reloaded when a different sized document is used.
	reflectx = 1;
	reflecty = 1;
	useaxis = 0;
	var axisx;
	var axisy;

}

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

	if (values != null) {
		reflectx = values[0];
		reflecty = values[1];
		useaxis = values[2];
	}
	
}


function onMouseDown(event) {
	// set the axis to either the artboard (0) or mouse location (1)
	if (useaxis == 0){
		axisx = docsize.x;
		axisy = docsize.y;	
	} else if (useaxis == 1){
		axisx = (event.point.getX())*2;
		axisy = (event.point.getY())*2;
	}
	//initialize all nessicary lines
    mainpath = new Path();
	mainpath.moveTo(event.point);
	if (reflectx == 1){
		rpathx = new Path();
		rpathx.moveTo((axisx - event.point.getX()), event.point.getY());
	}
	if (reflecty == 1){
		rpathy = new Path();
		rpathy.moveTo(event.point.getX(), (axisy - event.point.getY()));
	}
	if (reflecty == 1 && reflectx == 1){
		rpathxy = new Path();
		rpathxy.moveTo((axisx - event.point.getX()), (axisy - event.point.getY()));
	}

}

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

function onMouseDrag(event) {
    var gp = new Group();
	var point = event.point;
	// draws the main line were the mouse moves
	mainpath.lineTo(event.point);
	gp.appendChild(mainpath);
	// refelction across the x axis
	if (reflectx == 1){
		rpathx.lineTo ((axisx - event.point.getX()), event.point.getY());
		gp.appendChild(rpathx);
	}
	
	// refelction across the y axis
	if (reflecty == 1){
		rpathy.lineTo (event.point.getX(), (axisy - event.point.getY()));
		gp.appendChild(rpathy);
	}
	
	// refelction across both
	if (reflecty == 1 && reflectx == 1){
		rpathxy.lineTo ((axisx - event.point.getX()), (axisy - event.point.getY()));
		gp.appendChild(rpathxy);
	}

}
