Post Scriptum language

// Example 1
// This example shows basic language features

// This function calculates length in inches
function inch( x ) {    // The two keywords ('function' and 
                        // 'procedure') are interchangeable
	return 72*x;
}

// Construct the figure using built-in 
// PostScript operators
procedure wedge( angle ) {
	newpath();
	moveto( 0, 0 );
	translate( 1, 0 );
	rotate( angle / 2 );
	translate( 0, sin(angle/2));
	arc( 0, 0, sin(angle/2), -90, 90 );
	closepath();
}

gsave();
translate( inch(3.75), inch(7.25) );
scale( inch(1), inch(1) );
wedge( 30 );

// Post Scriptum accepts numbers without leading zero
setlinewidth(.02);       
stroke();
grestore();

gsave();
translate( inch(4.25), inch(4.25) );
scale( inch(1.75), inch(1.75) );
setlinewidth(.02);

n = 12;     // New global variable is created

// This is basic form of loop in Post Scriptum:
for (i=1 to n) {
	setrgbcolor( i/n, 1-i/n, 1-i/n );
	gsave();
	wedge( 360 / n );
	gsave();
	fill();
	grestore();
	setgray( 0 );
	stroke();
	grestore();
	rotate( 360 / n );
}

grestore();
showpage();