Large 2D Graphics Library
#1
This is a 2D graphics library. The routines in this library are mainly (but not entirely) based on algorithms found in the book Computer Graphics (Teach Yourself) by John Landsdown (Amazingly a newer version (1997) than mine (1987) is available at Amazon UK).

There are 2 common types of graphics used with computers - tile graphics and coordinate graphics. This library deals entirely with the latter. The library is accompanied by a demo. The library consists of a BI file, a BM file and a DAT data file. The demo consists of a BAS file and it's own dedicated DAT data file.

This library uses the following conventions. The coordinate pairs are stored in a 2 dimensional array of the form CoordinateArray#(0 TO N, QX% TO QY%). CoordinateArray#(0,QX%) and CoordinateArray#(0, QY%) are used to hold the coordinates of the centre of the graphics object. The following three types are used extensively throughout this library. The type Box2D is used both for storing the coordinates of an imaginary box surrounding each graphics object and also for the storage of the coordinates for graphics windows. AView2D is used to store the device coordinates for viewports. Type Vision combines both a graphics window and a viewport as well as additional information needed for the mapping of the world coordinates (stored in the arrays) to device coordinates (so you can display them).

If the above is all Ancient Greek to you don't panic, Just compile and run the demo to get a flavour of what's here.

Before I post the library in the next post, here is the original BI file (DO NOT USE- Just read) as documentation of the public routines in the library -

Code: (Select All)
REM ******************************************************
REM * Filespec  :  g2.bm g2.bi g2.dat                    *
REM *          :  g2demo.bas g2demo.dat                  *
REM * Date      :  September 15 1998                     *
REM * Time      :  12:25                                 *
REM * Revision  :  1.00B                                 *
REM * Update    :                                        *
REM ******************************************************
REM * Released to the Public Domain                      *
REM ******************************************************

'$DYNAMIC

TYPE Box2D
    Left  AS DOUBLE
    Right  AS DOUBLE
    Top    AS DOUBLE
    Bottom AS DOUBLE
END TYPE

TYPE AView2D
    Left  AS INTEGER
    Right  AS INTEGER
    Top    AS INTEGER
    Bottom AS INTEGER
END TYPE

TYPE Vision
    MyWindow AS Box2D
    MyView  AS AView2D
    XMove    AS DOUBLE
    YMove    AS DOUBLE
    XBound  AS DOUBLE
    YBound  AS DOUBLE
    XFactor  AS DOUBLE
    YFactor  AS DOUBLE
END TYPE

CONST FALSE% = 0
CONST TRUE% = NOT FALSE%
CONST QX% = 1, QY% = 2
CONST PI# = 3.141592653589793#
CONST PIDividedBy2# = 1.57079632679489661923    'PI / 2
CONST PITimes2# = 6.28318530717959              'PI * 2
CONST PITimes3# = 9.42477796076938              'PI * 3
CONST XScale% = 1, YScale% = 2, Scale% = 3
CONST OneSeventeenth# = .05882352941176471#

REM ******************************************************************
REM * The following routines are for the general management of the   *
REM * arrays used to hold the coordinates that we are working with.  *
REM * All of the following routines return TRUE% if they are         *
REM * successful and FALSE% if an error condition was detected.  The *
REM * output arrays are automatically resized to exactly the size    *
REM * necessary to hold the output data.                             *
REM ******************************************************************

