As of October, 2016, Embarcadero is offering a free release
of Delphi (Delphi
10.1 Berlin Starter Edition ). There
are a few restrictions, but it is a welcome step toward making
more programmers aware of the joys of Delphi. They do say
"Offer may be withdrawn at any time", so don't delay if you want
to check it out. Please use the
link to let me know if the link stops working.
Support DFF - Shop
If you shop at Amazon anyway, consider using
this link. We receive a few cents from each purchase.
Support DFF - Donate
If you benefit from the website, in terms of
knowledge, entertainment value, or something otherwise useful,
consider making a donation via PayPal to help defray the
costs. (No PayPal account necessary to donate via credit
card.) Transaction is secure.
e-mail with your comments about this program (or anything else).
An exercise to draw doors subdivided with one or more vertical frames separated
and divided by mullions of a given size.
Background & Techniques
This program was the result of a request from a Delphi programmer who was
faced with this problem in the course of developing a piece of software for
their business. It was a mildly challenging exercise just to prove
that it still could be done by this 77 year old programmer.
Haven't lost it yet!
The five Input values are: 1) Door Width, 2) Door Height, 3) Number of
frames in the door, 4) Width of Mullions, and 5) Height above door bottom
to the top of cross-mullion within each frame.
Non-programmers are welcome to read on, but may want to jump to bottom of
this page to download the executable program now.
"Rectangle" was the only TCanvas method used in drawing a door.
The problems included:
- Calculating frame width: FrameWidth =
DoorWidth - MullionWidth x (NbrFrames + 1)) / Number of Panels.
- Calculating frame Left/Top corner Nth frame (L, T).
L=MullionWidth + (N-1) x (FrameWiidth
--MullionWindth); T = Dootop + MullionWidth
- Calculating frame rectangle relative to passed (L,T)
- Lower panel Top/Left corner (PL,Pt):
PL= L; PT =
Doorheight - MullionHeightAboveBase + MullionWidth.
- Lower panel Height frames: Panelheight =
MullionHeightAboveBase - 2 x MullionWidth.
- Top/Left corner of the top panel within frames (PL,PT):
PL = L; PT = T.
- Height of the top panel within frames:
PanelHeight = Doorheight - MullionHeightAboveBase.
- Scaling the calculated values to display centered in the TImage
canvas: Converting from millimeters (or any other unit) to
pixels requires multiplying by a pixels/unit scaling factor.
Here we'll calculate two candidates; one for width and one for height and
take the smaller value as the one to use. I chose to make the top left
corner of the door image at 10% from the left and from the top of the
TImage and occupy 80% of the height and /or width. So
ScaleX = 0.8 x Timage width / Doorwidth;
ScaleY = 0.8 x TImage.Height / DoorHeight,
and Scale = min(scalex, scaley).
Scaled versions of the dimensional parameters described above are
used for drawing the rectangles.
Running/Exploring the Program
Suggestions for Further Explorations
|Original: March 18, 2016
March 19, 2016