Drawing Door Frames

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW

Search DelphiForFun.org

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 feedback 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.  Thanks


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.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only




Problem Description

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.

Programmer's Notes:

"Rectangle" was the only TCanvas method used in drawing a door. The problems included:

bulletCalculating frame width: FrameWidth = DoorWidth - MullionWidth x (NbrFrames + 1)) / Number of Panels.
bulletCalculating frame Left/Top corner Nth frame (L, T).  L=MullionWidth + (N-1) x (FrameWiidth --MullionWindth); T = Dootop + MullionWidth   
bulletCalculating frame rectangle relative to passed (L,T) value:
bullet Lower panel Top/Left corner (PL,Pt):  PL= L;  PT = Doorheight - MullionHeightAboveBase + MullionWidth.
bulletLower panel Height frames: Panelheight = MullionHeightAboveBase - 2 x MullionWidth.
bulletTop/Left corner of the top panel within frames (PL,PT):  PL = L; PT = T.  
bulletHeight of the top panel within frames:  PanelHeight = Doorheight - MullionHeightAboveBase.
bulletScaling 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 

bulletDownload  executable
bulletDownload source 

Suggestions for Further Explorations



Original:  March 18, 2016

Modified:  May 15, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.