{Listing 1: Pascal code demonstrating how to convert an integer}
{array into a Macintosh graphics structure, which is then pasted}
{onto the clipboard and written to a 'PICT' type disk file.}
{'nPoints' is the number of elements in our wave, which is passed}
{in the integer array 'theWave', of type 'waveType'.}
procedure WaveToPICT (nPoints: integer; theWave: waveType);

  var
   sysFlag: boolean;
   j, vRefNum, refNum: integer;
   longZero, longCount, count, scrapResult: longint;
   drawRect, picFrame: rect;
   fName, prompt, origName, nullStr: str255;
   myPic: picHandle;
   myPoly: polyHandle;
   scrapType: ResType;
   OSResult: OSErr;
   creator, fileType: OSType;
   reply: SFReply;
   where: point;
   dlgHook: ProcPtr;

 begin
{allocate handle for picture, define big picture frame}
  setRect(picFrame, 0, -5000, 10000, 5000);
  myPic := OpenPicture(picFrame);	{start recording QuickDraw calls}

{now draw the polygon - it will be recorded in myPic}
  myPoly := OpenPoly;	{allocate handle, start recording poly }
					{coords}
{y-values must be negated because positive y-axis points down }
{in QuickDraw}
  MoveTo(1, -theWave[1]);	{move pen to first coordinate}
  for j := 2 to nPoints do	{record the rest}
   LineTo(j, -theWave[j]);

{draw the baseline at zero volts}
  LineTo(nPoints, 0);
  LineTo(0, 0);
  ClosePoly;		       {stop recording poly coords}
  FramePoly(myPoly);    {'draw' the poly in the picture}
  KillPoly(myPoly);	       {dispose of the poly - it's stored in myPic}

{now draw calibration marks as a 2nd poly}
  myPoly := OpenPoly;		{create a new poly}
  MoveTo(npoints + 100, 0);	{start 100 points to the right of wave}
  LineTo(npoints + 100 + 200, 0);	{make horiz limb 200 points long}
  LineTo(npoints + 100 + 200, -150);{make vert limb 150 points high}
  ClosePoly;
  FramePoly(myPoly);
  KillPoly(myPoly);

  ClosePicture;			{stop recording picture}

{*** put the picture on the Clipboard ***}
  scrapResult := ZeroScrap;	{clear/initialize the Clipboard}
  scrapType := 'PICT';		{we're putting a picture there}
  count := myPic^^.picSize;	{size of picture in bytes}
  if odd(count) then
   count := count + 1;		{must be even}
{place the picture on the clipboard - if scrapResult=0 then no error}
  scrapResult := PutScrap(count, scrapType, ptr(myPic^));

{alert Multifinder to update other scraps}
  sysFlag := SystemEdit(3);	{3 is a 'Copy' command}

{*** write the picture to a disk file ***}
{prompt for a filename}
  where.h := 100;
  where.v := 100;
  dlgHook := nil;
  origName := 'Wave.PICT';
  prompt := 'Save graphics to:';
  SFPutFile(where, prompt, origName, dlgHook, reply);
{create the file}
  creator := '????';
  fileType := 'PICT';
  OSResult := Create(reply.fName, reply.vRefNum, creator, fileType);
{open the file}
  OSResult := FSOpen(reply.fName, reply.vRefNum, refNum);
{write 512 byte header first}
  longZero := 0;
  longCount := 4;
  for j := 1 to 512 div 4 do
   OSResult := FSWrite(refNum, longCount, @longZero);
{write picture to file}
  count := myPic^^.picSize;
  OSResult := FSWrite(refNum, count, ptr(myPic^));
{close file}
  OSResult := FSClose(refNum);
{update volume info}
  nullStr := '';
  OSResult := FlushVol(@nullStr, reply.vRefNum);

  KillPicture(myPic);	{we're done, release the picture handle}

 end;	
                                                                        