|
|
|
Having introduced the main programming ideas for
FIT100, it is time to put it all together.
The task will be to draw something interesting on the form and in
the process get experience writing procedures |
|
|
|
|
|
The form is logically divided into a grid, and a
position is designated by how many grid points it is from the Left and the Top |
|
The upper left corner is position (0,0) |
|
The position (x, y) is x units from Left, and y
units from Top |
|
Increasing the x value moves to the right |
|
Unlike graphing, though, increasing |
|
the y value moves down |
|
The lower right corner is |
|
position (ScaleWidth, ScaleHeight) |
|
To resize the form, change |
|
ScaleWidth and ScaleHeight |
|
|
|
|
|
To draw a line on Form1, call the procedure |
|
Form1.Line (x1, y1) - (x2, y2) |
|
|
|
|
|
|
|
If there is only one form, the form name can be elided |
|
To get a color, follow the positioning
information with the specification of the color |
|
Form1.Line (x1, y1) - (x2, y2), RGB(255,255,255) |
|
|
|
|
|
|
|
Recall that colors are created on the screen
with a combination of three colors of light -- red, green, blue |
|
When drawing, one can specify the exact color by
calling a procedure, RGB( , , ) whose three parameters are the contribution
of the three colors in the range 0 -- 255 |
|
RGB(0, 0, 0) |
|
RGB(255, 0, 0) |
|
RGB(0, 255, 0) |
|
RGB(0, 0, 255) |
|
RGB(255,255,255) |
|
|
|
|
|
Drawing a rectangle is like drawing a line
except that there is a final parameter “B” |
|
Line (x1, y1) - (x2, y2), RGB(r, g, b), B |
|
|
|
|
|
|
|
|
|
A specific fill color can be achieved by having
two properties set |
|
FillColor = RGB( , , ) |
|
FillStyle = 0 |
|
|
|
|
To begin, draw a box in the Form_Click event
handler |
|
|
|
|
A black rectangle on a gray form is a little
dorky … |
|
Set the background color of the form |
|
|
|
|
Make box fill opaque and change line to white
line |
|
|
|
|
Draw a 1K´1K box with opaque fill and a white line |
|
The fill color will be whatever color is set
when the procedure is called |
|
|
|
|
|
Click once, create one box |
|
Click again, show another |
|
Steps for multiclicks ... |
|
Declare clickCount variable |
|
In Form_Load initialize it to 0 |
|
In Form_Click, increment it |
|
Then test its value with If |
|
For each value do what you |
|
want on that click |
|
1st: black box |
|
2nd: green box |
|
|
|
|
|
Increase the form size |
|
to cover whole screen |
|
Add another “click” case |
|
WindowState has 3 values |
|
Setting 2 maximizes form |
|
Drawing box from (0,0) to |
|
(ScaleWidth,ScaleHeight) |
|
covers the entire form … |
|
make it red! |
|
|
|
|
Adding a timer allows changes to be made a
regular intervals … place timer anywhere on form |
|
|
|
|
The 4th click starts box draw |
|
and the 5th click stops it |
|
|
|
|
|
Diagonal boxes are boring … randomize |
|
To place boxes randomly, |
|
Set Randomize in Form_Load |
|
Declare xPos, yPos |
|
in tmrClock |
|
Pick a random number |
|
in (0,1) range with a |
|
Rnd(1) procedure call |
|
Multiply by the largest |
|
size to scale & make Int |
|
|
|
|
|
|
|
|
|
Project 2 is to design your own “artistic” image
… or electronic greeting card to impress your family and friends … and TA |
|
There is no limit to how intricate your design
can be |
|
There are points for creativity and ... |
|
You must use procedures as called for in the
assignment |
|
|
|