



It's so easy! If you're a beginner programmer, this is a nice problem to try especially once you've learned about inputting data and doing calculations. The solution I'm going to present now is a really straightforward one; the kind that a computer science teacher might show to his or her class. First off, we need to know the shape of the table top. Once that information is entered, we can determine what type of dimensions to ask from the user. If the shape is circular, we need the diameter of the table in feet. If the shape is rectangular, we program should ask for the the length and width of the table in feet. Whatever the shape of the table, we need the thickness of the table top in inches. Once we have these data, we can use the given equation to give the estimate cost of the table top and the estimate cost of the whole table. Finally, we print the costs and ask the user whether he or she wants a new estimate. The shape of things to come. To do the first part, (asking the shape of the table), we can simply display the choices (as in a menu) and let the user enter the letter of his or her choice:
The variable Shape should now contain a number representing one of the two shapes. The dimensions of the table. Depending on the shape of the table, it wi
Take note that the variable I used to copy the value of TIMER is in Long Integer format (instead of just Integer). Find the reason why? Now you know how to extract those things. But that is not what we want. (Haha.) We still need the fractional parts of their value. Why? If we just got the integral parts, the clock hands will point at discrete directions. What I mean is, if the time is 4:30, the hour hand will point at four, instead of between four and five. See what I mean? So the correct code should be:
Here, we made the second value an integer value. If you want it to have fractional values so that the second hand will move continuously instead of jumping every second, you can do so. The reason why I made it that way is so that we just have to update the clock display every second, instead of continuously (which could be flickery). I've noticed that there's no easy way to get the value for the minutes. I just made it so that I extract the integer value and then I just add the fraction of the minute depending on the second value. By the way, you may notice that we reduced the hour value to 12hour format instead of the usual 24hour format since the hour hand makes a complete revolution every 12 hours (actually, it won't really matter in some applications, but we might use a specific range of angles through lookup tables and such...). Converting to the angles. Now that we have the time values in their respective variables, we can now find the angles corresponding to each value. For convenience, we'll redefine the angular system so that 0° points up, to the 12 o'clock position, and the angle values increase in the clockwise direction. So 90° points to the 3 o'clock position, 180° points at 6 o'clock, and so on. I said that the screen mode we should use is SCREEN 12. Well, I plan on not changing the screen coordinate system, which is just like the Cartesian Coordinate System flipped along the xaxis (i.e., the positive x direction goes to the right and the positive y direction goes downwards). And I plan on using the trigonometric functions to convert the angle to the appropriate rectangular coordinates. So my xcoordinate function would be sine (with respect to my choice of angular system) and my ycoordinate function would be negative cosine. Figure out why. With those things out of the way, let's now proceed with the timevaluetoangle functions. By simple computation, we find out that the hour hand moves 30° every hour, while the minute and second hands both move 6° every minute and every second respectively. So we just multiply their corresponding unit interval angle with their values. We also convert the angles to radians since we'll be using the trig functions.
Voila! Now we're through getting the angles! Displaying the clock. The next process is to display the clock. What I'm going to do here is to show a very simple display. The clock would be centered on the screen. It's border will be a circle with a radius of 200 pixels. The hands will just be lines radiating from the center, with the hour hand having a length of 120 pixels, the minute hand 180 pixels, and the second hand 190 pixels. Our center pixel is (320, 240). To make sure that we update the the clock every second instead of continuously, we just do a looping check for the integral value of TIMER and redraw the clock whenever the value changes.
Here is code to draw the hands given the angles:
Why we still put the coordinates in their own variables will be apparent when we update the clock. Before, we can update the clock, we need to erase the hands first and it would be faster to erase the hands by redrawing over them with the background color instead of doing a CLS. Here's the complete program with all the parts added and combined:
Here's a sample output: I took this screenshot at around 10:15 pm. A little bit of fancy. That clock display looks very boring. Lets spice it up a little by adding second tick marks on the border and by extending the hands in the other direction by 30 pixels. Here's the revised code (I've highlighted the changes):
Here's the output to that program. The modifications I made to the program deal with drawing the second tick marks around the border and the addition of six new variables to track the position of the other endpoint of every hand. Looks better, doesn't it? 




Try creating more fancier clock displays! If you'll download the B3 Zip file, you'd find the previous two programs plus one more program showing the possibilities. 
Go back to the Case Study page. Home Page  Program Nook  Instructional  Open Forum Portfolio  Visitor's Area  Connections  About the Site Copyright © 19971999, SEAV Softwares. All rights reserved. Webmaster: Eugene Villar (SEAV); email: [email protected] 