Doodler Drawing #1

[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

Here's a "doodling" program that allows mouse drawing with optional reflections on 2 or 4 axes.   

Background & Techniques

While investigating of symmetry, I decided to post this program as an introduction.   It might be fun for youngsters to play around with.   A second version is planned that will be more complete, so this one is primarily to let novice programmers investigate use of the TPaintbox component and the OnPaint exit to maintain an image.   

No new objects defined in this program, just a TPoints record type to keep track of the path traveled by the mouse.  An array, Points,  of TPoints records is maintained  until the Reset button is pressed.   In Paintbox1, the OnMouseDown exit sets a boolean flag, Drawing.  OnMouseMove adds a point with the current characteristics if Drawing is true, OnMouseUp sets Drawing to false and sets the Break variable to true in the last point added.     Break allows us to keep track of multiple segments in the drawing which may be of different pen colors or widths.   

The OnPaint  exit, PaintBox1Paint, does the actual drawing when Refresh method is called (or automatically whenever required, for example if you minimize and restore the screen).  X and Y coordinates are saved relative to the center of the paint area.  For drawings reflected 4 ways, points are rotated by 0, 90, 180 and 270 degrees for display.  For 8-way reflections, they are displayed at 45 degree increments.   

The equations for rotating a point through angle A are:

xnew = x*cos(A)-y*sin(A) 

ynew = x*sin(A)+y*cos(A)

In this case, the Sin and Cos function values for 45 degree multiples are  approximately plus or minus 0.707, so I just plugged that value as you'll see in the code.

As usual, setting form property Doublebuffered to true eliminates flickering as the screen is redrawn.

TColorDialog is called to change pen colors and a TUpDown component associated with an TEdit box is used to control pen width.   

Running/Exploring the Program 

bulletBrowse source extract 
bulletDownload source 
bulletDownload  executable

Suggestions for Further Explorations

Lots of room to add features to this version
Additional reflection options
Line drawing style options
Undo or erase 
Print capability
Save/restore capability.
Although not quite a  bug, version 1 redraws the entire image with the current reflection options.  They should be applied by segment.

 

Modified: May 15, 2018

 

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