Doodler Drawing #2

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

 

 

Search

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.)

Contact

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

Search DelphiForFun.org only

 

 

 

Problem Description

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.  

A Rotate-draw page makes multiple copies of your drawing, each rotated by specified number of degrees and specified number of times. A checkbox activates or deactivates the rotate-draw feature.

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.

Have fun!

Background & Techniques

A couple of notes for users:  

bulletKaleidoscope and rotate-draw can both be activated at the same time, but you probably won't like the result.
bulletKaleidoscope mirrors are  virtual 2-way mirrors so the entire drawing is reflected multiple times, not just the portion between the mirrors.
bulletRight clicking in an area on the image fill changes color of clicked spot in all directions until a different color is found.  I wasn't smart enough to figure out how to  preserve area fill information when image is redrawn.  Enclosed areas may appear or disappear with rotate-draw or kaleidoscope options.  So it's probably best to save fill-in coloring  'til last.

Non-programmers may want  jump to page bottom now to download the program.

For programmers:  

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 

bulletBrowse source extract 
bulletDownload source 
bulletDownload  executable

Suggestions for Further Explorations

Realistic kaleidoscope with lines between the two primary mirrors  clipped at mirror boundaries and lines not between the mirrors not appearing at all. 
Add some sort of "stamp" feature to add predefined shapes or images to the drawing.   

 

Modified: May 15, 2018

 

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