DECLARE FUNCTION CopyShape2D%(InShape#(), OutShape#())
REM ******************************************************************
REM * Copies InShape#() to OutShape#().                              *
REM ******************************************************************

DECLARE FUNCTION AppendShape2D%(This#(), OntoThis#())
REM ******************************************************************
REM * Appends the contents of This#() onto the end of OntoThis#().  *
REM ******************************************************************

DECLARE FUNCTION MakePolygon%(This#(), OntoThis#())
REM ******************************************************************
REM * Identical to the preceding routine with additional action of   *
REM * copying the first coordinate pair of OntoThis#() to its end    *
REM * after appending This#().                                       *
REM ******************************************************************

DECLARE FUNCTION InsertShape2D%(This#(), IntoThis#(), AfterThisPoint%)
REM ******************************************************************
REM * Inserts the contents of This#() into IntoThis#() after the     *
REM * coordinate pair specified by AfterThis%.                       *
REM ******************************************************************

DECLARE FUNCTION DeletePoint2D%(This#(), PointNumber%)
REM ******************************************************************
REM * Deletes the coordinate pair specified by PointNumber%, From    *
REM * This#().                                                       *
REM ******************************************************************

DECLARE FUNCTION OuterLimits2D%(This#(), MyBounds AS Box2D)
REM ******************************************************************
REM * This routine determines the values for an imaginary box        *
REM * surrounding the graphics object held in This#().  These values *
REM * are placed in MyBounds.  The exact centre of the object is     *
REM * also determined by this routine and the coordinate pair of     *
REM * this centre are placed in This#(0, QX%) and This#(0, QY%).     *
REM ******************************************************************

REM ******************************************************************
REM * The following routines manipulate the coordinate pairs held in *
REM * the arrays in the manner specified in the individual           *
REM * descriptions.  Once all calculations are complete the new      *
REM * exact centre and boundary values are determined by an          *
REM * automatic call to OuterLimits2D%.  All of the following        *
REM * routines return TRUE% to indicate successful completion or     *
REM * FALSE% if an error condition was detected.                     *
REM ******************************************************************

DECLARE FUNCTION Translate2D%(This#(), MyBounds AS Box2D, ByX#, ByY#)
REM ******************************************************************
REM * Relative movement.  Moves the whole object by the amounts      *
REM * specified in ByX# and ByY#.                                    *
REM ******************************************************************

DECLARE FUNCTION MoveTo2D%(This#(), MyBounds AS Box2D, ToX#, ToY#)
REM ******************************************************************
REM * Absolute movement.  Moves the whole object so that the centre  *
REM * of the object is positioned at ToX#, ToY#.                     *
REM ******************************************************************

DECLARE FUNCTION InflateX2D%(This#(), MyBounds AS Box2D, By#)
REM ******************************************************************
REM * Make the object wider by the amount specified in By#, without  *
REM * disturbing the position of it's centre.                        *
REM ******************************************************************

DECLARE FUNCTION InflateY2D%(This#(), MyBounds AS Box2D, By#)
REM ******************************************************************
REM * Make the object taller by the amount specified in By#, without *
REM * disturbing the position of it's centre.                        *
REM ******************************************************************

DECLARE FUNCTION Inflate2D%(This#(), MyBounds AS Box2D, By#)
REM ******************************************************************
REM * Make the object larger in both dimensions by the amount        *
REM * specified in By#, without disturbing the position of it's      *
REM * centre.                                                        *
REM ******************************************************************

DECLARE FUNCTION ScaleX2D%(This#(), MyBounds AS Box2D, By#)
REM ******************************************************************
REM * Make the object wider by the amount specified in By#.          *
REM ******************************************************************

DECLARE FUNCTION ScaleY2D%(This#(), MyBounds AS Box2D, By#)
REM ******************************************************************
REM * Make the object taller by the amount specified in By#.         *
REM ******************************************************************

DECLARE FUNCTION ScaleXY2D%(This#(), MyBounds AS Box2D, ByX#, ByY#)
REM ******************************************************************
REM * Make the object taller (ByY#) and wider (ByX~) by the amount   *
REM * specified.                                                     *
REM ******************************************************************

DECLARE FUNCTION Scale2D%(This#(), MyBounds AS Box2D, By#)
REM ******************************************************************
REM * Make the object larger by the amount specified in By#.         *
REM ******************************************************************

DECLARE FUNCTION ShearX2D%(This#(), MyBounds AS Box2D, By#)
REM ******************************************************************
REM * Shearing in the X plane distorts the figure in a manner that   *
REM * relates the amount specified in By# and Y coordinate for each  *
REM * point.                                                         *
REM ******************************************************************

DECLARE FUNCTION ShearY2D%(This#(), MyBounds AS Box2D, By#)
REM ******************************************************************
REM * Shearing in the Y plane distorts the figure in a manner that   *
REM * relates the amount specified in By# and X coordinate for each  *
REM * point.                                                         *
REM ******************************************************************

DECLARE FUNCTION Shear2D%(This#(), MyBounds AS Box2D, ByX#, ByY#)
REM ******************************************************************
REM * This merely combines shearing in both planes into a single     *
REM * procedure.                                                     *
REM ******************************************************************

DECLARE FUNCTION Rotation2D%(This#(), MyBounds AS Box2D, Angle#)
REM ******************************************************************
REM * Rotates the figure about the origin (that is the point at 0,0) *
REM * by Angle#.  The direction of the rotation is controlled by the *
REM * sign of Angle#.  A positive Angle# gives rotation in an        *
REM * anti-clockwise direction and a negative one gives a clockwise  *
REM * rotation.                                                      *
REM ******************************************************************

DECLARE FUNCTION Spin2D%(This#(), MyBounds AS Box2D, Angle#)
REM ******************************************************************
REM * Identical to Rotation2D except that the rotation is about the  *
REM * centre of the figure being rotated.                            *
REM ******************************************************************

DECLARE FUNCTION Orbit2D%(This#(), MyBounds AS Box2D, OrbitX#, OrbitY#, Angle#)
REM ******************************************************************
REM * Identical to Rotation2D except that the rotation is about      *
REM * OrbitX#, OrbitY#.                                              *
REM ******************************************************************

REM ******************************************************************
REM * The next 3 routines are for the management of the data types   *
REM * used to control which part(s) of the graphical objects we are  *
REM * dealing with are visible and where they will be displayed.     *
REM * While it is true that QB already has such mechanisms built-in, *
REM * you can only have one graphical window and one view-port at a  *
REM * time with these.  The graphical system presented here allows   *
REM * for multiple such windows and viewports at once.               *
REM ******************************************************************

DECLARE FUNCTION SetNewWindow2D%(ThisWindow AS Box2D, Left#, Right#, Top#, Bottom#)
REM ******************************************************************
REM * Stores the values held in Left#, Right#, Top# and Bottom# in   *
REM * ThisWindow.                                                    *
REM ******************************************************************

DECLARE FUNCTION SetNewViewPort%(ViewPort AS AView2D, Left%, Right%, Top%, Bottom%)
REM ******************************************************************
REM * Stores the values held in Left%, Right%, Top% and Bottom% in   *
REM * ViewPort.                                                      *
REM ******************************************************************

DECLARE SUB SetNewVision(Vew AS Vision, ThisWindow AS Box2D, ViewPort AS AView2D)
REM ******************************************************************
REM * Copies the contents of ThisWindow and ViewPort to Vew and then *
REM * makes certain calculations, storing the results in Vew.  This  *
REM * way all of the information necessary for mapping the world     *
REM * coordinates (i.e. those stored in the coordinate arrays) to    *
REM * the device coordinates (i.e. those of the monitor's screen).   *
REM *                                                                *
REM * NOTE - if you do not want your graphics to have uncontrolled   *
REM * distortion it is essential that the aspect ratio               *
REM * (i.e. (Right - Left) / (Top - Bottom)) of ThisWindow and       *
REM * ViewPort are identical.                                        *
REM ******************************************************************

DECLARE SUB ClipLine2D(X1Old#, Y1Old#, X2Old#, Y2Old#, X1New#, Y1New#, X2New#, Y2New#, Vew AS Vision, Visible%)
REM ******************************************************************
REM * If a line is within the Box2D held in Vew, it will be trimmed  *
REM * to fit if necessary.  Visible% flags the obvious.              *
REM ******************************************************************

DECLARE FUNCTION ClipDots2D%(Shape2D#(), MyBounds AS Box2D, Vew AS Vision, Dots#())
REM ******************************************************************
REM * Those dots in Shape2D# that are within the Box2D held in Vew   *
REM * are returned in dots.                                          *
REM ******************************************************************

REM ******************************************************************
REM * In the context of the following routines a polygon is simply a *
REM * list of coordinates that will be drawn as lines.  The way that *
REM * these lines are drawn is as follows.  The first line to be     *
REM * drawn uses the first pair of coordinates to produce the line.  *
REM * The next and subsequent lines use the last coordinates from    *
REM * the previous line as their first coordinate and the next       *
REM * coordinate as their last coordinate. If a closed figure is     *
REM * desired, it is necessary for the last pair of coordinates to   *
REM * be identical to the first pair.                                *
REM *                                                                *
REM * A shape, on the other hand is more complex and therefore uses  *
REM * an INTEGER array to hold a list of points to be connected in   *
REM * the order in which they are to be connected.  The format of    *
REM * the data held in this array is as follows:-                    *
REM *                                                                *
REM * The first 2 coordinate pairs (i.e. A#(1, QX%), A#(1,QY%) and   *
REM * A#(2,QX%), A#(2,QY%)) ALWAYS specify the start and end points  *
REM * of the first line of the figure.  After that, the last point   *
REM * of the preceding pair of points is the start point for the     *
REM * next line and the next item specifies the end point of that    *
REM * line unless the next A#(N, QX%) is -1.  If it is -1 it means   *
REM * drop the data already read and treat the next 2 coordinate     *
REM * pairs as the start and end points of the next line.  As an     *
REM * example of this, the snippet of code below is the actual       *
REM * connection list for the StarOfDavid which is defined later.    *
REM *                                                                *
REM *        Connections%(0) = 1                                     *
REM *        Connections%(1) = 3                                     *
REM *        Connections%(2) = 5                                     *
REM *        Connections%(3) = 7                                     *
REM *        Connections%(4) = -1                                    *
REM *        Connections%(5) = 2                                     *
REM *        Connections%(6) = 4                                     *
REM *        Connections%(7) = 6                                     *
REM *        Connections%(8) = 2                                     *
REM *                                                                *
REM ******************************************************************

DECLARE FUNCTION DisplayDotsDirect%(Dots#(), MyBounds AS Box2D, ScreenMode%, Colour%)
REM ******************************************************************
REM * Tries to display the points held in Dots on the current        *
REM * graphics screen without any clipping or mapping.               *
REM ******************************************************************

DECLARE FUNCTION DisplayPolygonDirect%(Polygon#(), MyBounds AS Box2D, ScreenMode%, Colour%)
REM ******************************************************************
REM * Tries to display the lines described in Polygon on the current *
REM * graphics screen without any clipping or mapping.               *
REM ******************************************************************

DECLARE FUNCTION DisplayShapeDirect%(Shape2D#(), MyBounds AS Box2D, ConnectionList%(), ScreenMode%, Colour%)
REM ******************************************************************
REM * Tries to display the lines described in Shape2D and List, on   *
REM * the current graphics screen without any clipping or mapping.   *
REM ******************************************************************

DECLARE FUNCTION DisplayDots%(Dots#(), MyBounds AS Box2D, Colour%, Vew AS Vision)
REM ******************************************************************
REM * Those points held in Dots that are within the Box2D that is    *
REM * part of Vew will be clipped, mapped and displayed by this      *
REM * routine.                                                       *
REM ******************************************************************

DECLARE SUB DisplayLine(X1#, Y1#, X2#, Y2#, Colour%, Vew AS Vision)
REM ******************************************************************
REM * Any portion of the line described by point (X1,Y1) to point    *
REM * (X2,Y2), that is within the Box2D that is part of Vew it will  *
REM * be clipped, mapped and displayed by this routine.              *
REM ******************************************************************

DECLARE FUNCTION DisplayPolygon%(Polygon#(), Colour%, Vew AS Vision)
REM ******************************************************************
REM * Those lines described in Polygon that are within the Box2D     *
REM * that is part of Vew will be clipped, mapped and displayed by   *
REM * this routine.                                                  *
REM ******************************************************************

DECLARE FUNCTION DisplayShape2D%(Shape2D#(), Colour%, ConnectionList%(), Vew AS Vision)
REM ******************************************************************
REM * Those lines described in Shape2D and List that are within the  *
REM * Box2D that is part of Vew will be clipped, mapped and          *
REM * displayed by this routine.                                     *
REM ******************************************************************

REM ******************************************************************
REM * The graphical objects dealt with in this part of the library   *
REM * are of 2 kinds, pre-calculated straight line objects (mostly   *
REM * polygons) and curved objects that mostly have to be calculated *
REM * "on the fly" (the exception being circles which are            *
REM * pre-calculated).  In the context of this library, all curved   *
REM * objects are simulated by a number of (comparatively) short     *
REM * straight lines.  This is done to enable the use of the simple  *
REM * transformation routines already described.                     *
REM *                                                                *
REM * For those who don't know the names of regular polygons and the *
REM * number of sides each posses, I enclose the following list.     *
REM *                                                                *
REM * Sides    Name                                                  *
REM *                                                                *
REM *  3    Triangle                                                 *
REM *  4    Square                                                   *
REM *  5    Pentagon                                                 *
REM *  6    Hexagon                                                  *
REM *  7    Heptagon                                                 *
REM *  8    Octagon                                                  *
REM *  9    Nonagon                                                  *
REM *  10    Decagon                                                 *
REM *  11    Undecagon                                               *
REM *  12    Dodecagon                                               *
REM *                                                                *
REM ******************************************************************

REM ******************************************************************
REM * The following routines all resize and load the array with the  *
REM * coordinates for the appropriate shape.  All the shapes that    *
REM * have the prefix Unit have dimensions that are in the range     *
REM * from -1 to +1 and are centred at 0,0.  The data for these      *
REM * shapes is held in the file SHAPES2D.DAT.                       *
REM ******************************************************************

DECLARE SUB UnitTriangle(ATriangle#())
DECLARE SUB UnitSquare(ASquare#())
DECLARE SUB UnitPentagon(APentagon#())
DECLARE SUB UnitHexagon(AHexagon#())
DECLARE SUB UnitHeptagon(AHeptagon#())
DECLARE SUB UnitOctagon(AnOctagon#())
DECLARE SUB UnitNonagon(ANonagon#())
DECLARE SUB UnitDecagon(ADecagon#())
DECLARE SUB UnitUndecagon(AnUndecagon#())
DECLARE SUB UnitDodecagon(ADodecagon#())
DECLARE SUB UnitCircle(ThisCircle#())
DECLARE SUB UnitArrow(AnArrow#())
DECLARE SUB UnitParralellogram(AParralellogram#())
DECLARE SUB UnitDiamond(ADiamond#())

REM ******************************************************************
REM * The next set of routines also load the output variable with    *
REM * the coordinates of the given shape.  The way they work is to   *
REM * first get a copy of the appropriate Unit shape, expand them in *
REM * such a way as to produce a figure with sides that are SideSize *
REM * long and then to move the whole figure so that it is centred   *
REM * at CenterX, CenterY.                                           *
REM ******************************************************************

DECLARE SUB Triangle(SideSize#, CenterX#, CenterY#, ATriangle#(), MyBounds AS Box2D)
DECLARE SUB Square(SideSize#, CenterX#, CenterY#, ASquare#(), MyBounds AS Box2D)
DECLARE SUB Pentagon(SideSize#, CenterX#, CenterY#, APentagon#(), MyBounds AS Box2D)
DECLARE SUB Hexagon(SideSize#, CenterX#, CenterY#, AHexagon#(), MyBounds AS Box2D)
DECLARE SUB Heptagon(SideSize#, CenterX#, CenterY#, AHeptagon#(), MyBounds AS Box2D)
DECLARE SUB Octagon(SideSize#, CenterX#, CenterY#, AnOctagon#(), MyBounds AS Box2D)
DECLARE SUB Nonagon(SideSize#, CenterX#, CenterY#, ANonagon#(), MyBounds AS Box2D)
DECLARE SUB Decagon(SideSize#, CenterX#, CenterY#, ADecagon#(), MyBounds AS Box2D)
DECLARE SUB Undecagon(SideSize#, CenterX#, CenterY#, AnUndecagon#(), MyBounds AS Box2D)
DECLARE SUB Dodecagon(SideSize#, CenterX#, CenterY#, ADodecagon#(), MyBounds AS Box2D)
DECLARE SUB Arrow(LongSideSize#, CenterX#, CenterY#, AnArrow#(), MyBounds AS Box2D)
DECLARE SUB Diamond(Height#, CenterX#, CenterY#, ADiamond#(), MyBounds AS Box2D)

REM ******************************************************************
REM * The next 2 shapes are slightly more complicated than those     *
REM * that have preceded them.  They are based around points that    *
REM * have already been calculated, but these points are connected   *
REM * in a different order to the simple polygons that proceeded     *
REM * them and therefore use an INTEGER array to hold a list of      *
REM * points to be connected in the order in which they are to be    *
REM * connected.  In other words these are shapes as described       *
REM * earlier.                                                       *
REM ******************************************************************

DECLARE SUB Pentagram(Span#, CenterX#, CenterY#, ThisPentagram#(), MyBounds AS Box2D, Connections%())
DECLARE SUB StarOfDavid(Span#, CenterX#, CenterY#, ThisStar#(), MyBounds AS Box2D, Connections%())

REM ******************************************************************
REM * This final set of routines is concerned with the generation of *
REM * curved shapes.  Most of the routines in this section actually  *
REM * involve calculation as distinct from the preceding routines    *
REM * which did not.  NOTE - all angles used in this section are     *
REM * in degrees.                                                    *
REM ******************************************************************

DECLARE FUNCTION CircleInformation%(X1#, Y1#, X2#, Y2#, X3#, Y3#, CenterX#, CenterY#, Radius#)
REM ******************************************************************
REM * Given the three points described by the coordinate pairs       *
REM * (X1,Y1), (X2,Y2) and (X3,Y3) this routine calculates the       *
REM * centre (CenterX,CenterY) and Radius of a circle.  The rules    *
REM * for the usage of this routine are that the three points lie on *
REM * the circumference of the circle and are encountered, in order, *
REM * by travelling along the upper hemisphere of the circle in a    *
REM * clockwise direction.  Further it is an error if all three      *
REM * points lie upon a straight line (known as collinearity) and    *
REM * FALSE will be returned if this occurs.                         *
REM ******************************************************************

DECLARE SUB TwinCircleTangent(CenterX1#, CenterY1#, Radius1#, CenterX2#, CenterY2#, Radius2#, Point1X#, Point1Y#, Point2X#, Point2Y#)
REM ******************************************************************
REM * This routine follows a specialised need namely to connect 2    *
REM * arcs with a straight line that flows smoothly into the arcs.   *
REM * The way this is done is to take the centres and radii of two   *
REM * circles and to calculate the points where an appropriate line  *
REM * would be tangential to both.  The coordinates of Point1        *
REM * correspond with the details of circle 1 and Point2 with circle *
REM * 2.  As for any given pair of circles there are 4 possible      *
REM * tangential lines that could connect them a mechanism is needed *
REM * to enable distinction of which line should be calculated.  The *
REM * mechanism used is directionality of rotation of the circles    *
REM * expressed as the sign of the individual radius's. By this I    *
REM * mean that if a radius is negative the corresponding circle is  *
REM * assumed to be drawn in a clockwise direction and a positive    *
REM * radius, anti-clockwise.  Now if you consider the line to be    *
REM * drawn as a continuation of the 2 circles it becomes a simple   *
REM * matter to determine the signs of the radii to be passed to     *
REM * this routine.                                                  *
REM ******************************************************************

DECLARE SUB ACircle(Radius#, CenterX#, CenterY#, ThisCircle#(), MyBounds AS Box2D)
REM ******************************************************************
REM * Loads ThisCircle#() with the coordinates of a 72 sided figure  *
REM * which simulates a circle of Radius at CenterX, CenterY.        *
REM ******************************************************************

DECLARE SUB Ellipse(XRadius#, YRadius#, CenterX#, CenterY#, AnEllipse#(), MyBounds AS Box2D)
REM ******************************************************************
REM * Loads Ellipse#() with the coordinates of a 72 sided figure     *
REM * which simulates an ellipse of XRadius, YRadius at CenterX,     *
REM * CenterY.  The way this works is that a UnitCircle is expanded  *
REM * by differing X and Y amounts.                                  *
REM ******************************************************************

DECLARE SUB CalculateAngle(CenterX#, CenterY#, PointX#, PointY#, Angle#)
REM ******************************************************************
REM * Calculates the angle that a line (running from CenterX,        *
REM * CenterY to PointX,PointY) makes in relation to the horizontal  *
REM * axis.  Positive angles indicate that the line is above the     *
REM * horizontal axis and negative below.                            *
REM ******************************************************************

DECLARE FUNCTION GetAngle#(StartAngle#, EndAngle#)
REM ******************************************************************
REM * Calculates the length of an arc, in degrees, of an arc running *
REM * in an anti-clockwise direction from StartAngle to EndAngle.    *
REM ******************************************************************

DECLARE FUNCTION ArcInformation%(X1#, Y1#, X2#, Y2#, X3#, Y3#, CenterX#, CenterY#, Radius#, StartAngle#, Degrees#)
REM ******************************************************************
REM * Given 3 points on the circumference of an arc, this routine    *
REM * calculates all the information needed to create an arc.  Point *
REM * (X1,Y1) is the starting point for the arc, point (X2,Y2) the   *
REM * mid-point and point (X3,Y3) the end point of the arc.  The     *
REM * rules for the usage of this routine are the same as for        *
REM * CircleInformation.                                             *
REM ******************************************************************

DECLARE SUB CreateArc(CenterX#, CenterY#, Radius#, StartAngle#, Degrees#, Arc#(), MyBounds AS Box2D)
REM ******************************************************************
REM * Loads Arc#() with the coordinates of an arc described by the   *
REM * arguments CenterX#, CenterY#, Radius#, StartAngle# and         *
REM * Degrees#.  The argument Degrees holds the length of the arc in *
REM * degrees.                                                       *
REM ******************************************************************

DECLARE SUB CreateParametricCubicCurve(X1#, Y1#, X2#, Y2#, X3#, Y3#, X4#, Y4#, CubicCurve#(), MyBounds AS Box2D)
REM ******************************************************************
REM * As not all curved shapes are based on conic sections this      *
REM * routine and the next offer 2 ways of describing those other    *
REM * shapes, based on control points which are external to the      *
REM * desired curved shape.  In this routine point (X1,Y1) is the    *
REM * start point, point (X4,Y4) is the end point.  Points (X2,Y2)   *
REM * and (X3,Y3) in conjunction with the points already mentioned   *
REM * are used to determine the final shape of the curve.  This      *
REM * routine is based on the algorithm devised by Harry Timmer of   *
REM * the Douglas Aircraft Company.  This routine (in common with    *
REM * many others) uses four blending functions to describe the      *
REM * curve parametrically.  The characteristic that sets this       *
REM * algorithm apart from the others is that if an imaginary line   *
REM * is drawn from X2#,Y2# to X3#,Y3# and the curve is then         *
REM * calculated and drawn it will be noted that the apex of the     *
REM * curve either touches or crosses this line at its centre.       *
REM ******************************************************************

DECLARE FUNCTION CreateComplexCurve%(ControlPoints#(), Curve#(), MyBounds AS Box2D)
REM ******************************************************************
REM * This is an extension to the preceding routine.  The array      *
REM * ControlPoints#() contains a series of control points, the      *
REM * number of which must be divisible by 2 and greater than or     *
REM * equal to 4 (ideally greater than 4 e.g. at least 6).           *
REM ******************************************************************

REM ******************************************************************
REM * The final three routines are here to enable programs to        *
REM * interact with the routines presented here.                     *
REM ******************************************************************

DECLARE FUNCTION DeviceToWorldCoordinates%(InX%, InY%, Vew AS Vision, OutX#, OutY#)
REM ******************************************************************
REM * If a point on the screen (InX%,InY%) is within the viewport in *
REM * Vew the coordinates will be converted to the corresponding     *
REM * point in world coordinates and TRUE% returned.  Otherwise      *
REM * FALSE% is returned.                                            *
REM ******************************************************************

DECLARE FUNCTION InBox%(TX#, TY#, Bounds AS Box2D)
REM ******************************************************************
REM * If the point TX#,TY# is within Bounds TRUE% is returned,       *
REM * otherwise FALSE%.                                              *
REM ******************************************************************

DECLARE FUNCTION ClosestPoint%(TX#, TY#, Shape#())
REM ******************************************************************
REM * Returns the number of the coordinate pair in shape#() which is *
REM * closest to TX#, TY#.                                           *
REM ******************************************************************

Library in next post.

TR
Reply


Messages In This Thread
Large 2D Graphics Library - by TarotRedhand - 05-16-2022, 09:10 AM
RE: Large 2D Graphics Library - by TarotRedhand - 05-16-2022, 09:20 AM
RE: Large 2D Graphics Library - by TarotRedhand - 05-16-2022, 09:29 AM
RE: Large 2D Graphics Library - by James D Jarvis - 05-16-2022, 11:56 AM
RE: Large 2D Graphics Library - by TarotRedhand - 05-16-2022, 10:38 PM



Users browsing this thread: 2 Guest(s)