home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Share Gallery 1
/
share_gal_1.zip
/
share_gal_1
/
GA
/
GA028.ZIP
/
HOPALONG.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-08-27
|
6KB
|
208 lines
PROGRAM Hopalong;
(****************************************************)
(* COPYRIGHT (C) 1986 by Kevin McCarty. *)
(* All commercial use prohibited. *)
(* Permission is granted for copying, distribution, *)
(* adaptation, and incorporation into other works, *)
(* but for personal or educational use only, *)
(* and this notice is to be preserved. *)
(****************************************************)
(*
Adapted for Computer Recreations in
September 1986 Scientific American
Based on ideas of Barry Martin of Aston University
in Birmingham, England
Version 1.1, August 27 1986
*)
LABEL Resume;
Var
x, y : real;
xmin, xmax, xspan, xscale, xs,
ymin, ymax, yspan, yscale, ys : real;
n, nc, color : integer;
ch : char;
AxisColor : integer;
{$I plot.inc}
Function Scale(x : real) : real;
{ returns largest power of 10 < x/4 }
VAR s : real;
BEGIN
s := 1.0;
WHILE s < x DO s := 10.0 * s;
WHILE s >= 0.5*x DO s := 0.1 * s;
Scale := s
END; (* Scale *)
Procedure Set_Scale;
BEGIN
Writeln;
Writeln('Specify Plot Window--');
Write('(Xmin - Xmax) (',xmin:10:3,' - ',xmax:10:3,'): ');
Readln(xmin, xmax);
Write('(Ymin - Ymax) (',ymin:10:3,' - ',ymax:10:3,'): ');
Readln(ymin, ymax);
xspan := xmax - xmin;
yspan := ymax - ymin;
IF (xspan = 0.0) OR (yspan = 0.0) THEN
BEGIN
IF (xspan = 0.0) THEN Writeln('Xmin = Xmax !');
IF (yspan = 0.0) THEN Writeln('Ymin = Ymax !');
Writeln('Can''t handle that!');
Halt;
END;
xscale := Scale(Abs(xspan));
yscale := Scale(Abs(yspan));
Writeln('X span = ',xspan:10:3,', scale = ',xscale:10:4);
Writeln('Y span = ',yspan:10:3,', scale = ',yscale:10:4);
END; (* Set_Scale *)
Procedure Draw_Axes;
VAR
i, j, i1, i2 : integer;
Procedure Xtick(at_x, at_y, size : integer);
{vertical tick}
BEGIN
FOR j := -size TO size DO
Plot (at_x, at_y + j, AxisColor)
END; (* Xtick *)
Procedure Ytick(at_x, at_y, size : integer);
{horizontal tick}
BEGIN
FOR j := -size TO size DO
Plot (at_x + j, at_y, AxisColor)
END; (* Ytick *)
BEGIN
IF (xmin <= 0.0) AND (xmax >= 0.0) THEN
BEGIN { draw vertical axis ticks }
i1 := Trunc (ymin/yscale);
i2 := Trunc (ymax/yscale);
FOR i := i1 TO i2 DO
BEGIN
Ytick (Trunc (-maxXdot * xmin / xspan),
Trunc (maxYdot * (ymax-i*yscale) / yspan), 2);
END;
END;
IF (ymin <= 0.0) AND (ymax >= 0.0) THEN
BEGIN { draw horizontal axis ticks }
i1 := Trunc (xmin/xscale);
i2 := Trunc (xmax/xscale);
FOR i := i1 TO i2 DO
BEGIN
Xtick (Trunc (maxXdot * (i*xscale-xmin) / xspan),
Trunc (maxYdot * ymax / yspan), 2);
END;
END;
END; (* Draw_Axes *)
Procedure Draw_Grid;
{ draw a grid of dots showing the scale }
VAR
i, j, xj, yi, xlo, xhi, ylo, yhi : integer;
BEGIN
{ determine x and y scales }
xlo := Trunc (xmin / xscale);
xhi := Trunc (xmax / xscale);
ylo := Trunc (ymin / yscale);
yhi := Trunc (ymax / yscale);
FOR i := ylo TO yhi DO
BEGIN
yi := Trunc ( maxYdot * (ymax - i * yscale) / yspan);
FOR j := xlo TO xhi DO
BEGIN
xj := Trunc (maxXdot * (j * xscale - xmin) / xspan);
Plot (xj, yi, AxisColor);
END;
END;
Draw_Axes;
END; (* Draw_Grid *)
{$I hop.pas}
BEGIN (* MAIN *)
ClrScr;
Writeln(' *** WALLPAPER FOR THE MIND ***');
Writeln(' (see Sept. 1986 Scientific American)');
Writeln;
Writeln;
Writeln(' while plotting---');
Writeln(' G: Draw grid dots');
Writeln(' Blank: Cycle Colors');
Writeln(' *: Graphics Screen Dump');
Writeln(' (Make sure printer is ONLINE!)');
Writeln(' <enter>: Return to text mode to change parameters');
Writeln(' any other key: Exit program');
Writeln;
Init_Graphics;
IF maxcolor > 1
THEN AxisColor := Yellow
ELSE AxisColor := 1;
Set_Defaults;
REPEAT { input / plot cycle }
Set_Coefficients;
Set_Scale;
Initialize;
Graphics_Mode; { entering graphics mode }
n := 0; { iteration counter }
nc := 0; { color index }
Resume:
REPEAT
IF (n = 0) THEN
BEGIN { cycle color every so often }
nc := (nc mod maxcolor) + 1;
IF maxcolor = 15 THEN
color := ColorList [nc]
ELSE
color := nc;
END;
n := (n + 1) mod boredom;
Next_Iteration;
xs := (x - xmin) / xspan;
ys := (ymax - y) / yspan;
IF (Abs(xs) < 1.0) AND (Abs(ys) < 1.0) THEN
Plot (Trunc (maxXdot * xs), Trunc (maxYdot * ys), color);
UNTIL KeyPressed;
Read(kbd,ch);
CASE UpCase(ch) OF
'*': BEGIN Screen_Dump; Goto Resume END;
'G': BEGIN Draw_Grid; Goto Resume END;
' ': BEGIN Cycle_Palette; Goto Resume END;
END; (* Case *)
Text_Mode;
IF (ch <> ^M) THEN
BEGIN
Write('Are you bored with this stuff already (Y/N)? ');
Read(kbd,ch);
Writeln(ch);
END;
UNTIL UpCase(ch) = 'Y';
end.