Lab 13:
Graphics, Randomization, Iteration
Spring 2001
Reading to be done for
Lab 13:
·
p. 272-278 (top of 278)
in Chapter 1- of Computer Programming Fundamentals with Applications in
Visual Basic 6.0
Introduction:
For Project 3, you have complete control of the look and design of your program. Using the functions and methods available in VB to draw lines, boxes, circles and rectangles, you and your program will create a work of art. Lab 13 shows you the basic statements needed to manipulate geographic shapes in a way that is pleasing to the eye.
Objectives:
TO DO:
“Click on the Form to see
something cool!”
Name the label lblInstrunctions
·
Clicked the form
Dim clickcount as Integer
·
The x coordinate for a line, box or circle
Dim xCoord as Integer
·
The y coordinate for a line, box or circle
Dim yCoord as Integer
·
The radius of a circle
Dim rad as Integer
·
The number of counts used as your program goes through
a loop
Dim loopCount as Integer
Use the declared variables above to hold values when you
want to have the program draw a line, a box or a circle.
clickcount = 0
clickcount = clickcount + 1
· If the clickcount is 1, then make the label invisible.
· Make the BackColor of the form RGB(171, 25, 191)
· Maximize the WindowState of the form
Your statement should look like this:
If clickcount = 1 Then
lblInstructions.Visible
= False
frmLab13.BackColor =
RGB(171, 25, 191)
frmLab13.WindowState = 2 ‘WindowState is a Form property
‘a WindowState of 0 is Normal,
End If ‘1 is Minimized and 2 is Maximized
Adding Shapes
· If the clickcount is 2, not 1, make the form FillColor RGB(0, 255, 0)
· Give the xCoord and yCoord variables the value of 1000
· Create a Box that goes from the xCoord and yCoord variables to the ScaleWidth – xCoord and the ScaleHeight – yCoord.
· Make the outline of the Box the color red using RGB values
Your statement should now look like this:
If clickcount = 1 Then
lblInstructions.Visible = False
frmLab13.BackColor = RGB(171, 25, 191)
frmLab13.WindowState
= 2
ElseIf
clickcount = 2 Then
FillColor =
RGB(0, 255, 0)
xCoord = 1000
yCoord = 1000
frmLab13.Line
(xCoord, yCoord)-(ScaleWidth - xCoord, _
ScaleHeight - yCoord), RGB(255, 0, 0), B
‘ScaleWidth and ScaleHeight are constant ‘variables that always hold the value of form’s ‘current Width and Height in twips
End If
· Make the fill color anything you want, but give the circle a radius of at least 500.
· Use your lecture notes and the Project 3 description to figure out the proper syntax.
Procedures-Parameter and Arguments
· If the clickcount is 3, not 2 or 1, then start a loop using the Do While iteration statement.
· Use the loopCount variable to keep track of the number of times your program does the loop.
· Set loopCount to 0
· While the loopCount is less than 10:
1. Increment loopCount by 1
2. Increment xCoord by 500
3. Increment yCoord by 500
4. Use the new xCoord and yCoord variable values as arguments and pass them to a procedure called Boxes.
· Create a procedure with the name Boxes at the bottom of your code window.
1. Set the parameters as integers and name them x and y
2. Inside the procedure, change the fill color property to Red using RGB
3. Create a Box that goes from the x and y coordinates to x + 500 and y + 500.
4.
Make the outline color Red as well using RGB
Your additional statement inside the IF/Then of the Form_Click event should look like this:
ElseIf
clickcount = 3 Then
loopCount = 0
Do While
loopCount < 10
loopCount =
loopCount + 1
xCoord = xCoord +
500
yCoord = yCoord +
500
Call
Boxes(xCoord, yCoord)
Your Boxes procedure should look like this:
Private
Sub Boxes(x As Integer, y As Integer)
frmLab13.FillColor
= RGB(255, 0, 0)
frmLab13.Line
(x, y)-(x + 1000, y + 1000), RGB(255, 0, 0), B
End Sub
Using the Timer Control
· If the clickcount is 4, not 3, 2 or 1 then set the tmrTime interval to 1000.
· Go to the tmrTime object and select the Timer procedure from the drop down menus.
· Inside the Timer event, we only want the event to “fire” if the user has clicked 4 times. Write a condition that checks to see if clickcount is 4.
· If it is, then increment xCoord by 1000 and yCoord by 1000
· Use the new xCoord and yCoord variable values as arguments and pass them to the procedure called Boxes.
Your 4th condition to check inside the IF/Then of the Form_Click event should look like this:
ElseIf
clickcount = 4 Then
tmrTime.Interval =
1000
End If
The Timer event for the tmrTime control should look like this:
Private
Sub tmrTime_Timer()
If clickcount =
4 Then
xCoord =
xCoord + 1000
yCoord = yCoord
+ 1000
Call
Boxes(xCoord, yCoord)
End If
Your last condition should look like this:
ElseIf clickcount = 5 Then
frmLab13.Cls
lblInstructions.Visible
= True
lblInstructions.Caption
= "Thank you for clicking!"
End If