UNIT 8: A Tool for DIY

As indicated in Unit 7, our work during the holiday period is mainly a matter of the revision and application of BBC BASIC techniques already acquired. We begin with a program for calculating quantities in decorating. The actual programming skills required are admittedly elementary, but nonetheless essential: the author confesses that he wrote the program after decorating a room, in the course of which the quantities were scribbled on paper with the aid of a calculator, and as a result mistakes were made, and a long and tedious journey had to be undertaken in heavy traffic to get an extra pot of emulsion!

The program is relatively simple, leaving the student the opportunity to fine-tune and extend the details. The measurements are in metric, as there is no way of circumventing the quantities printed on tins of paint, etc. The calculation of quantities of paint is based on average examples in the author's own paint cupboard, but these vary between different types and brands, so the student will need to check out coverage as printed on paint tins, and adjust the program accordingly.

10 @%=&20209
20 REM Program for calculating quantities in decorating
30 CLS
40 INPUT' ' "Enter the length of the room in metres.",length
50 CLS
60 INPUT' ' "Enter the width of the room in metres ",width
70 CLS
80 area=length*width
90 PRINT' ' "The area of the floor, and likewise the ceiling, is ";area;"sq.metres."
100 INPUT' ' "Are you intending to replace the carpet Y/N ?",C$
110 IF C$="Y" OR C$="y"THEN PROCCARPET ELSE PROCPAINT
120 END
130 :
140 DEFPROCCARPET
150 CLS
160 INPUT' ' "Enter the cost per sq. metre of carpet ",carpsqm
170 CLS
180 carpcost=carpsqm*area
190 PRINT''"The total cost of carpet is GBP ";carpcost
200 PRINT' ' "Press any key to continue."
210 G=GET
220 CLS
230 PROCPAINT
240 ENDPROC
250 :
260 CLS
270 DEFPROCPAINT
280 PRINT' ' "The area of the ceiling is ";area;" sq.m."
290 CLS:INPUT''"Enter the coverage per litre of emulsion ",coverage_ltr
300 PRINT' ' "The ceiling will require ";area/coverage_ltr;" litres of emulsion."
310 PRINT' "Press any key to continue."
320 G=GET
330 CLS
340 INPUT' ' "Enter the height of the room ",height
350 wallarea=2*(length*height)+2*(width*height)
360 CLS
370 PRINT' ' "The area of the walls, including doors and windows, is ";wallarea;"sq.m."
380 INPUT' ' "Are you going to emulsion the walls or paper them e/p ",wallfinish$
390 IF wallfinish$="E" OR wallfinish$="e" THEN PROCEMUL ELSE PROCPAPER
400 ENDPROC
410 :
420 DEFPROCEMUL
430 CLS
440 INPUT' ' "Enter the coverage per litre of emulsion ",coverage_ltr
450 CLS
460 emulqty=wallarea/coverage_ltr
470 PRINT' ' "The emulsion required, disregarding windows and doors, is ";emulqty
480 ENDPROC
490:
520 DEFPROCGLOSS
530 INPUT "Measure the height of the door",doorheight
540 INPUT "Measure the width of the door ",doorwidth
550:
560 CLS
570 PRINT' ' "The area of the door is ";doorwidth;" sq.m."
580 CLS:INPUT' ' "Measure the height of the skirting board" ' "and enter it as a decimal fraction of " ' "a metre ",skirt
590 board=skirt*((2*length)+(2*width))
600 CLS:PRINT''"The total area to be glossed is ",doorwidth+skirt
610 ENDPROC
615 :
620 DEFPROCPAPER
630 CLS
640 INPUT' ' "Enter the coverage per roll of paper " ' "that you have chosen ",coverage
650 CLS
660 rolls=wallarea/coverage
670 PRINT ' ' "You will need ";rolls;" rolls of wallpaper."
680 ENDPROC

This program is appended as a text-file to this lesson, as DECOBAS.TXT, and you can *EXEC it straight into BBC BASIC.

Graphics for carpentry

When constructing furniture from commercially prepared furniture board, it's always a useful to be able to draw panels to size, so as to be able to visualise the result. In conventional drawing this takes a lot of time with a pencil and a ruler, and whilst elaborate software programs are available on the market, BBC BASIC can provide simple and accurate scale drawings in a short program.

At this point it would be useful to refresh your memory on the topic of graphics by revising Unit 2. We began our box 200 pixels up from the bottom of the screen and 200 pixels in. That's fine for a one-off diagram - but what happens if you want to write a program catering for rectangles of varying sizes, in which the length and the width of any given rectangle can be simply entered in a dialogue box, so as to construct the rectangle automatically?

BBC BASIC command VDU 29

One worthwile option, although it takes a certain amount of labour of concentration to follow it through, is to move the point from which you start - known as the "graphics origin" - from the bottom left of the screen to the centre (of a standard screen). If you then imagine (or draw) the x and y co-ordinates they will intersect in the centre of the screen at zero. This means, however, that the numbers below zero along either co-ordinate will then be negative.

To move the "graphics origin" to the centre, we use the BASIC command VDU 29, as follows:

VDU 29,640;512;

For technical reasons, don't forget the semi-colons, which send the number as a two-byte pair. Note also that in the program, the centre of the X co-ordinate is called XCEN and that of the Y co-ordinate YCEN. Herewith the program:

10 MODE 8
20 XCEN= 640
30 YCEN= 512
40 VDU29,XCEN;YCEN;
50 INPUT'"Enter width of box ",width
60 CLS
70 INPUT'"Enter height of box ",height
80 CLS
90 MOVE -width/2,-height/2
100 DRAW -width/2,height/2
110 DRAW width/2,height/2
120 DRAW width/2,-height/2
130 DRAW -width/2,-height/2
140 VDU 26

The program is appended to this lesson as DRAWBOX.TXT, and you can *EXEC it straight into BBC BASIC.

Left UNIT 7

UNIT 9Right


Best viewed with Any Browser Valid HTML 3.2!
© Edmund Burke 2000