/*** draw a simple line ***/
//winfig.setCenter(1200, 1200);

// set the pen
var colors = new Object();

colors.penColor = new Object();
colors.penColor.index = 1;

colors.fillColor = new Object();
colors.fillColor.index = 31;

colors.fillShade = -1;

// fillShade and fillPattern are exclusive. Only one of them will be used
colors.fillShade = 22;
//colors.fillPattern = 4;

var pen = new Object();
pen.width = 10;
pen.lineStyle = "dashed";
pen.dashValue = 6.5;
pen.capStyle = "round";
pen.joinStyle = "bevel";
pen.colors = colors;
winfig.setPen(pen);

// draw a closed line with 3 points
var line = new Object();
line.depth = 51;
line.comment = "a comment";
line.points = new Array();

line.closed = true;
line.points[0] = new Object();
line.points[0].x = 100;
line.points[0].y = 200;

line.points[1] = new Object();
line.points[1].x = 5000;
line.points[1].y = 1500;

line.points[2] = new Object();
line.points[2].x = 2000;
line.points[2].y = 2500;

winfig.drawPolyline(line);

/*** paint 10 horizontal lines and rotate the pen color in the interverval 0..31 ***/
/*** glue them into a compound object */
/*** reuse the pen ***/

winfig.beginCompound();

var points = new Array();
line.points = new Array();

pen.width = 1;
pen.lineStyle = "solid";
winfig.setPen(pen);

for (var i=0; i < 10; i++)
{
	var line = new Object();

	var point1 = new Object();
	point1.x = 1000;
	point1.y = 2000+(i*(1200/80));
	points[0] = point1;

	var point2 = new Object();
	point2.x = 6000
	point2.y = 2000+(i*(1200/80));
	points[1] = point2;

	pen.colors.penColor.index = i%32;

	// this is costly. If the pen wouldn't change, we didn't set it here.
	// We would use winfig.setPen(pen) instead only once before the loop.
	line.pen = pen;

	line.points = points;

	winfig.drawPolyline(line);
}

winfig.finishCompound();
/**
This script demonstrates how to create the different types of graphical objects.

Please be aware that the coordinates refer to a coordinate systems as it is common
in computer graphics. That is, the origin is in the upper left corner and the y direction is downwards.
The scale is 1200dpi per inch.

For an example that uses a cartesian coordinate sytem with metric scale please see drawCurve.js
*/

// draw a spline with 3 points
pen.width = 3;
pen.colors.fillShade = -1;
pen.colors.fillPattern = -1;
winfig.setPen(pen);

var spline = new Object();
spline.points = new Array();

spline.points[0] = new Object();
spline.points[0].x = 200;
spline.points[0].y = 8000;

spline.points[1] = new Object();
spline.points[1].x = 2100;
spline.points[1].y = 6600;

spline.points[2] = new Object();
spline.points[2].x = 3100;
spline.points[2].y = 8600;

var backArrow = new Object();
backArrow.type = 1;

// thickness, width, height are optional values, which will be derived from line width if not set here
backArrow.thickness = pen.width;
backArrow.width = 14*pen.width;
backArrow.height = 18*pen.width;

spline.backwardArrow = backArrow;

var forwArrow = new Object();
forwArrow.type = 4;

// thickness, width, height are optional values, which will be derived from line width if not set here
forwArrow.thickness = pen.width;
forwArrow.width = 4*pen.width;
forwArrow.height = 8*pen.width;

spline.forwardArrow = forwArrow;

winfig.drawSpline(spline);

// draw a closed spline with 3 points
pen.width = 3;
winfig.setPen(pen);

var spline = new Object();
spline.points = new Array();

spline.points[0] = new Object();
spline.points[0].x = 320;
spline.points[0].y = 8600;

spline.points[1] = new Object();
spline.points[1].x = 2200;
spline.points[1].y = 7400;

spline.points[2] = new Object();
spline.points[2].x = 3000;
spline.points[2].y = 9400;

