[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
Version 2 of Doodler adds rotate-duplicate and kaleidoscope drawing to the previous Doodler 1 version.
Users can click and drag with the mouse to draw on the image area. A Pen
options page allows changing pen color and width. This page also specifies the color
to be used to fill image areas when the user right clicks.
Kaleidoscope page sets first mirror angle and angle between mirrors for kaleidoscope effect.
Buttons allow erasing drawn lines, redrawing, printing, saving, or clearing the image.
Background & Techniques
A couple of notes for users:
Non-programmers may want jump to page bottom now to download the program.
This is called Doodler 2, but it's actually version 5. I assign a new version number whenever changes are significant enough to justify keeping the previous version in case I'm really off base with some intended change. Use "Save project as" first, followed by "Save as" Delphi menu options to make a new version. If you use "Save as" first, the old project will be using the new unit, not a good thing.
I switched from a TPaintBox to TImage based drawing in this version, mainly because it simplified getting the bitmap information needed for printing or saving. A TPageControl was finally chosen as the best way to allow several pages of options in minimum space.
As usual, there is one critical routine that proved the most challenging, and the provided most satisfaction when it finally worked. In this case the procedure is DrawLineInSeg which draws a single line segment between two endpoints, together with it's rotations and reflections. The rotation-draw part is straightforward. TPoints records now contain the angle and radius of each point, measured from the center of the image. Angles are incremented by the rotate angle as many times as the user specified for each end of the line segment, the new x and y coordinates computed, and the connecting lines drawn.
Mirror drawing was even more fun. I sacrificed the wife's vanity mirror to make a pair of mirrors hinged with masking tape in order to investigate how a kaleidoscope works. If you play this way, or with a real kaleidoscope, you'll notice image brightness decrease for each image around the semi-circle from the real objects being reflected. This is because the each successive clockwise or counterclockwise image is a reflection of a reflection (of a reflection, of a ...., etc.). Each image has been reflected an additional time with some loss of light each time.
The first images are reflections of the actual object (or drawing in our case). The second image on the left is the reflection of the right hand reflection, etc. So that's the way the drawing procedure works. Each reflected point exists at an angle behind the mirror equal to the angle that the real point is in front of the mirror.
Notice that this implementation differs from a real world kaleidoscope. For a two mirror kaleidoscope in the real world, objects not in the area between the mirrors are not visible at all. This would have involved clipping line segments at the mirror faces and ignoring line segments not between the mirrors. We'll save that version for a future exploration. These are magic virtual 2-way mirrors, so all line segments get reflected as if they existed between the two primary mirrors.
I think that the rest of the program is pretty straight-forward stuff, so let's get to it!
Running/Exploring the Program
Suggestions for Further Explorations
Modified: May 15, 2018
[Feedback] [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby All rights reserved.