{ 9/19/95 Here is a pascal program curve.p, which has about the same effect as our curve.c. I didn't write this; it was written by a student in the class a few years ago. Some of the code seems to be curve.c, modified to pascal. It appears to be well written. It doesn't have the features of login name and date ... i don't know how to do those in pascal. Some modification may be required before it will work on Turbo Pascal, but that should be possible. } program curve; const PI = 3.1415927; STEP = 400; { Number of divisions of the time interval.} START_T = 0.0; STOP_T = 2*PI; LEFT = -1.10; { value of u at left of window } RIGHT = 6.50; BOTTOM = -1.10; { value of v at bottom of window } TOP = 1.10; SIZE = 6.4; H_OFFSET = 1.2; V_OFFSET = 2; type inches = real; time = real; window_units = real; paper_point = array[1..2] of inches; window_point = array[1..2] of window_units; var tcount : integer; t : time; r : window_point; procedure line_to(q:paper_point); begin writeln('l ',q[1]:8:3,' ',q[2]:8:3); end; procedure move_to(q:paper_point); begin writeln('m ',q[1]:8:3,' ',q[2]:8:3); end; function window_to_paper(p: window_point) : paper_point; var q : paper_point; begin p[1] := p[1] - LEFT; p[2] := p[2] - BOTTOM; p[1] := p[1]/(RIGHT-LEFT); p[2] := p[2]/(TOP-BOTTOM); q[1] := H_OFFSET + (SIZE * p[1]); q[2] := 8.5-V_OFFSET-SIZE + (SIZE * p[2]); window_to_paper := q; end; procedure window_line_to(p:window_point); var q: paper_point; begin q := window_to_paper(p); line_to(q); end; procedure window_move_to(p:window_point); var q: paper_point; begin q := window_to_paper(p); move_to(q); end; procedure make_window; begin writeln('w 0.0 0.0 8.5 8.5'); end; procedure width(i:integer); begin writeln('W ',i); end; procedure draw_frame; var p, q, r, s : paper_point; begin width(20); p[1] := H_OFFSET; q[1] := H_OFFSET; q[2] := 8.5 - V_OFFSET; r[2] := 8.5 - V_OFFSET; r[1] := H_OFFSET + SIZE; s[1] := H_OFFSET + SIZE; s[2] := 8.5 - V_OFFSET - SIZE; p[2] := 8.5 - V_OFFSET - SIZE; move_to(p); line_to(q); line_to(r); line_to(s); line_to(p); end; procedure position_label; begin writeln('%Moving to the label position'); writeln('m 1.1 -0.7'); end; procedure position_signature; begin writeln('%Moving to the signature position'); writeln('m 5.5 -1.5'); end; procedure label_x_axis; var p:paper_point; begin p[1] := H_OFFSET - 0.2; p[2] := 8.5 - V_OFFSET - SIZE - 0.22; move_to(p); writeln('x',LEFT:4:2); p[1] := p[1] + SIZE + 0.1; move_to(p); writeln('x',RIGHT:4:2); end; procedure label_y_axis; var p:paper_point; begin p[1] := H_OFFSET - 0.55; p[2] := 8.5 - V_OFFSET - 0.07; move_to(p); writeln('x',TOP:4:2); p[2] := p[2] - SIZE + 0.1; move_to(p); writeln('x',BOTTOM:4:2); end; procedure draw_axes; var p0,p1:paper_point; begin writeln('%Here we draw the coordinate axes, if they fit.'); width(2); if ( (LEFT < 0.0) and (RIGHT > 0.0)) then begin p0[1] := H_OFFSET + SIZE * (LEFT/(LEFT - RIGHT)); p1[1] := H_OFFSET + SIZE * (LEFT/(LEFT - RIGHT)); p0[2] := 8.5 - V_OFFSET; p1[2] := 8.5 - V_OFFSET - SIZE; move_to(p0); line_to(p1); end; if ( (BOTTOM < 0.0) and (TOP > 0.0)) then begin p1[2] := 8.5 - V_OFFSET - SIZE*(1.0-(BOTTOM/(BOTTOM - TOP))); p0[2] := 8.5 - V_OFFSET - SIZE*(1.0-(BOTTOM/(BOTTOM - TOP))); p0[1] := H_OFFSET; p1[1] := H_OFFSET + SIZE; move_to(p0); line_to(p1); end; writeln('%This ends the laying down of the axes.'); end; begin { program } make_window; draw_frame; draw_axes; label_x_axis; label_y_axis; position_label; writeln('TTwo periods of the function sin\(2x\)'); position_signature; writeln('twtaylor'); width(3); for tcount:= 0 to STEP do begin t:= START_T + (tcount/STEP)*(STOP_T - START_T); r[1]:= t; r[2]:= sin(2*t); if tcount=0 then window_move_to(r) else window_line_to(r); end; end. { program } { Not useful here, but save for future reference: function cosh(x:real) : real; begin cosh:=(exp(x)+exp(-1*x))/2; end; function sinh(x:real) : real; begin sinh:=(exp(x)-exp(-1*x))/2; end; function midpoint(p,q:point) : point; var r : point; begin r[1]:= (p[1]+q[1])/2; r[2]:= (p[2]+q[2])/2; midpoint := r; end; }