Drawplex

Drawing on the complex plane

(C) 2005 Marius Amado Alves

Drawplex supports drawing geometric forms, text, and images, on the complex plane, and materializing any portion of it in viewable forms e.g. BMP files.Drawplex is 100% Ada.

All Drawplex operations are effected on a Canvas defined by the user.A Canvas is a package of type Color, vector Unit, and actions Put and Get for points.Drawplex includes support for the creation of a number of useful canvases.For example Drawplex.Memory represents a canvas stored in main memory.Sensible defaults are provided for all parameters except Color.

Drawplex privileges the unit square i.e. the region (0,0) × (1,1) of the complex plane.Drawplex.Standard entities are set accordingly, and with respect to a discretization of the unit square into 1000 × 1000 cells.

Remind that the complex plane equals the 2-dimensional plane with the real component on the horizontal axis and the imaginary component on the vertical.Note that, unlike most other graphics libraries, Drawplex respects the mathematical standard vertical orientation, namely with vertical values increasing upwards.

Canvases

The Canvas abstraction has the following semantics.

Color:Drawplex uses Color'First and Color'Last as the default foreground and background colors respectively.

Unit represents the maximum intervals between consecutive point coordinates used in drawing straight lines. That is, when Drawplex draws a line, what it does is drawing dots at points on the abstract line such that consecutive points are no more distant from each other than the absolute size of the coordinates of Unit.

Also, in a canvas distretized into cells like the one represented by Drawplex.Memory, Unit defines the cell size.Also, Unit corresponds to Density 1 in the Dot operation (see below).

Put represents drawing an infinitly small point with the specified color.

Get represents the color of the specified (infinitly small) point.

In a canvas discretized into cells like the one represented by Drawplex.Memory, a point inside a cell is expected to represent the cell.That is, Get represents the color of the cell containing the specified point, and the color of a cell is the color of the point last put inside the cell.

Utility canvases

A number of utility canvases are provided as nested generic packages of Drawplex.Naturally, each matches the Canvas_Template signature.Also, each provides a corresponding instantiation of Canvas_Template, called Instance.

Memory stores the specified region discretized into Unit-sized cells in main memory. Procedure Fill paints all cells with the specified color.Procedure Clear is called upon package instantiation.

Bounds computes the drawing bounds.Region represents the minimal bounds of all drawing effected on the canvas.Region raised Undefined if no drawing has been done since instantiation of the package or the last call to Reset.Get always raises Nonsense, as this is a "Put-only" canvas.Reset "reundefines" the bounds, thus readying the package for reutilization.

Transform transposes and rescales a canvas to the specified origin and by the specified factor.That is, point (x, y) on the new canvas corresponds to point Origin + (x × Factor.Re, y × Factor.Im) on the original canvas.Put and Get operations are delegated to the corresponding operations of the original canvas with the point coordinates adjusted accordingly.

Rescale rescales a canvas to the new Unit.Namely, Rescale (Canvas, Unit) is equivalent toTranform (Canvas, Origin => (0.0, 0.0), Factor => (Canvas.Unit.Re / Rescale.Unit.Re, Canvas.Unit.Im / Rescale.Unit.Im)).

Drawing operations

Drawing operations are provided by nested package Drawplex.Drawing for geometric forms, and child package Drawplex.Characters for text.Next these operations are described.Text drawing operation names start with Put.Other operation names refer to geometric form drawing.The Drawplex logo is produced with Drawplex and is used to illustrate the result of some operations.

Dot draws a round or square dot centred at Point and with diameter or side Thickness.Dot parameters include a Density factor, corresponding to the number of points put (i.e. number of calls to Put) with respect to a discretization of the dot region based on Unit. Namely, number of points put = Factor × number of Unit-sized cells in the dot region.The points put are scatered evenly across the region.The Drawplex logo includes 8 round and 8 square dots, all with the same thickness, and density increasing from 1/8 to 1 (from left to right).Note that, because points are infinitly small, zero Thickness represents (exactly) one point, not none.However zero Density does mean zero points put.

All other drawing operations are effected by drawing dots at the computed points.Therefore, all other drawing operations include the "Dot parameters" Thickness, Density, Round,which are used in the internal calls to Dot.

Furthermore: in general, more complex drawing operations (including text drawing ones) are effected as a composition of simpler ones.Accordingly, such drawing operations include all the parameters required by the simpler ones.Unless otherwise noted, the values of these parameters are passed unmodified to the simpler operations.

Line (From, To...) draws a straight line between the two specified points.

Line (Points...) draws a series of lines, each between each two consecutive elements of Points.The turns i.e. the shifts in direction can be smoothed into a circular arc with radius Curve. Naturally the default value 0 of Curve specifies sharp turns, i.e. no smoothing.