spline.type = "interpolated";
spline.closed = true;

winfig.drawSpline(spline);

/*** draw a rectangle ***/
/** specify upper left and lower right corner */
var rectangle = new Object();
pen.width = 10;
pen.lineStyle = "dashed";

// fillShade and fillPattern are exclusive. Only one of them will be used. Set the other to "undefined".
pen.colors.fillShade = undefined;
pen.colors.fillPattern = 4;
rectangle.pen = pen;

rectangle.cornerType = "round";
rectangle.cornerRadius = 30;

rectangle.p1 = new Object();
rectangle.p1.x = 2000;
rectangle.p1.y = 2500;

rectangle.p2 = new Object();
rectangle.p2.x = 6000;
rectangle.p2.y = 4000;
winfig.drawRectangle(rectangle);

/*** draw a picture ***/
/* The picture is positioned by setting the upper left corner.
   The picture size can be set in two ways:
   1. by providing the lower right corner
   2. by using the original image size from the file and optionally setting a scale value.
*/

// draw a regular polygon with 8 sides
var regpoly = new Object();
regpoly.comment = "a regular polygon";

pen.width = 1;
pen.lineStyle = "soild";
pen.colors.fillShade = -1;
pen.colors.fillPattern = -1;
regpoly.pen = pen;

var center = new Object();
center.x = 4000;
center.y = 7000;
regpoly.center = center;

regpoly.radius = 1000;
regpoly.angle = 10;
regpoly.sides = 8;

winfig.drawRegularPolygon(regpoly);

// draw a circle
var circle = new Object();

var center = new Object();
center.x = 5000;
center.y = 8000;
circle.center = center;
circle.radius = 1000;

winfig.drawCircle(circle);

// draw an ellipse
var ellipse = new Object();

var center = new Object();
center.x = 5000;
center.y = 8000;
ellipse.center = center;
ellipse.radiusx = 2000;
ellipse.radiusy = 1000;
ellipse.angle = 45;

winfig.drawEllipse(ellipse);

// draw an arc
var arc = new Object();

arc.p1 = new Object();
arc.p1.x = 8677;
arc.p1.y = 5325;

arc.p2 = new Object();
arc.p2.x = 7395;
arc.p2.y = 3255;

arc.p3 = new Object();
arc.p3.x = 9660;
arc.p3.y = 2865;

arc.type = "pie";

// draw a text
var text = new Object();

text.base = new Object();
text.base.x = 1600;
text.base.y = 6000;
text.font = "Courier Bold";
text.fontSize = 18;
text.angle = 10;
text.alignment = "center";
text.text = "this is not a formula: $a_b$";
text.rigid = true;
text.latex = true;

winfig.drawText(text);

/* the available fonts
Times Roman
Times Italic
Times Bold
Times Bold Italic
AvantGarde Book
AvantGarde Book Oblique
AvantGarde Demi
AvantGarde Demi
AvantGarde Demi Oblique
AvantGarde Demi Oblique
Bookman Light
Bookman Light Italic
Bookman Demi
Bookman Demi Italic
Courier
Courier Oblique
Courier Bold
Courier Bold Oblique
Helvetica
Helvetica Oblique
Helvetica Bold
Helvetica Bold Oblique
Helvetica Narrow
Helvetica Narrow Oblique
Helvetica Narrow Bold
Helvetica Narrow Bold Oblique
New Century Schoolbook Roman
New Century Schoolbook Italic
New Century Schoolbook Bold
New Century Schoolbook Bold Italic
Palatino Roman
Palatino Italic
Palatino Bold
Palatino Bold Italic
Symbol
Zapf Chancery Medium Italic
Zapf Dingbats
*/

// argument can be relative or absolute path
// windows path separators must be escaped i.e. "C:\\temp\\foo.fig"
//winfig.save("samples.fig");

var params = new Object();

var result = winfig.test(41);
winfig.test(result);

var testobj = new Object();
var testobj2 = winfig.test2(testobj);
winfig.test3(testobj2);
