PROGRAM sines; {demonstrates plot of sine function} {Copyright 1984 by N.T.Carnevale. Permission granted for nonprofit use.} CONST GRAFSCREEN=2; {use only hires screen 2 with PCPI v.2 CP/M} BELL=7; TYPE {these are used to map the "real world" onto the display} realdata=RECORD x,y:real; {x&y world coordinates, that is, "real data"} END; screendata=RECORD x,y:integer; {x&y display coordinates} END; realscalefactors=RECORD mx,my,bx,by:real; {used to map world into display} END; {$I PCP.INC} {$I APLGR/G.INC} {$I APLGR/H.INC} VAR ans:char; frameloc,framesize:screendata; lowerleft,upperright:realdata; frame:realscalefactors; hue:hireshues; {$I PLOTTER.INC} {PLOTTER.INC contains the following: PROCEDURE setframe--sets up the coefficients ("magnifications" and "shifts") that are used to transform or map "real data" to the display. Parameters are: lowerleft,upperright:realdata--the opposite corners of a rectangular area that contains the range of "real data" to be plotted ("corners of the real world"). frameloc:screendata--left upper corner of area on the screen where the data is to go (where to put the picture). framesize:screendata--dimensions of the area on the screen where the data is to go (how big to make the picture). VAR frame:realscalefactors--this record contains the coefficients (calculated by setframe) that will be used by other procedures to map "real data" to the display. PROCEDURE plot--draws a point on the hires page using specified scale factors. Parameters are: point:realdata--x,y coordinates of the point in the "real world." frame:scalefactors--the coefficients used to map the point onto the display. PROCEDURE plotline--starting from present cursor location, draws a line to the point on the screen that corresponds to a specified endpoint in the "real world," using specified scale factors. Parameters are: endpoint:realdata--x,y coordinates of the end of the line in the "real world." frame:scalefactors--the coefficients used to map the point onto the display. } PROCEDURE genplot; {generate and plot one cycle of a sine wave} CONST PI=3.1415926; VAR i:integer; point:realdata; dx:real; BEGIN point.x:=0.0; dx:=0.02*pi; point.y:=sin(point.x); plot(point,frame); {plot the first point} FOR i:=1 TO 100 DO BEGIN point.x:=point.x+dx; {calculate the next point} point.y:=sin(point.x); plotline(point,frame); {and draw a line to it} END; END; BEGIN hirespatch; {install register-loading routines} writeln('Sine plotter'); write('First, screen ',GRAFSCREEN, ' will be cleared--press return to proceed'); readln(ans); hgrselect(GRAFSCREEN); {select screen to use} hiresgr(GRAFSCREEN,FULLSCREEN); { and clear it} textscreen(1); {restore text display} writeln; writeln('Press return to plot sine function.'); writeln('After the bell rings, press return again'); writeln(' to leave graphics mode.'); readln(ans); {specify limits of "real world" data} lowerleft.x:=0.0; lowerleft.y:=-1.0; upperright.x:=2*PI; upperright.y:=1.0; {set up size of display area} framesize.x:=HIHRES - 90; framesize.y:=HIVRES DIV 2; {put first frame at top left-hand corner of display} frameloc.x:=0; frameloc.y:=0; hiresgr(GRAFSCREEN,FULLSCREEN); {go back to graphics} hue:=BLACK1; {first "color" to use} REPEAT hue:=succ(hue); {advance to the next color} hisetcolor(hue); frameloc.y:=frameloc.y+10; { and shift the frame} frameloc.x:=frameloc.x+12; setframe(lowerleft,upperright,frameloc,framesize,frame); genplot; {plot one sine wave} UNTIL hue=WHITE2; writeln(chr(BELL)); {ring the bell} readln(ans); {wait until return key is pressed} textscreen(1); {restore text display before exit!} END. {end of PROGRAM sines}