Project 2 "Yes, But Is It Art?" The purpose of this project is to acquire additional experience with procedures, iteration, and conditionals in VB 6.0, hopefully having some fun with graphics and creativity along the way. The program you write will be expected to include the following features: These will be the primary basis for grading this assignment, but they will probably be a natural outcome of your programming effort. Note that it’s possible for a single procedure to fulfill more than one of the above requirements, although it may take some clever planning and design. This is perfectly acceptable; i.e. you are not required to write a separate procedure for each of the six features listed above. As always, if you have any questions about this or any of the instructions, just e-mail us. The question that will be explored by this project is, "Can Visual Basic be used ‘artistically?’" Naturally, art is often a matter of opinion, and in this case, the opinion that matters is yours. What is the most artistic or aesthetic way in which you can use the graphics and computational facilities of VB? Of course, VB was not designed as a graphics package, or even intended for use in any serious graphics applications, but with a little imagination, almost any general purpose programming language can be used to do interesting things graphically. Our goal is not to push the limits of graphics; we want to push the limits of VB. What can you think of? How creative can you be? As an added incentive to being as ingenious as possible, we will have an in-class display of everyone’s design and award prizes for the best. Suggestions: In general, you’re welcome to do anything you’d like with VB graphics and the above programming requirements. You could just draw a pleasing or clever picture on a form. Perhaps you could try making an electronic greeting card...Mothers Day is fast approaching! Motion or action in which the image develops dynamically on the screen can lead to interesting results; e.g. you might have a circle on your form that appears to grow every time you click. Repeatedly redrawing objects in different colors can also have a neat effect. Project Design: Plan on constructing two designs, the first to be graded at an intermediate point and one as your final submission. (The second can be based on the first, or it can be entirely different.) Detailed requirements and due dates are given below. When a project begins executing, it should show an empty form to the user. The user then clicks on the form, causing the image to be drawn. You will not be using controls extensively. All of the graphics will be produced by program code, written by you as procedures. Of course, since the image is produced when the user clicks on the form, the you’ll start your programming effort with the
For-Next loop
In developing the image program, you should emphasize writing procedures. (One could easily imagine writing a dozen small procedures for this project.) First of all, writing procedures is the purpose of the project. Secondly, and more importantly, procedures allow you to organize the development, encapsulating effects that you can then compose into more complex images. Accordingly, the Form_Click() event procedure should not be a very long piece of code, but rather it should merely orchestrate the calling of procedures that do the work, probably by calling other procedures.
Milestones: The first of your two required submissions is due at the start of lab on Thursday, April 29. The program you submit on this date should include at least four of the six programming requirements listed above. Focus on getting the programming requirements done before getting too wrapped up with aesthetic details, especially early on, when working toward this first due date.
The second (and final) submission is due at the start of lecture the following Tuesday, May 4. This program should fulfill all six programming requirements. It’s probably easiest for you to add to your first submission, but, as noted above, you’re welcome to submit a new program altogether, as long as the programming requirements are all met. Hopefully, you’ll have time to bring out the artist in you for this submission.
Since this is the first time you’re designing and writing procedures on your own, we strongly encourage you to keep in touch with us as you start planning your program and experimenting with VB, both things you should do before you start writing your program. You are encouraged (but not required) to e-mail Ken (at yasuhara@cs) a description of some/all of the procedures you plan to write for the first submission to fulfill four of the six requirements. This gives you a chance to make sure you’re on track for the Thursday due date.
Resources: As noted above, VB is not a graphics programming system, but there are many things that can be done with its basic capabilities. Chapter 12 of the Beginning Visual Basic 6.0 book discusses graphics, and though this chapter contains information that we have not covered (nor will we), it is possible to find quite a bit of useful information there that is accessible. See the examples below. If you see something in the Chapter that you’d like to use but don’t understand, just ask us.
In an effort to provide some useful raw material for creating interesting images, consider the following resources.
frmMain.WindowState = 2
After this,
ScaleWidth and ScaleHeight will be huge. Find out by running this version of the Form_Click() procedure from a normal size window:Sub Form_Click() MsgBox "The initial size is " & ScaleWidth & " x " & ScaleHeight frmMain.WindowState = 2 MsgBox "The new size is " & ScaleWidth & " x " & ScaleHeight End Sub
frmMain.BackColor = RGB(216,232,182)
which turns the background to an "olive green". Of course, it is possible to dynamically change these values.
FillColor = RGB(_,_,_) 'set color for inside of rectangle FillStyle = 0 'make shapes filled with solid color frmMain.Line (boxLeft, boxTop)-(boxLeft + boxWidth, boxTop + boxHeight), RGB(_,_,_), B
where you must put everything after the first two lines on a single line in your program. Also, fill in the blank R-G-B values with numbers or variable values from 0 through 255. Remember the key points about this call, namely the facts that you are specifying two corners of a rectangle, the "
—" is required between the two corners, and the "B" is required. If you don’t put in the second RGB() call shown, then the line around the rectangle is black.Drawing a circle is even easier (p. 419):
FillColor = RGB(_,_,_) FillStyle = 0 frmMain.Circle (centerLeft, centerTop), radius, RGB(_,_,_)
where, if the
RGB() is omitted, the line around the circle is black. Of course, (centerLeft, centerTop) is the center point of the circle, and radius is the radius.He calls it splatter painting, and you should read about how it works in the book. I used it in the following procedure to get the effect shown:
Private Sub Form_Click() Dim nIndex As Integer 'declare a loop index variable Dim nXCoord As Integer, nYCoord As Integer Dim nRed As Integer, nGreen As Integer, nBlue As Integer DrawMode = 9 Randomize 'Set up random number generator For nIndex = 1 To 32000 nXCoord = Int(Rnd(1) * frmMain.ScaleWidth) nYCoord = Int(Rnd(1) * frmMain.ScaleHeight) nRed = Int(Rnd(1) * 255) nGreen = Int(Rnd(1) * 255) nBlue = Int(Rnd(1) * 255) PSet (nXCoord, nYCoord), RGB(nRed, nGreen, nBlue) Next nIndex DrawMode = 13 End Sub
Set up form so that it starts out with a white background (as described in lecture) and place a label with the words "Hi, Mom!" as its caption. The splatters will normally cover the form, including the letters. This looks kind of dumb, so the way to avoid this (on black letters) is to change the form property
DrawMode to 9, Mask Pen. The DrawModes have different effects on how color appears when you draw, and you might want to experiment with them.The loop goes through 32,000 iterations. (Wright used only 2,000.) It is not possible to go through more than 32,767 using a standard
Integer. So, to do more iterations of splattering, you will need to enclose the "32000-loop" shown in another, outer loop.A key idea in this example is random numbers. Computers cannot generate true random numbers, because they follow instructions faithfully. But, they can generate number sequences that "look" random and that can be verified scientifically to have random properties. To use random numbers, you need to do two things: First, you must put the
Randomize command at the start of your program so the computer sets up the randomization. Second, when you want a random number, just write the function Rnd(1). The result is a random number between 0 and 1. So, the procedure above finds a random color value between 0 and 255 by the codeInt(Rnd(1)*255)
Suppose the random number from
Rnd(1) was 0.5 (which doesn’t seem too random, I suppose!), then the product would yield 127.5 Since this must be converted into a whole number, the Int function is applied to the result to throw away the fractional digits, giving 127.Dim tickTime As Integer
so that it is global to the timer routine. Next, initialize the
tickTime variable in the Form_Load() event procedurePrivate Sub Form_Load() TickTime = 0 End Sub
Finally, write some code to draw on each time tick:
Private Sub tmrMyClock() FillStyle = 0 FillColor = RGB(200, 100, 50) frmMain.Line (200 + tickTime * 200, 200)-(400 + tickTime * 200, 400), RGB(200, 100, 50), B tickTime = tickTime + 1 End Sub
Remember the line drawing command must be on a single line. Then, whenever the timer goes off, the box is drawn in the next position. Run it. Nothing happen? Did you set the
Interval on the timer? Experiment with different "speeds", smaller numbers make the timer go off more frequently, speeding up the image drawn. How do you stop it from running off the form? An If statement can be used to assure that tickTime isn’t allowed to get too large.frmMain.Cls
Cls stands for "clear screen."
Watch the FAQ and e-mail list for more graphics ideas and answers to your questions. Good luck, and have fun.