home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
BEEHIVE
/
UTILITYS
/
PUDD.ARC
/
PUDD-07.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-08-11
|
5KB
|
158 lines
{****************************************************************************}
{* InBounds will return true if the point specified (x,y) is on the screen *}
{****************************************************************************}
function InBounds(x,y:integer):boolean;
begin
if (x >= 0) and (x < 640) and (y >= 0) and (y < 240) then
InBounds := true
else
InBounds := false;
end;
{****************************************************************************}
{* Angle will return the angle in radians between the line from point 1 to *}
{* point 2 and the horizontal axis. In correspondence with normal geometry }
{* the angle is measured counterclock-wise. *}
{****************************************************************************}
function Angle(x1,y1,x2,y2 :integer):real;
var theta :real;
begin
charcolor(1);
if (xPoz-x1 = 0) then {....vertical line }
if (yPoz > y1) then
theta := 1.5707963 {.......which points up }
else
theta := -1.5707936 {.......which points down }
else
theta := arctan((2*(yPoz-y1))/(xPoz-x1));
if (xPoz < x1) then {....angle is greater than 90 }
begin
begin
theta := 3.1415927 + theta; {...in The2nd or 3rd quardents }
end
end;
if (theta < 0) then
theta := theta + 6.2831853;
angle := theta;
end;
{****************************************************************************}
{* vectorPoint will draw a single point which is 'length' away from point **}
{* x,y at angle 'angle'. **}
{****************************************************************************}
procedure vectorPoint(x,y:integer;angle,length:real);
var Xpoint,Ypoint :integer;
begin
Xpoint := x + round(2 * length * cos(angle));
Ypoint := y + round(length * sin(angle));
if InBounds(Xpoint,Ypoint) then
begin
Moveto(Xpoint,Ypoint);
Drawto(Xpoint,Ypoint);
end;
end;
{****************************************************************************}
{* Arc will draw some or all of a circle **}
{****************************************************************************}
procedure arc(centerX,centerY:integer);
const MaxReal = 99e30;
Pi = 3.141592654;
var X,Y :integer;
The1stAngle, The2ndAngle, radius :real;
deltaX,deltaY :real;
step :real;
begin
The1stAngle := MaxReal; {...............initalize to some absurd number }
The2ndAngle := MaxReal;
repeat
repeat
read(kbd,response);
response := UpCase(response);
case response of
'S':SetSpeed(speed);
'5':SetSpeed(speed);
'1'..'9':begin
reInitXhair(size,xpoz,ypoz);
MoveCross(size,speed,response,xPoz,yPoz);
end;
end; {.....case }
until pos(response,'S123456789') = 0; {...any key but a curser key }
if The1stAngle = MaxReal then {......1st angle still not selected }
begin
The1stAngle := angle(centerX,centerY,xPoz,yPoz);
deltaX := centerX - Xpoz;
deltaY := 2 * (centerY - Ypoz);
radius := sqrt(deltaX*deltaX + deltaY*deltaY)/2;
end
else
The2ndAngle := angle(centerX,centerY,xPoz,yPoz); {..select 2nd angle }
until The2ndAngle <> MaxReal;
if radius <> 0 then {..this avoids division by 0 for a radius of r=0 }
step := 1/(2 * radius) {...........minimum step is a chord of one pixel }
else
step := 2*Pi;
offXhair(size,xPoz,yPoz);
if (The1stAngle = The2ndAngle) then
begin
AlphaMode;
clrscr;
gotoXY(20,19);
write('Do you want ..........');
gotoXY(22,21);
write('1) a full circle ');
gotoXY(25,22);
write('or');
gotoXY(22,23);
write('2) no circle');
repeat
read(kbd,response);
until (response = '1') or (response = '2');
initgraph;
if response = '1' then
begin
The1stAngle := The1stAngle - 2 * Pi;
repeat
vectorPoint(centerx,centery,The1stAngle,radius);
The1stAngle := The1stAngle + step;
until The1stAngle >= The2ndAngle
end;
end
else
begin
AlphaMode;
clrscr;
gotoXY(20,19);
write('From the first point given on the arc should I draw...');
gotoXY(22,21);
write('1) Counter Clockwise');
gotoXY(25,22);
write('or');
gotoXY(22,23);
write('2) Clockwise');
repeat
read(kbd,response);
until (response = '1') or (response = '2');
initgraph;
if response = '1' then
begin
if The1stAngle > The2ndAngle then {..set the limit of the loop }
The2ndAngle := The2ndAngle + (2 * Pi);
repeat
vectorPoint(centerx,centery,The1stAngle,radius);
The1stAngle := The1stAngle + step;
until The1stAngle >= The2ndAngle; {..until we reach limit of loop }
end
else
begin
if The1stAngle < The2ndAngle then
The2ndAngle := The2ndAngle - 2 * Pi;
repeat
vectorPoint(centerx,centery,The1stAngle,radius);
The1stAngle := The1stAngle - step;
until The1stAngle <= The2ndAngle;
end;
end;
initXhair(size,xPoz,yPoz);
end;