SB BBC @ GBR Oldie hints/tips #052-057 Hints and tips from the archives of Wakefield BBC Micro User Group... 52. Drawing circles and discs ~~~~~~~~~~~~~~~~~~~~~~~~~ This is a Procedure for drawing circles or solid discs of any size, anywhere on the screen. You call the Procedure by specifying the X co-ordinate, (0-1279), and the Y co-ordinate, (0-1023), of the centre, plus the radius, and lastly a "C" for circle or "D" for disc. The graphics origin is set back to 0,0 after the circle is drawn, but you can stop this by omitting the VDU29 statement in line 150, if you wish. The example uses Mode 4, but any graphic Mode is suitable. 10 MODE4:PROCcircle(639,511,400,"C"):PROCcircle(639,511,300,"D") 20 END 100 DEFPROCcircle(X%,Y%,R%,T$):LOCAL Q 110 VDU29,X%;Y%;:FORQ=0 TO PI*41/20 STEP PI/20 120 X%=R%*COS(Q):Y%=R%*SIN(Q) 130 IF Q=0 THEN MOVE X%,Y% ELSE IF T$="C" THEN DRAW X%,Y% ELSE MOVE 0,0:PLOT 85,X%,Y% 140 NEXT:VDU29,0;0;:ENDPROC (NB: The Master/Compact have ready-made circle/disc routines) 53. String formatting ~~~~~~~~~~~~~~~~~ A statement such as < PRINT A$, > doesn't do what you would expect, and that < PRINT A$,; > is needed to prevent an unwanted linefeed. If you try the first program below, you will see that this only works for 27 passes of a FOR-NEXT loop, after which odd things happen. The simplest cure is probably to pad the string out with spaces, and not use commas at all. Note that two line 100's are given, and they each give a slightly different effect, depending on whether you want to pad the string at the beginning or the end. You can change the figure 10 in line 100 to 4,5,10,20 etc., ie. something that will divide into the screen width of 20,40 or 80. 10 A$="ABCD":FOR S%=1 TO 60:PRINT A$,;:NEXT:PRINT 10 A$="ABCD":FOR S%=1 TO 60:PRINT FNpad(A$);:NEXT:PRINT:END 100 DEF FNpad(x$):=x$+STRING$(10-LEN(x$)," ") 100 DEF FNpad(x$):=STRING$(10-LEN(x$)," ")+x$ 54. Capitals conversion ~~~~~~~~~~~~~~~~~~~ This is a Function for converting a string to all upper-case letters; figures and punctuation are not affected. This saves you having to test for, say, "YES" and "yes", in response to a keyboard input. To make sure a string is all capitals, just use A$=FNcaps(A$) . By making the alterations suggested in the REM statement, you can make it change to lower-case instead. 100 DEF FNcaps(text$):LOCAL letter%,char%,result$ 110 FOR letter%=1 TO LEN(text$) 120 char%=ASC(MID$(text$,letter%,1)) 130 IF char%>96 AND char%<123 THEN char%=char%-32 140 REM change 96 to 64, 123 to 91, and -32 to +32 150 result$=result$+CHR$(char%):NEXT:=result$ 55. Tab command ~~~~~~~~~~~ When you are using the simple TAB(X) command, you will find that items already printed to the left are liable to be blanked out. This is a mixed blessing, and can be avoided by using the full TAB(X,Y) syntax. However, this can be inconvenient at times, but you will find that using TAB(X,VPOS) can be used instead in most cases. Try using TAB(20,VPOS) instead of TAB(20) in the example. 10 PRINT"HELLO":pause=INKEY(200):VDU11 20 PRINT TAB(20)"THERE" 56. Altering the cursor ~~~~~~~~~~~~~~~~~~~ It is possible to alter the size and flash rate of the cursor in all screen Modes, and to turn it off, with the command: VDU23;10,N,0;0;0; where N is made up by adding together two numbers. The first controls the flashrate, and you must pick one of the following... 0=steady 32=invisible 64=fast_flash 96=slow_flash (default is 96) The second controls the size, and you may have anything from a thick block, which is 0 in all Modes, to a thin line, which is 7 in Modes 0,1,2,4 & 5, 9 in Modes 3 & 6, and 18 in Mode 7, (default is 7 in Modes 0-6, and 18 in Mode 7). ie. 0=thick block in all modes 7=thin line in modes 0,1,2,4,5 (default 7) 9=thin line in modes 3,6 (default 7) 8=thin line in mode 7 (default 18) Thus N=105 (96+9) would give you a thinner cursor in Modes 3 & 6, and N=0 would give you a non-flashing solid block in all Modes. A Mode change will reset the cursor, and it can still be turned on and off with the usual commands. 57. Reversing flags ~~~~~~~~~~~~~~~ It is often necessary to use "flags" in a program. Eg. IF male%=TRUE THEN PRINT "Hello Sir" ELSE PRINT "Hello Madam" where male% is a flag to indicate the sex of the user. If you need to reverse the polarity of the flag, (ie change it from TRUE to FALSE and vice-versa), you could use: IF flag%=TRUE THEN flag%=FALSE ELSE flag%=TRUE However, this can be done much more simply, with: flag%=NOT(flag%) 73 Rick G4BLT @ GB7WRG