The BASIC keywords COLOUR, MOVE and DRAW were introduced in Unit 2, and now need to be revised and extended through all the graphics categories of the BBC BASIC Online Manual. An enormous amount of variety can be obtained through very small changes in the simplest of structures. Turn to the section on COLOUR in the Manual. The key detail to appreciate, in getting to know this section for using dialogue boxes, is that "foreground colours" are effectively the colours available for the text. The "background colours" are then self-explanatory. Try matching and swapping different types of contrast for foreground and background colours. If you want to go methodically through all the options and sample them, herewith a short sampler program for this purpose, into which you simply enter the mode, the foreground colour and background colour:
10 REM COLOUR NAVIGATOR
20 REM F=FOREGROUND COLOUR, B=BACKGROUND COLOUR, M=MODE
30 CLS
40 INPUT "SELECT MODE",M
50 INPUT "CHOOSE FOREGROUND COLOUR",F
60 CLS
70 INPUT "CHOOSE BACKGROUND COLOUR",B
80 :
100 CLS
110 MODE M
120 COLOUR F
130 COLOUR B+128
140 PRINT''"This is foreground colour ";F
141 PRINT'"and background colour ";B
143 PRINT'"in Screen Mode ";M
You can *EXEC this program directly into BBC BASIC. You can download it as a text file, entitled COLORNAV.TXT
When you have become familiar with exploring the screen modes and colour possibilities in the manual, you can try them out on the following program, designed for timing a joint of roast meat. (Vegetarians might adapt the program to baking potatoes or pizzas.) The times are taken from an older and more detailed edition of Mrs Beeton, written in Imperial measures. The author confesses to finding these measures handier for the common sense practicality which the kitchen demands. An infuriating experience, for those who do use Imperial measures for this purpose, is the legal requirement of labelling the weight of meat in metric, which then has to be converted into Imperial with a jotter and a calculator - unless, of course, a permanent solution is found by means of a program such as the one below, into which you type the weight in metric from the supermarket label, then specify the type of meat, and obtain the roasting time automatically. This, surely is the sort of thing for which the "home computer" was originally conceived?
10 @%=&20009
20 CLS
30 PRINT''"CYBER ROASTER"
40 PRINT'"Are you cooking beef, lamb, chicken, pork or turkey (enter B/L/C/P/T)"
50 INPUT M$:IF M$="B" THEN meat$="beef"ELSE IF M$="L"THEN
meat$="lamb"ELSE IF M$="C" THEN meat$="chicken"ELSE IF M$="P"THEN
meat$="pork"ELSE IF M$="T"THEN meat$="turkey"
60 CLS
65:
70 INPUT''"Enter the weight in kg.",W
80 L=W*2.2046
90 CLS
100 PRINT'"That is ";L;" lb."
110 PRINT'"Because we are cooking ";meat$;:IF meat$="chicken" AND L<3
THEN PRINT " and the weight is under 3lb"
120 IF M$="P" THEN M=30 ELSE M=20:IF M$="C" AND L<3 THEN M=15
130 PRINT " it will be ";M;" minutes per lb. and ";M;" minutes over."
140 TM=(M*L)+M
150 H%=TM DIV 60: M%=TM MOD 60
160 PRINT'"The total cooking time is ";H%;" hr. and ";M%;" min. Press
any key when cooking starts."
170 G=GET
190 CLS
200 CLOCK$=RIGHT$(TIME$,8)
210 MIN$=LEFT$(CLOCK$,5)
220 H$=LEFT$(MIN$,2):M$=RIGHT$(MIN$,2)
230 H=VAL(H$):M=VAL(M$)
240 FH=H%+H:FM=M%+M
250 PROCtimer
260 END
265 :
270 DEFPROCtimer
280 R=FM
290 Q=R DIV 60
300 S=FH+Q
310 IF S>24 THEN S=S-24
320 NFM=R MOD 60
330 PRINT'' "The time is now ";RIGHT$(TIME$,8)
340 PRINT'"The "meat$;" is due out of the oven at ";S;":";NFM;" to
the nearest minute."
350 ENDPROC
In addition to appearing here in the text of Unit 7, the program can also be downloaded as a text-file (COOKER.TXT) which you can *EXEC into BBC BASIC. Now let us briefly run through the program and what it does. (For speed and keyboard convenience, the author prefers the older style of short variable names, but the user can choose his or her own!)
Line 10 ensures that we only have two decimal figures.
Lines 40-50 select the type of meat;
Line 80 converts kilograms to lbs.
Lines 110-139 calculate the times for different types of meat: @ 15 minutes per lb for chicken under 3lb in weight, 20 minutes for beef, lamb and chicken over 3lb, and 30 minutes for pork. You could insert a subroutine here to time the beef to rare, medium or well done settings.
Line 140 adds an extra 15,20 or 30 minutes to the minutes per lb. and gives the total cooking time in minutes.
We met the BASIC Keyword TIME$ in the bank balancing program. (If you type PRINT TIME$, the date and time will be printed out). Try it now,to remind yourself how it works. Clearly we don't need the whole of the time and date displayed, so we use string slicing operations, which you have met, to select the portion of the time statement that we need. Line 310 ensures that if you have a midnight feast, your clock will not be so ignorant as to exceed 24 hours in the day! Using your own adaptation of the timer, you can add a screen display to flash up when the meat is due out.
Here is the routine:
1. Go into DOS, as explained in the previous chapter,
2. Access BBC BASIC by means of the statement CD BBCBASIC.
3. Type MODE7 <return>. You should get the following message:
Viewdata screen emulator V1.30 now installed.
4. Go into BBC BASIC and type MODE 7 again. That should install MODE 7. If it doesn't, try contacting Richard Russell via the website - but there is no guarantee that Mode 7 will work on your own particular PC.
Assuming that MODE 7 does work, however, you will be able to use Teletext graphics as detailed below.
PRINT CHR$145 "RED"
will print the word RED in red. Then,the numbers 146,147,148,149 and 150 respectively, preceded by CHR$, give green, yellow, blue, magenta and cyan. It is also possible to mix foreground text and background colour by using CHR$, as you will see in the manual.(The number following CHR$ refers to the ASCII code.) As an illustration of its use, herewith a sample dialogue box from an invoice program used for private tuition in languages.
90 PRINT:PRINTCHR$(132);CHR$(157):PRINTCHR$(132);CHR$(157);CHR$(135); "Enter the client (parent if minor)"
100 PRINT CHR$(132);CHR$(157)
110 PRINT CHR$(135);CHR$(157);CHR$(132);:INPUT N$
120 PRINT CHR$(132);CHR$(157):PRINTCHR$(132);CHR$(157);CHR$(135);"Enter the name of the student"
130 PRINT CHR$(132);CHR$(157)
140 PRINT CHR$(135);CHR$(157);CHR$(132);:INPUT STU$
150 PRINT CHR$(132);CHR$(157):PRINTCHR$(132);CHR$(157);CHR$(135);"Enter the language "
160 PRINT CHR$(132);CHR$(157)
170 PRINT CHR$(135);CHR$(157);CHR$(132);:INPUT L$
180 PRINT CHR$(132);CHR$(157):PRINTCHR$(132);CHR$(157);CHR$(135);"Enter the date of the first lesson "
190 PRINT CHR$(132);CHR$(157)
200 PRINT CHR$(135);CHR$(157);CHR$(132);:INPUT K$
210 PRINT CHR$(132);CHR$(157):PRINTCHR$(132);CHR$(157);CHR$(135);"Enter the date of issue "
220 PRINT CHR$(132);CHR$(157)
230 PRINT CHR$(135);CHR$(157);CHR$(132);:INPUT O$
240 CLS
250 PRINT CHR$(132);CHR$(157):PRINTCHR$(132);CHR$(157);CHR$(135);"Enter the number of lessons @ 1 hour ";
260 PRINT CHR$(132);CHR$(157)
270 PRINT CHR$(135);CHR$(157);CHR$(132);:INPUT N
280 PRINT CHR$(132);CHR$(157):PRINTCHR$(132);CHR$(157);CHR$(135);"Enter the charge-band:"
290 PRINT CHR$(132);CHR$(157)
300 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"1=separate"
310 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"2=set of six"
320 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"3=set of twelve"
330 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"4=intensive"
340 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"5=pair"
350 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"6=group of three "
360 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"7=group of four to six "
370 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"8=in-company group"
380 PRINT CHR$(132);CHR$(157);CHR$(131);TAB(10)"9=special arrangement"
390 PRINT CHR$(132);CHR$(157)
400 PRINT CHR$(135);CHR$(157);CHR$(132);:INPUT X
It could, of course, be adapted to any other kind of dialogue box using Mode 7, and it would be worth while experimenting with the range of possibilities offered by the manual.
UNIT 6 |
UNIT 8 |