PROCEDURE Diamond;

VAR
	
	stripeCount:		REAL;
	heightLeft:			REAL;
	heightRight:			REAL;
	stripeAngle:			REAL;
	pageWidth:			REAL;
	pageHeight:			REAL;
	scratchLayer:		HANDLE;
	cutLayer:				HANDLE;
	halfPageHeight:	REAL;
	horDiamDist:		REAL;
	varPi:					REAL;
	topHorLineCut:		REAL;
	midHorLineCut	:	REAL;
	lineCount:			INTEGER;
	counterVar:			INTEGER;
	alternatorVar:		INTEGER;

BEGIN

	{* define variables for script run as opposed to plugin run *}
	varPi:=3.141592653589793;
	alternatorVar:=0;
	stripeCount:=PSTRIPECOUNT;
	lineCount:=stripeCount + (stripeCount - 1);
	pageWidth:=PPAGEWIDTH;
	pageHeight:=PPAGEHEIGHT;
	heightLeft:=PHEIGHTLEFT;
	heightRight:=heightLeft;
	stripeAngle:=PSTRIPEANGLE;
	stripeAngle:= stripeAngle * (varPi / 180);
	horDiamDist:=Tan(stripeAngle) * (heightLeft - (pageHeight / 2));
	
	scratchLayer:=GetLayerByName('ScratchLayer');
	cutLayer:=GetLayerByName('CutLayer');
	
	IF (NOT(GetType(scratchLayer)=31)) THEN BEGIN	
		scratchLayer:=CreateLayer ('ScratchLayer', 1);
	END;
	
	IF (NOT(GetType(cutLayer)=31)) THEN BEGIN
		cutLayer:=CreateLayer('CutLayer', 1);
	END;

	{*define pen*}
	penPat(2);
	penFore(0,0,65535);
	
	{*draw sheet*}
	Layer('CutLayer');
	moveto(0,0);
	lineto(pageWidth,0);
	lineto(pageWidth,pageHeight);
	lineto(0,pageHeight);
	lineto(0,0);

	{* draw middle line *}
	Layer('ScratchLayer');
	penFore(65535,0,0);
	halfPageHeight:=pageHeight / 2;
	moveto(0,halfPageHeight);
	lineto(pageWidth,halfPageHeight);

	{* draw top and bottom lines *}
	IF (horDiamDist < (pageWidth / 2)) THEN BEGIN
		moveto(horDiamDist,heightLeft);
		lineto(pageWidth - horDiamDist,heightLeft);
		moveto(horDiamDist,(pageHeight - heightLeft));
		lineto(pageWidth - horDiamDist,(pageHeight - heightLeft));
	END;
	IF (horDiamDist > (pageWidth / 2)) THEN BEGIN
		Message ('Invalid value for angle.');
	END;

	{* draw diamond vertical lines *}
	IF (horDiamDist < (pageWidth / 2)) THEN BEGIN
		Layer('CutLayer');
		penFore(0,0,65535);
		topHorLineCut:=(pageWidth - ( 2 * horDiamDist)) / lineCount;
		midHorLineCut:=pageWidth / lineCount;
		FOR counterVar:=0 TO lineCount DO BEGIN
			moveto(counterVar * midHorLineCut, halfPageHeight);
			lineto(horDiamDist + (counterVar * topHorLineCut), heightLeft);
			IF ((alternatorVar=1) AND NOT(counterVar=lineCount) ) THEN BEGIN
				penFore(65535,65535,65535);
				moveto(horDiamDist + (counterVar * topHorLineCut), heightLeft);
				lineto(horDiamDist + ((counterVar + 1) * topHorLineCut), heightLeft);
				moveto(horDiamDist + (counterVar * topHorLineCut), pageHeight - heightLeft);
				lineto(horDiamDist + ((counterVar + 1) * topHorLineCut), pageHeight - heightLeft);
				penFore(0,0,65535);
			END;
			moveto(counterVar * midHorLineCut, halfPageHeight);
			lineto(horDiamDist + (counterVar * topHorLineCut), pageHeight - heightLeft);
			CASE alternatorVar OF
				0: alternatorVar:=1;
				1: alternatorVar:=0;
			END;
		END;
	END;

END;

RUN (Diamond);