Arc draws a circular arc with the specified Center and Radius between the two specified angles From, To.The arc is always drawn in direct (counter clockwise) direction, even if From is greater than To, i.e. Arc (... From, To...) is equivalent to Arc (... To, From...). So, to draw a 1/2 π arc from -1/4 π to 1/4 π, write either Arc (... From => -Quarter_Pi, To => Quarter_Pi...) or Arc (... From => Quarter_Pi, To => -Quarter_Pi...). To draw the complementary 3/4 π arc the difference between From and To must express this quantity e.g. Arc (... From => Quarter_Pi, To => Two_Pi - Quarter_Pi...)or Arc (... From => Two_Pi - Quarter_Pi, To => Quarter_Pi...).

Circle simply calls Arc with angles from 0 to 2π.

Parameter Step: operations with a (potential or actual) circular component have a parameter Step with the following semantics. Arcs are drawn as a sequence of straight lines between points in the arc such that the angle between two consecutive point is no greater than Step.The default value of Step represents an angle such that the distance between consecutive points approximates Modulus (Unit).

All angles are in radians.

Put (C : Character...) draws a glyph corresponding to C at the specified position and with the specified size.The position corresponds to the lower left corner of the glyph box.The size corresponds to the size of the glyph box.On exit, Position is updated to point to the lower rigth corner of the glyph box i.e. Position on exit = Position on entry + Size.Re.

The glyph box is a square.The glyph is inside the box except for the small pretuberances of certain characters, for example 'p' and 'l' (see the effect in the Drawplex logo).The bottom of the box corresponds to the baseline of normal text.Glyphs are horizontally centred on the box.All 0 to 9 digits have the same bounds.Digits 0 to 9 and uppercase letters have the full height of the box.Lowecase letters have height 70% of the box (except for pretuberances).The glyph table follows.Glyphs not properly implemented yet show as the corresponding character code in hexadecimal.Unicode is adopted.

Drawplex character table

Put_String (S...) simply calls Put (C : Character...) in sucession for each element of S.

Bounds (C : Character...) returns the bounds of the (1,1)-sized glyph of C positioned at (0,0).

Width (C : Character...) is equivalent to Bounds (C...) (2).Re - Bounds (C...) (1).Re

Drawplex.BMP

This package provides writing/reading a region of a canvas into/from a BMP file of 24-bit RGB colors.

This package is based on BMP_Pro.BMP_Pro is part of the Drawplex distribution, but it can be used on its own for other applications.

License

Drawplex is released under the SDC Conditions, a progressive license published and discussed by the Software Developers Cooperative.The full license text follows.
Conditions of Use of SDC ArtifactsVersion 2 (2003-07-24)(C) Software Developers Cooperative (SDC)(General)1 The effective version of these conditions is, at any time, the mostrecent. Henceforth "these conditions" denote the effective version.2 In these conditions, "artifact" means a work of authorship, subject tocopyright law.3 The use of any SDC artifact is subject to these conditions. The use, ofan SDC artifact, not in accordance with these conditions, is an illegalact.4 An SDC artifact is any artifact claimed to be such by its authors. Anyartifact copyrighted exclusively by SDC has such claim made implicitely.5 Any copy of an SDC artifact must have a license for its use, as follows.6 A copy used in a business must have a specific license for that useexplicitly issued by SDC. Such a license is called a "commercial license"and is explained in the Commented Conditions.7 A copy not used in a business has a license for that use implicitlyissued by SDC at zero monetary cost. That license is called"non-commercial" and is defined in clauses 10-23.8 "Used in a business" means being part of a commercial service or acommercial product, or being used in the process of creating, preparing orproviding such service or product.9 "Commercial" means having the purpose or result of being sold.(Non-commercial license)10 Clauses 10-23 define the specific conditions of use of, a copy of anSDC artifact, not used in a business. Henceforth such a copy is called"the artifact".11 The artifact may be copied or distributed.12 Any distribution must have a copy made publicly available in theInternet.13 If the artifact is a software program or component its distributionmust include the entire source code of the artifact.14 "Source code" means the preferred form, of representation of theartifact, for understanding or modifying the artifact, or for combiningthe artifact with other artifacts represented in the same form.15 The artifact may be modified as long as:16 the modification is described with at least the date of themodification and the identification of the author of the modification, and17 all pre-existing descriptions of modifications or creation, includingcopyright notices, are preserved in the modified copy.18 The modified artifact is still an SDC artifact subject to the currentConditions of Use of SDC Artifacts.19 The artifact must exhibit a notice containing at least:20 the claim specified in clause 4;21 a valid reference to a copy of these conditions.22 A product containing the artifact, or a service using it, mustadvertise that fact.(Warranties)23 Unless explicitly stated on a commercial license, an SDC artifact isprovided with no warranties of any kind.(SDC Indentification)24 SDC is the organization expressed in the Internet atwww.softdevelcoop.org, or yahoogroups.com/group/softdevelcoop.