Programmer’s Reference Guide - FUZE BASIC · This reference guide aims to provide a comprehensive...
Transcript of Programmer’s Reference Guide - FUZE BASIC · This reference guide aims to provide a comprehensive...
2
Introduction
Immediate Mode Commands
Functions, Constants & Procedures
Joystick and Gamepad commands
Keycodes (scanKeyboard)
Notes & Octaves for Sound command
For new commands, features and projects visit;
www.fuze.co.uk
Published in the United Kingdom ©2016 - 2016 FUZE Technologies Ltd. FUZE, FUZEBASIC, FUZE logos, designs, documentation and associated materials are Copyright FUZETechnologies Ltd.No part of this document may be copied, reproduced and or distributed without writtenconsent from FUZE Technologies Ltd. All rights reserved. The Arduino brand, Arduinologo and design of their boards are copyright of Arduino LLC. Any other brand names arethe copyright of their respective owners.
With many thanks and a great deal of respect to Gordon Henderson for his work on RTB where FUZEBASIC originated.
FUZE BASIC is developed by FUZE Technologies Ltd in the UK. The team consists of;
Jon Silvera - Project managerLuke Mulcahy - Lead programmerMike Green - Code contributor & Technical consultantDavid Silvera - FUZE Product managerColin Bodley - DocumentationAdditional information – www.fuze.co.uk
Manual Version: Date: 7th July 2016 FUZE BASIC Version: 3.6
3
4
12
133
134
135
Programmer’s Reference Guide
3
main index
IntroductionThis reference guide aims to provide a comprehensive anddetailed explanation of every command in the FUZE BASIClibrary.
It is an evolving document because FUZE BASIC is constantlybeing updated and improved. To download the latest versionplease visit the resources section on the www.fuze.co.uk website.
FUZE BASIC is currently available for Microsoft Windows®,Raspberry Pi, The FUZE and Linux. We hope to add Android inthe coming months and possibly Mac OSx & iOS versions too.
Listed alongside each command is a series of operating systemicons highlighted to show which OS the command is compatiblewith. For example;
ANALOGREAD
The direct analog commands require the FUZE IO Board becauseit has a built in analog chip whereas the Raspberry Pi does nothave one as standard.
SENSEPLOT
..because this command will work on a standalone Pi and a FUZEwith a senseHAT connected.
Installing FUZE BASIC
For details on installing and getting started we highly recommendyou begin with the FUZE BASIC Project Workbook which can bedownloaded for free from the FUZE website.
The website also has many other tutorials, examples and projects.You are encouraged to contribute more to help fellow codingstudents.
Introduction
displays
displays
Community
We really hope you enjoy using FUZE BASIC as much as we do.
If you find yourself becoming quite proficient at FUZE BASIC thenwhy not show off er.. share your work on the FUZE website. At thevery least you’ll be helping others to progress.
Many thanks from teamFUZE
Using FUZE BASIC with an Arduino / Genuino
FUZE BASIC will only recognise an Arduino device once the driversoftware has been installed. Please visit the official Arduinowebsite at https://www.arduino.cc and download / install thelatest version.
Once installed FUZE BASIC will ask if you want to prepare it foruse. It will do this with any new unit or existing ones where youmight have installed a none FUZE BASIC application.
4
main indexImmediate mode Commands
4
5
5667788889999
10101111
CD
CHAIN
CLEARCLSCONTCONTINUEDIREDITEXITLISTLISTGAMEPADSLOADLOOKNEWRUNSAVETROFFTRONVERSION
CDPurposeChange the current directory
SyntaxCD foldername
DescriptionChange the current folder to the one specified.
Example
CD fuzebasic Switch to the folder named fuzebasic. This must be in the current folder towork.
CD .. Go back to the parent folder ( CD ../.. will go back two folders.)
CD / Go back to root folder.
AssociatedPWD, LS, LOAD, SAVE, CHAIN, DIR
5
main indexImmediate mode Commands
CLEARPurposeClear variable memory.
SyntaxCLEAR
DescriptionClears all variables and deletes all arrays. It also removesany active sprites from the screen. Stopped programs maynot be continued after a CLEAR command.
ExampleREM Immediate ModeVARIABLE=10PRINT VARIABLECLEARREM Unassigned variable error!PRINT VARIABLE
AssociatedNEW
CHAINPurposeLoad a program into memory and immediately execute it.
SyntaxCHAIN filename$
DescriptionLoads in a program from the local non-volatile storage. As withSAVE, you need to supply the filename without any quotes. Donot include the .fuze file extension. Note, if your filename hasspaces then you must enter it within quoatation marks. CHAIN"my game" for example.
The program will start automatically as soon as it loads.
ExampleREM Immediate ModeCHAIN demos/ballRUN
AssociatedLOAD, SAVE, NEW
6
main indexImmediate mode Commands
CLSPurposeClear the video display screen.
SyntaxCLS
DescriptionClears the video display screen and places the cursor inthe top left corner. The background is set to the currentbackground (PAPER) colour.
ExamplePAPER=WHITEINK=BLACKCLSPRINT "Hello World"END
AssociatedCLS2, INK, PAPER, UPDATE
CONTPurposeContinue running a program that has beenstopped.
SyntaxCONT
DescriptionContinues program execution after a STOPinstruction.Variables are not cleared.
ExampleREM Immediate modeCONT
AssociatedSTOP
7
main indexImmediate mode Commands
CONTINUEPurposeContinue a loop.
SyntaxCONTINUE
DescriptionWill cause the loop to re-start at the line containing theLOOP instruction, continuing a FOR instruction and re-evaluating any WHILE or UNTIL instructions.
ExampleREM Prints 1 to 10 but skips over 5FOR I=1 to 10 LOOP
IF (I=5) THEN CONTINUEPRINT I
REPEATEND
AssociatedBREAK, LOOP, LOOP REPEAT, FOR REPEAT, REPEATUNTIL, UNTIL REPEAT, WHILE REPEAT
DIRPurposeList FUZE BASIC program files in the current or specifieddirectory.
SyntaxDIR [directory]
DescriptionLists the program files in your current working directory orthe optional specified directory. These will have the .fuzefile extension.
ExampleREM Immediate ModeDIR
AssociatedLOAD, SAVE
8
main index
LISTGAMEPADSPurposeTo display any connected joysticks and gamepads.
SyntaxLISTGAMEPADS
DescriptionThis lists, by name, any attached joystick devices that are currentlyconnected via USB or wireless USB, if supported by the OS.
ExampleREM Immediate ModeLISTGAMEPADS
Immediate mode Commands
LISTPurposeList the program stored in memory to the screen.
SyntaxLIST
DescriptionThis lists the program stored in memory to the screen. You can pausethe listing with the space-bar and terminate it with the ESC key.
EDITPurposeEdit the program in memory.
SyntaxEDIT
DescriptionEdits the program in memory using a full screen editor.
ExampleREM Immediate modeEDIT
EXITPurposeExit FUZE BASIC and return to the environment.
SyntaxEXIT
DescriptionExit FUZE BASIC and return to the environment you started it in.
ExampleREM Immediate modeEXIT
9
main index
NEWPurposeStart a new program
SyntaxNEW
DescriptionDeletes the program in memory. There is no verification andonce it’s gone, it’s gone. Remember to save first!
AssociatedCLEAR
RUNPurposeRuns the program in memory.
SyntaxRUN
DescriptionRuns the program in memory. Note that using RUN willclear all variables.
ExampleREM Immediate ModeRUN
Immediate mode Commands
LOADPurposeLoad a program into memory.
SyntaxLOAD filename$
DescriptionLoads in a program from the local non-volatile storage. As withSAVE, you need to supply the filename without any quotes. Donot include the .fuze file extension. Note, if your filename hasspaces then you must enter it within quoatation marks. LOAD"my game" for example.
ExampleREM Immediate ModeLOAD demos/ballRUN
AssociatedSAVE
LOOKPurpose
Not much at all
SyntaxLOOK
DescriptionErm…
10
main index
SAVEPurposeSaves your program to the local non-volatile storage.
SyntaxSAVE filename$
DescriptionSaves your program to the local non-volatile storage. Thefilename$ is the name of the file you wish to save andmay not contain spaces. If you have already saved a file,then you can subsequently execute SAVE without thefilename and it will overwrite the last file saved. (This isreset when you load a new program or use the NEWcommand)
ExampleREM Immediate ModeSAVE testprog
AssociatedLOAD
TROFFPurposeDisables TRON
SyntaxTROFF
DescriptionIf TRON is enabled then TROFF switches it off.
ExampleREM Immediate ModeTROFF
AssociatedTRON
Immediate mode Commands
11
main index
TRONPurposeEnables TRON mode for debugging.
SyntaxTRON
DescriptionSwitching TRON on has a very dramatic effect. Running yourprogram when TRON is enabled displays a section of code onscreen to show exactly which line is being executed.
You can adjust TRON settings with the following controls;
CTRL+ UP / DOWN to change speedCTRL+ LEFT to Pause (hold down)CTRL+ LEFT + RIGHT to stepCTRL+ RIGHT toggle transparentCTRL+ SHIFT + UP toggle TRON displayCTRL+ PAGEUP increase number of lines displayedCTRL+ PAGEDOWN decrease number of lines displayedCTRL+ SHIFT + PAGEUP move TRON display upCTRL+ SHIFT + PAGEDOWN move TRON display down
ExampleREM Immediate ModeTROFF
AssociatedTRON
VERSIONPurposePrint the current version of FUZE BASIC.
SyntaxVERSION
DescriptionPrint the current version of FUZE BASIC.
ExampleREM Immediate ModeVERSION
Immediate mode Commands
12
main indexFunctions, Constants & ProceduresABSACOSADVANCESPRITEANALOGREADANALOGWRITEARDUINODIGITALREADARDUINODIGITALWRITEARDUINOPINMODEARDUINOANALOGWRITEARDUINOANALOGREADARMBODYARMELBOWARMGRIPPERARMLIGHTARMRESETARMSHOULDERARMWRISTASCASINATANBREAKCHR$CIRCLECLEARKEYBOARDCLOCKCLONESPRITECLOSECLSCLS2
COLOURCOPYREGIONCOSLOOPLOOP REPEATDATADATE$DEF FNDEF PROCDEFCHARDEGDIGITALREADDIGITALWRITEDIMDRCANALOGREADDRCCLOSEDRCDIGITALREADDRCDIGITALWRITEDRCOPENDRCPINMODEDRCPWMWRITEELLIPSEELSEENDENDIFENDPROCENVELOPEEOFEXP
FADEOFFFADEONFADINGFALSEFFWDFNFONTSIZEFOR LOOPFREEIMAGEFULLSCREENGETGET$GETIMAGEHGETIMAGEWGETMOUSEGETPIXELGETPIXELRGBGETSPRITEANGLEGETSPRITEHGETSPRITEWGETSPRITEXGETSPRITEYGHEIGHTGRABREGIONGWIDTHHIDESPRITEHLINEHTABHVTABIF THENINK
INKEYINPUTINPUT#INTLEFTLEFT$LENLINELINETOLOADIMAGELOADMUSICLOADSAMPLELOADSPRITELOCALLOGMAXMICROTIMEMID$MINMODE7PLOTIMAGEMODE7PLOTSPRITEMOUSEOFFMOUSEONMOUSEXMOUSEYMOVEMOVETONEWSPRITENUMFORMATOPENORIGIN
1414151516161717181819192020212122222323242425252626272728
2829303031313233333434353536373738383939404041414242434444
45454646474748484949505051515252535354545555565657575858595960
60616162626363646465656666676768686969707071717272737374757576
13
main index
SENSELINESENSEPLOTSENSEPRESSURESENSERECTSENSERGBCOLOURSENSESCROLLSENSETEMPERATURESENSEVFLIPSETCHANVOLSETMODESETMOUSESETMUSICVOLSETSPRITEALPHASETSPRITEANGLESETSPRITEFLIPSETSPRITEORIGINSETSPRITESIZESETSPRITETRANSSGETSGET$SGNSHOWKEYSSINSOFTPWMWRITESOPENSOUNDSPACE$SPRITECOLLIDESPRITECOLLIDEPPSPRITEOUTSPUT
REWINDRGBCOLOURRIGHTRIGHT$ROTATEIMAGERNDSAVEREGIONSAVESCREENSCALEIMAGESCANKEYBOARDSCLOSESCROLLDOWNSCROLLLEFTSCROLLRIGHTSCROLLUPSEEDSEEKSENSEACCELXSENSEACCELYSENSEACCELZSENSECLSSENSECOMPASSXSENSECOMPASSYSENSECOMPASSZSENSEGETRGBSENSEGYROXSENSEGYROYSENSEGYROZSENSEHEIGHTSENSEHFLIPSENSEHUMIDITY
PAPERPAPEROFFPAPERONPAUSECHANPAUSEMUSICPENDOWNPENUPPIPI2PINMODEPLAYMUSICPLAYSAMPLEPLOTPLOTIMAGEPLOTSPRITEPOLYENDPOLYPLOTPOLYSTARTPLOTTEXTPRINTPRINT#PRINTATPROCPWMWRITERADREADRECTREPEAT UNTILRESTORERESUMECHANRESUMEMUSIC
SPUT$SQRTSREADYSTOPSTOPCHANSTOPMUSICSTR$SWAPSWITCHTANTANGLETHEIGHTTIMETIME$TONETRIANGLETRUETWIDTHUPDATEMODEUNTIL REPEATUPDATEVALVLINEVTABWAITWHILE REPEAT
76777778787979808080818182828383848485858686878788888989909091
919292939394949595969697979797989899999999
100100100100101101101101102102
103103104104105105106106107107108108109109110110111111112113113114114115115116116117118119119
120120121121122122123123124125125126126127127128128129129130130131131132132133
Functions, Constants & Procedures
14
main index
ABSPurposeReturn the absolute value of the argument.
Syntaxpositivenumber=ABS(number)
DescriptionReturns the absolute value of the supplied argumentnumber i.e. If the argument is negative, make it positive.
ExamplePRINT FN ElapsedYears(1966,2013)PRINT FN ElapsedYears(2013,1966)ENDREM Return Number of years elapsedREM Between two datesDEF FN ElapsedYears(Year1, Year2)=ABS(Year1-Year2)
AssociatedSGN
ACOSPurposeReturns the arc cosine of the supplied argument.
Syntaxangle=ACOS(cosine)
DescriptionThis is the inverse of the COS function returning the anglefor a given cosine.
ExamplePRINT "Angle with cosine = 0.5: "DEGREM 60 DegreesPRINT "In Degrees: ";ACOS(0.5)RADREM PI/3 RadiansPRINT "In Radians: "; ACOS(0.5)CLOCKPRINT "In Minutes: "; ACOS(0.5)END
AssociatedATAN, COS, SIN, TAN
Functions, Constants & Procedures
15
main index
ADVANCESPRITEPurposeAdvances a sprite a specified amount
SyntaxADVANCESPRITE( sprite, distance )
DescriptionMoves a sprite forward by the specified distance. Thedirection is set by the SETSPRITEANGLE function. This is veryuseful when used with rotating sprites.
Examplepic = NEWSPRITE( 1 )LOADSPRITE("logo.bmp", pic,0)PLOTSPRITE( pic, gWidth / 2, gHeight / 2, 0 )FOR angle = 0 TO 360 LOOPSETSPRITEANGLE( pic, angle )ADVANCESPRITE( pic, 5 )UPDATEREPEATEND
AssociatedPLOTSPRITE, SETSPRITEANGLE
ANALOGREADPurposeReturns the value from an analog input.
SyntaxANALOGREAD(0)
Description
Returns the a value of between 0 and 255 (0V & 3.3V) from thespecified analog pin. There are four inputs, 0 to 3.
ExampleREM Attach an LDR to 3.3V and analog pin 0PRINT analogRead(0)REM cover the LDR and run again.END
AssociatedANALOGREAD, ANALOGWRITE, ARDUINOANALOGREAD,ARDUINOANALOGREAD
Functions, Constants & Procedures
16
main index
ARDUNIODIGITALREADPurposeReturns the value from a digital input from an Arduinocompatible device
SyntaxARDUINODIGITALGREAD(2)ADNALOGREAD(2)
Description
Returns a value of 1 or 0 from the specified digital pindepending on the the signal being hi or low.
ExampleCLSAPINMODE (2, 1)ADWRITE (2, NOT ADREAD (2))PRINT ADREAD (2)END
AssociatedDIGITALREAD, DIGITALWRITE, ARDUINODIGITALWRITE
ANALOGWRITEPurposeSends a value to the analog output.
SyntaxANALOGWRITE(0,value)
Description
Sends a voltage between 0V and 3.3V (as a value of 0 to 255) toanalog pin 0. There is one analog output.
ExampleREM Attach an LED to analog OUT pin 0 (the longer leg) and theshorter leg to GNDLOOPFOR volt= 0 TO 255 LOOPanalogWrite(0,volt)REPEATREPEATEND
AssociatedANALOGREAD, ANALOGWRITE, ARDUINOANALOGREAD,ARDUINOANALOGWRITE
Functions, Constants & Procedures
ARDUNIOPINMODEPurposeConfigure the mode of a digital pin on an Arduino compatibledevice.
SyntaxARDUINOPINMODE(pinno,pinmode)APINMODE(pinno,pinmode)
DescriptionConfigures the mode of a pin on the Pi’s GPIO. It takes anargument which specifies the mode of the pin - input, output orPWM output. The modes are:
0 pinINPUT1 pinOUTPUT
ExampleCLSAPINMODE (2, 1)ADWRITE (2, NOT ADREAD (2))PRINT ADREAD (2)END
AssociatedPINMODE, SOFTPWMMODE, ARDUINOPINMODE
ARDUNIODIGITALWRITEPurposeSet the state of a digital pin on an Arduino compatible device.
SyntaxARDUINODIGITALWRITE(pinno,pinvalue)ADWRITE(pinno,pinvalue)
DescriptionThis procedure sets a digital pin to the supplied value - 0 for offor 1 for on. As with DigitalRead, you may need to set the pinmode (to output) beforehand.
ExampleCLSAPINMODE (2, 1)ADWRITE (2, NOT ADREAD (2))PRINT ADREAD (2)END
AssociatedDIGITALREAD, DIGITALWRITE, ARDUINODIGITALREAD
Functions, Constants & Procedures main index
17
ARDUNIOANALOGWRITEPurposeWrite a value to an analog output on an Arduino compatibledevice.
SyntaxARDUINOANALOGWRITE( 0 )AAWRITE( 0 )
Description
Send a value between 0 and 1023 depending on the outputrequired.
ExampleREM Attach an LED (5V) to digital pin 11 and GND on anArduino compatible device.CLSAPINMODE (11, 1)LOOPFOR v=0 TO 1023 LOOPAAWRITE (11,v)REPEATREPEATEND
AssociatedANALOGREAD, ANALOGWRITE, ARDUINOANALOGREAD,
ARDUNIOANALOGREADPurposeReturns the value from an analog input on an Arduinocompatible device.
SyntaxARDUINOANALOGREAD( 0 )AAREAD( 0 )
Description
Returns a value between 0 and 1023 depending on the currentattached to an analog pin on an Arduino compatible device.
ExampleREM Attach an LDR (leg 1) to GND and (leg 2) to analog pin 0and then a 10k resistor from (leg 2) to 5V.
LOOPPRINTAT ( 0, 0 ); AAREAD(0); “ “REPEATEND
AssociatedDIGITALREAD, DIGITALWRITE, ARDUINODIGITALWRITE
Functions, Constants & Procedures main index
18
ARMBODYPurposeMove the robot arm body.
SyntaxARMBODY(direction)
DescriptionActivates the motor in the base of the robot armaccording to the direction argument as follows:
1 Move clockwise0 Stop-1 Move anti-clockwise.
ExampleREM Move the body for 2 seconds clockwiseARMBODY(1)WAIT(2)ARMBODY(0)END
AssociatedARMELBOW, ARMGRIPPER, ARMLIGHT, ARMRESET,ARMSHOULDER, ARMWRIST
Functions, Constants & Procedures
ARMELBOWPurposeMove the robot arm elbow.
SyntaxARMELBOW(direction)
DescriptionActivates the motor in the elbow of the robot armaccording to the direction argument as follows:1 Move clockwise0 Stop-1 Move anti-clockwise.
ExampleREM Move the elbow for 1s anti-clockwiseARMELBOW(-1)WAIT(1)ARMELBOW(0)END
AssociatedARMBODY, ARMGRIPPER, ARMLIGHT, ARMRESET,ARMSHOULDER, ARMWRIST
main index
19
20
main index
ARMGRIPPERPurposeOpen or close the robot arm gripper.
SyntaxARMGRIPPER(direction)
DescriptionActivates the motor in the gripper of the robot armaccording to the direction argument as follows:1 Open gripper0 Stop-1 Close gripper
ExampleREM Open the gripper for 1 secondsARMGRIPPER(1)WAIT(1)ARMGRIPPER(0)END
AssociatedARMBODY, ARMELBOW, ARMLIGHT, ARMRESET,ARMSHOULDER, ARMWRIST
Functions, Constants & Procedures
ARMLIGHTPurposeSwitch the robot's LED on or off.
SyntaxARMLIGHT(switch)
DescriptionIf the switch argument is 1 then the LED is illuminated andif it is 0 it is switched off.
ExampleREM Flash the LED with 1 second intervalLOOP
ARMLIGHT(1)WAIT(1)ARMLIGHT(0)WAIT(1)
REPEAT
AssociatedARMBODY, ARMELBOW, ARMGRIPPER, ARMRESET,ARMSHOULDER, ARMWRIST
21
main index
ARMRESETPurposeReset the robot arm.
SyntaxARMRESET
DescriptionStops any moving motors on the robot arm and switchesoff the LED.
ExampleARMLIGHT(1)ARMELBOW(1)WAIT(2)ARMRESETEND
AssociatedARMBODY, ARMELBOW, ARMGRIPPER, ARMLIGHT,ARMSHOULDER, ARMWRIST
Functions, Constants & Procedures
ARMSHOULDERPurposeMove the robot arm shoulder.
SyntaxARMSHOULDER(direction)
DescriptionActivates the motor in the shoulder of the robot armaccording to the direction argument as follows:1 Move clockwise0 Stop-1 Move anti-clockwise.
ExampleREM Move shoulder for 1s clockwise & backARMSHOULDER(1)WAIT(1)ARMSHOULDER(-1)WAIT(1)ARMSHOULDER(0)END
AssociatedARMBODY, ARMELBOW, ARMGRIPPER, ARMLIGHT,ARMRESET, ARMWRIST
22
main index
ARMWRISTPurposeMove the robot arm wrist.
SyntaxARMWRIST(direction)
DescriptionActivates the motor in the wrist of the robot armaccording to the direction argument as follows:1 Move clockwise0 Stop-1 Move anti-clockwise.
ExampleREM Move wrist for 1s clockwise & backARMWRIST(1)WAIT(1)ARMWRIST(-1)WAIT(1)ARMWRIST(0)END
AssociatedARMBODY, ARMELBOW, ARMGRIPPER, ARMLIGHT,ARMRESET, ARMSHOULDER
Functions, Constants & Procedures
ASCPurposeReturn the ASCII code for a string character.
Syntaxasciicode=ASC(string$)
DescriptionReturns the ASCII value represented by the first character ofstring$ e.g. "A" would return 65. It is the opposite of the CHR$function.
Examplecode=ASC("A")PRINT "ASCII value of letter A is: "; codePRINT "ASCII char of code 65: "; CHR$(code)END
AssociatedCHR$
23
main index
ASINPurposeReturns the arc sine of the supplied argument.
Syntaxangle = ASIN(sine)
DescriptionThis is the inverse of the SIN function returning the anglefor a given sine.
ExamplePRINT "Angle with sine = 0.5: "DEGREM 30 DegreesPRINT "In Degrees: ";ASIN(0.5)RADREM PI/6 RadiansPRINT "In Radians: ";ASIN(0.5)CLOCKPRINT "In Minutes: ";ASIN(0.5)END
AssociatedACOS, ATAN, COS, SIN, TAN
Functions, Constants & Procedures
ATANPurposeReturns the arc tangent of the supplied argument.
Syntaxangle=ATN(tangent)
DescriptionThis is the inverse of the TAN function returning the anglefor a given tangent.
ExamplePRINT "Angle with tangent equal to 1: "DEGREM 45 DegreesPRINT "In Degrees: ";ATAN(1)RADREM PI/4 RadiansPRINT "In Radians: ";ATAN(1)CLOCKPRINT "In Minutes: ";ATAN(1)END
AssociatedACOS, ASIN, COS, SIN, TAN
24
main index
BREAKPurposeProvide an early exit from a loop.
SyntaxBREAK
DescriptionTerminates a loop before the terminating condition ismet.
ExampleREM Loop until the space bar is pressedPRINT "Press the space bar to continue"LOOP
IF INKEY=32 THEN BREAKREPEATEND
AssociatedCONTINUE, LOOP, LOOP REPEAT, FOR REPEAT, REPEATUNTIL, UNTIL REPEAT, WHILE REPEAT
Functions, Constants & Procedures
CHR$PurposeReturns the string character for the specified ASCII code.
Syntaxcharacter$=CHR$(asciicode)
DescriptionReturns a one-character string consisting of the charactercorresponding to the ASCII code indicated by the asciicodeargument. This is the opposite of the ASC function.
ExamplePRINT "The following print the letter A"PRINT CHR$(65)PRINT CHR$(ASC("A"))PRINT "The following print the number 3"PRINT CHR$(51)PRINT CHR$(ASC("0") + 3)END
AssociatedASC
25
main indexFunctions, Constants & Procedures
CIRCLEPurposeDraw a circle on the screen.
SyntaxCIRCLE(centrex,centrey,radius,fill)
DescriptionDraws a circle at position (centrex,centrey) with thespecified radius in the current foreground COLOUR. Thefinal parameter fill is either TRUE or FALSE, and specifiesfilled (TRUE) or outline (FALSE).
ExampleCLSPRINT "Draw a filled yellow circle ";PRINT "In the centre of the screen"COLOUR=yellowCIRCLE(GWIDTH/2,GHEIGHT/2,100,TRUE)UPDATEEND
AssociatedELLIPSE, RECT, TRIANGLE
CLEARKEYBOARDPurposeClear all pending keyboard input.
SyntaxCLEARKEYBOARD
DescriptionClears the keyboard input buffer.
ExamplePRINT "Press space to continue"WHILE NOT SCANKEYBOARD(scanSpace) LOOPREPEATCLEARKEYBOARDEND
AssociatedSCANKEYBOARD
26
main index
CLOCKPurposeSet angle units to minutes.
SyntaxCLOCK
DescriptionSwitches the internal angle system to clock mode. Thereare 60 minutes in a full circle.
ExamplePRINT "ATAN(1) = "DEGPRINT ATAN(1); " Degrees"CLOCKPRINT ATAN(1); " Minutes"RADPRINT ATAN(1); " Radians"END
AssociatedDEG, RAD
Functions, Constants & Procedures
CLONESPRITEPurposeCreate a new sprite from an existing one.
SyntaxCLONESPRITE ( sprite handle )
DescriptionCopies a sprite and its settings from an existing one (spritehandle) into a new one.
Example
sprite = newSprite (1)loadSprite (“ballBlue.png”, sprite, 0)sprite2 = cloneSprite (sprite)LOOP PlotSprite (sprite, 100, 100, 0) PlotSprite (sprite2, 200, 200, 0)REPEAT
AssociatednewSprite, loadSprite
27
main index
CLOSEPurposeClose a file after use.
SyntaxCLOSE(handle)
DescriptionThe CLOSE instruction closes the file specified by handleafter use and makes sure all data is securely written to thestorage medium.
Examplehandle = OPEN("testfile.txt")PRINT# handle, "Colin"CLOSE(handle)handle = OPEN("testfile.txt")INPUT# handle, Name$CLOSE(handle)PRINT "Name: " + Name$END
AssociatedEOF, FFWD, INPUT#, OPEN, PRINT#, REWIND, SEEK
Functions, Constants & Procedures
CLSPurposeClear screen.
SyntaxCLS
DescriptionCompletely clear the screen of text and graphics. Note, this doesnot clear sprites from the screen.
ExamplePRINT “Hello World”WAIT (1)CLSEND
AssociatedCLS, UPDATE
28
main index
CLS2PurposeClear screen without an update.
SyntaxCLS2
DescriptionIdeally suited to games and graphical programming. CLS2 clearsthe background or buffer screen and does not issue an updatecommand. This means you can wipe the screen buffer, redraw onit and then issue an update. This ensures flicker free updates. It isalso much faster than CLS.
Exampley = GHEIGHT / 2radius = GWIDTH / 10FOR x = 0 TO GWIDTH STEP radius LOOPCLS
COLOUR = PINKCIRCLE (x, y, radius, 1)UPDATE
REPEATFOR x = GWIDTH TO 0 STEP -10 LOOP
CLS2COLOUR = YELLOWCIRCLE (x, y, radius, 1)UPDATE
REPEAT
AssociatedCLS, UPDATE
Functions, Constants & Procedures
COLOURPurposeSet/Read the current graphics plot colour.
SyntaxCOLOUR=setcolour
DescriptionSet/Read the current graphics plot colour as follows:
0 Black1 DarkGrey2 Grey3 Silver4 LightGrey5 White6 Maroon7 Red8 Purple9 Raspberry
10 Pink11 LightPink12 DarkGreen13 Green14 BrightGreen15 Olive16 Lime17 LightGreen18 Navy19 Blue
20 Teal21 Cyan22 Aqua23 LightBlue24 Brown25 LightBrown26 Orange27 Gold28 Yellow29 LightYellow
29
main index
ExampleCLSFOR c=0 TO 29 LOOP
COLOUR=cCIRCLE(50,GHEIGHT-c*40-50,20,TRUE)COLOUR=WHITECIRCLE(50,GHEIGHT-c*40-50,20,FALSE)READ NameOfColour$HVTAB(5,c*2+2)PRINT NameOfColour$;" ";c
REPEATUPDATEDATA "Black", "DarkGrey", "Grey", "Silver"DATA "LightGrey", "White", "Maroon", "Red"DATA "Purple", "Raspberry", "Pink", "LightPink"DATA "DarkGreen", "Green", "BrightGreen", "Olive"DATA "Lime", "LightGreen", "Navy", "Blue", "Teal"DATA "Cyan", "Aqua", "LightBlue", "Brown"DATA "LightBrown", "Orange", "Gold", "Yellow"DATA "LightYellow"END
AssociatedINK, PAPER, RGBCOLOUR
Functions, Constants & Procedures
COPYREGIONPurposeCopy a region of the screen from one location to another.
SyntaxCOPYREGION(oldx,oldy,width,height,newX,newY)
DescriptionThis enables you to duplicate the contents of a section of the screenfrom one place to another. This could be used for example to create abackground for a game by drawing an image and then duplicating it.The region to be copied is specified by the rectangle at coordinates(oldx,oldy) width pixels wide and height pixels high. The region iscopied to coordinates (newx,newy)
ExampleCOLOUR=REDRECT(0,0,50,50,TRUE)COLOUR=WHITELINE(0,50,50,50)LINE(0,25,50,25)LINE(0,25,0,50)LINE(50,25,50,50)LINE(25,0,25,25)LINE(0,0,50,0)FOR X=0 TO GWIDTH STEP 50 LOOP
FOR Y=0 TO GHEIGHT STEP 50 LOOPCOPYREGION(0,0,50,50,X,Y)
REPEATREPEATUPDATE
AssociatedGRABREGION
30
main index
COSPurposeReturns the cosine of the given angle.
Syntaxcosine=COS(angle)
DescriptionReturns the cosine of the argument angle. This is the ratioof the side of a right angled triangle, that is adjacent tothe angle, to the hypotenuse (the longest side).
ExampleCLSPRINT "Draw ellipse in screen centre"DEGFOR Angle=0 TO 360 LOOP
Xpos=100*COS(Angle)+GWIDTH / 2Ypos=50*SIN(Angle)+GHEIGHT / 2PLOT(Xpos, Ypos)
REPEATEND
AssociatedACOS, ASIN, ATAN, SIN, TAN
LOOPPurposeDefines the start of a block of code to be repeated.
SyntaxLOOP
DescriptionMarks the start of a block of repeating code (called aloop). The number of times that the loop is executeddepends on the command used before LOOP or at theend of the loop.
ExampleREM See Associated commands below.
AssociatedBREAK, CONTINUE, LOOP REPEAT, FOR REPEAT, REPEATUNTIL, UNTIL REPEAT, WHILE REPEAT
Functions, Constants & Procedures
31
main index
LOOP REPEATPurposeCreate an infinite loop.
SyntaxLOOP
{statements}REPEAT
DescriptionExecute the statements again and again forever. The BREAKcommand can be used to terminate a loop. Pressing the Esc keywill also interrupt the loop (and program).
ExampleREM Loop until the space bar is pressedPRINT "Press the space bar to continue"LOOP
IF INKEY = 32 THEN BREAKREPEATEND
AssociatedBREAK, CONTINUE, LOOP, FOR REPEAT, REPEAT UNTIL,UNTIL REPEAT, WHILE REPEAT
DATAPurposeStore constant data.
SyntaxDATA constant{,constant}
DescriptionStores numerical and string constants for later retrievalusing the READ command.
ExampleREM Load the name of the days of theREM week into a string arrayDATA "Monday", "Tuesday", "Wednesday"DATA "Thursday", "Friday", "Saturday"DATA "Sunday"DIM DaysOfWeek$(7)FOR DayNo=1 TO 7 LOOP
READ DaysOfWeek$(DayNo)REPEATFOR DayNo=1 TO 7 LOOP
PRINT "Day of the week number ";DayNo;PRINT " is ";DaysOfWeek$(DayNo)
REPEATEND
AssociatedREAD, RESTORE
Functions, Constants & Procedures
32
main index
DATE$PurposeReturn the current date.
Syntaxtodaysdate$ = DATE$
DescriptionThis returns a string with the current date in the format:YYYY-MM-DD. For example: 2015-03-24.
ExamplePRINT "Today is ";FN FormatDate(DATE$)END
DEF FN FormatDate()DayNo=VAL(RIGHT$(DATE$, 2))MonthNo=VAL(MID$(DATE$, 5, 2))Year$=LEFT$(DATE$,4)SWITCH (DayNo MOD 10)
CASE 1DaySuffix$ = "st"
ENDCASECASE 2
DaySuffix$ = "nd"ENDCASECASE 3
DaySuffix$ = "rd"ENDCASEDEFAULT
DaySuffix$ = "th"ENDCASE
ENDSWITCHFOR I=1 TO MonthNo LOOP
READ MonthName$REPEATResult$=STR$(DayNo)+DaySuffix$+" "
=Result$+MonthName$+" "+Year$DATA "January","February","March","April"DATA "May","June","July","August"DATA "September","October","November"DATA "December"
AssociatedTIME$
Functions, Constants & Procedures
33
main index
DEF FNPurposeCreate a user defined function.
SyntaxDEF FN name({parameter}{,parameter})
{commands}=value
DescriptionUser defined functions are similar to user definedprocedures except that they can return a value. This canbe either a number or a character string.
ExampleREM Function test - print squaresFOR I=1 TO 10 LOOP
x=FN square(I)PRINT I; " squared is "; xREPEATENDDEF FN square(num)
LOCAL resultresult=num*num
=result
AssociatedFN, LOCAL
DEF PROCPurposeCreate a user defined procedure.
SyntaxDEF PROC name({parameter}{,parameter})
{commands}ENDPROC
DescriptionAllows you to create your own routines that can be called bytheir label. Once you have written a procedure to do a particulartask you can copy it into other programs that require it.Procedures are usually defined after the END of the program.
ExampleCLSPROC Hexagon(200,200,100,Red)UPDATEENDDEF PROC Hexagon(x,y,l,c)
PENUPMOVETO(x-l*COS(30),y+l/2)COLOUR = cPENDOWNFOR I=1 to 6 LOOP
RIGHT(60)MOVE(l)
REPEATENDPROC
AssociatedLOCAL, PROC, ENDPROC
Functions, Constants & Procedures
34
main index
DEFCHARPurposeDefine a new font character.
SyntaxDEFCHAR(char,line1 … line10)
DescriptionCreate a user defined font character. The char parameter is theposition of the character within the font (0-255) e.g. 65 is thecapital letter A in ASCII. The character consists of 10 lines with8 pixels in each line. These are set by the corresponding bits ineach of the line parameters. So for example decimal 170 (binary10101010) would set alternate pixels on the corresponding lineof the character.
NOTE: The zero ‘CHR$(0)’ should not be used.
ExampleREM Define Chessboard CharacterFONTSIZE(10)DEFCHAR(2,0,85,170,85,170,85,170,85,170,0)PRINT CHR$(2)END
AssociatedCHR$
DEGPurposeSet angle units to degrees.
SyntaxDEG
DescriptionSwitches the internal angle system to degree mode. Thereare 360 degrees in a full circle.
ExampleREM Draw an ellipse in the screen centreCLSDEGFOR Angle = 0 TO 360 LOOP
Xpos=100*COS(Angle)+GWIDTH / 2Ypos=50*SIN(Angle)+GHEIGHT / 2PLOT(Xpos, Ypos)
REPEATEND
AssociatedCLOCK, RAD
Functions, Constants & Procedures
35
main index
DIGITALREADPurposeRead the state of a digital pin on the Raspberry Pi.
Syntaxpinvalue=DIGITALREAD(pinno)
DescriptionReads the state of a digital pin on the Raspberry Pi. You mayneed to set the pin mode beforehand to make sure it’sconfigured as an input device. It will return TRUE or FALSE toindicate an input being high or low respectively.
ExampleREM Set pin 12 to inputPINMODE(12,0)REM Wait for button to be pushedUNTIL DIGITALREAD(12) LOOPREPEATPRINT "Button Pushed"END
AssociatedDIGITALWRITE, PINMODE, PWMWRITE
DIGITALWRITEPurposeSet the state of a digital pin on the Raspberry Pi.
SyntaxDIGITALWRITE(pinno,pinvalue)
DescriptionThis procedure sets a digital pin to the supplied value - 0 for offor 1 for on. As with DigitalRead, you may need to set the pinmode (to output) beforehand.
ExampleREM Flash LED attached to pin2 of GPIOREM Set pin 2 to output modePINMODE(2,1)LOOP
REM Set output High (on)DIGITALWRITE(2,1)WAIT(1)REM Set output Low (off)DIGITALWRITE(2,0)WAIT(1)
REPEATEND
AssociatedDIGITALREAD, PINMODE, PWMWRITE
Functions, Constants & Procedures
36
main index
DIMPurposeDimension an array of variables.
SyntaxDIM variable(dimension{,dimension})
DescriptionCreates an indexed variable with one or more dimensions. Thevariable can be either a numeric or character string type (theycannot hold mixed values). The index is a number from 0 to thesize of the dimension. Associative arrays (sometimes calledmaps) are another way to refer to the individual elements of anarray. In the example below we use a number, however stringsare also allowed. They can be multi-dimensional and you canfreely mix numbers and strings for the array indices.
ExampleREM Initialise the squares of a chessREM board to black or whiteDIM ChessBoard(8,8)Count=0FOR Row=1 TO 8 LOOP
FOR Col=1 TO 8 LOOPCount=Count+1IF Count MOD 2=1 THEN
ChessBoard(Row,Col) = BlackELSE
ChessBoard(Row,Col) = WhiteENDIF
REPEATREPEATPRINT ChessBoard(1,4)END
Functions, Constants & Procedures
37
main index
DRCANALOGREADPurposeRead an analog channel on a DRC device.
Syntaxvoltage=DRCANALOGREAD(handle,pin)
DescriptionThis function reads an analog channel on a DRC compatibledevice specified by handle and returns the result. The valuereturned will depend on the hardware you’re connected to - forexample the Arduino will return a number from 0 to 1023representing an input voltage between 0 and 5 volts. Otherdevices may have different ranges.
Examplearduino=DRCOPEN("/dev/ttyUSB0")REM Get voltage on pin 4voltage=DRCANALOGREAD(arduino, 4)/1023*5PRINT "Voltage= "; voltageDRCCLOSE(arduino)END
AssociatedDRCCLOSE, DRCDIGITALREAD, DRCDIGITALWRITE,DRCOPEN, DRCPINMODE, DRCPWMWRITE
DRCCLOSEPurposeClose a connection to a DRC compatible device.
SyntaxDRCCLOSE(handle)
DescriptionThis closes a connection to a DRC device and frees up anyresources used by it. It’s not strictly necessary to do this whenyou end your program, but it is considered good practice.
Examplearduino = DRCOPEN("/dev/ttyUSB0")REM Set pin 12 to inputDRCPINMODE(arduino, 12, 0)LOOPREPEAT UNTIL DRCDIGITALREAD(arduino, 12)PRINT "Button Pushed"DRCCLOSE(arduino)END
AssociatedDRCANALOGREAD, DRCDIGITALREAD, DRCDIGITALWRITE,DRCOPEN, DRCPINMODE, DRCPWMWRITE
Functions, Constants & Procedures
38
main index
DRCDIGITALREADPurposeRead the state of a digital pin on a remote DRC device.
Syntaxstate=DRCDIGITALREAD(handle,pin)
DescriptionThis function allows you to read the state of a digital pin on aDRC device specified by handle. You may need to set the pinmode beforehand to make sure it’s configured as an inputdevice. It will return TRUE or FALSE to indicate an input beinghigh or low respectively.
Examplearduino = DRCOPEN("/dev/ttyUSB0")REM Set pin 12 to inputDRCPINMODE(arduino, 12, 0)LOOPREPEAT UNTIL DRCDIGITALREAD(arduino, 12)PRINT "Button Pushed"DRCCLOSE(arduino)END
AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALWRITE,DRCOPEN, DRCPINMODE, DRCPWMWRITE
DRCDIGITALWRITEPurposeSet a digital pin on a remote DRC device to the suppliedvalue.
SyntaxDRCDIGITALWRITE(handle,pin,value)
DescriptionThis procedure sets a digital pin on a DRC device specified byhandle to the supplied value - 0 for off or 1 for on. As withDrcDigitalRead, you may need to set the pin mode beforehand.
Examplearduino=DRCOPEN("/dev/ttyUSB0")REM Set pin 2 to output modeDRCPINMODE(arduino, 2, 1)REM Set Output High (on)DRCDIGITALWRITE(arduino, 2, 1)REM Pause for 1 secondWAIT(1)REM Set output Low (off)DRCDIGITALWRITE(arduino, 2, 0)DRCCLOSE(arduino)END
AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALREAD,DRCOPEN, DRCPINMODE, DRCPWMWRITE
Functions, Constants & Procedures
39
main index
DRCOPENPurposeOpen a connection to a DRC compatible device.
Syntaxhandle=DRCOPEN(drcdevice)
DescriptionThis opens a connection to a DRC compatible device and makesit available for our use. It takes the name of the device as anargument and returns a number (the handle) of the device. Wecan use this handle to reference the device and allow us to openseveral devices at once. Some implementations may have IOdevices with fixed names.
Examplearduino = DRCOPEN("/dev/ttyUSB0")REM Set pin 12 to inputDRCPINMODE(arduino, 12, 0)LOOPREPEAT UNTIL DRCDIGITALREAD(arduino, 12)PRINT "Button Pushed"DRCCLOSE(arduino)END
AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALREAD,DRCDIGITALWRITE, DRCPINMODE, DRCPWMWRITE
DRCPINMODEPurposeConfigure the mode of a pin on a remote DRC device.
SyntaxDRCPINMODE(handle,pin,mode)
DescriptionThis configures the mode of a pin on the DRC device specifiedby handle. It takes an argument which specifies the mode of thespecified pin - input, output or PWM output. Other modes maybe available, depending on the device and its capabilities. Notethat not all devices support all functions. The modes are:0 pinINPUT1 pinOUTPUT2 pinPWM
Examplearduino = DRCOPEN("/dev/ttyUSB0")REM Set pin 12 to inputDRCPINMODE(arduino, 12, 0)LOOPREPEAT UNTIL DRCDIGITALREAD(arduino, 12)PRINT "Button Pushed"DRCCLOSE(arduino)END
AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALREAD,DRCDIGITALWRITE, DRCOPEN, DRCPWMWRITE
Functions, Constants & Procedures
40
main index
DRCPWMWRITEPurposeOutput a PWM waveform on the selected pin of a DRCdevice.
SyntaxDRCPWMWRITE(handle,pin,value)
DescriptionThis procedure outputs a PWM waveform on the specified pinof a DRC compatible device specified by handle. The pin mustbe configured for PWM mode beforehand, and depending onthe device you are using, then not all pins on a device maysupport PWM mode. The value set should be between 0 and255.
Examplearduino=DRCOPEN("/dev/ttyUSB0")REM Set pin 11 to PWM output modeDRCPINMODE(arduino, 11, 2)DRCPWMWRITE(arduino, 11, 200)DRCCLOSE(arduino)END
AssociatedDRCANALOGREAD, DRCCLOSE, DRCDIGITALREAD,DRCDIGITALWRITE, DRCOPEN, DRCPINMODE
ELLIPSEPurposeDraw an ellipse on the screen.
SyntaxELLIPSE(xpos,ypos,xradius,yradius,fill)
DescriptionDraws an ellipse centred at position (xpos,ypos) with thespecified xradius and yradius in the current foregroundCOLOUR. The final parameter fill is either TRUE or FALSE, andspecifies filled (TRUE) or outline (FALSE).
ExampleCLSREM Draw a filled red ellipse atREM location 200,200COLOUR=redELLIPSE(200,200,100,50,TRUE)UPDATEEND
AssociatedCIRCLE, RECT, TRIANGLE
Functions, Constants & Procedures
41
main index
ELSEPurposeExecute statement(s) when a tested condition is False.
SyntaxIF condition THEN{statements}ELSE{statements}ENDIF
ExampleNumber = 13IF Number MOD 2 = 0 THEN
PRINT "Number is Even"ELSE
PRINT "Number is Odd"ENDIFEND
AssociatedENDIF, IF THEN
ENDPurposeEnd program execution.
SyntaxEND
DescriptionProgram execution is ended. Programs must terminatewith the END or STOP commands or an error will occur.
ExamplePRINT "Hello World"END
Functions, Constants & Procedures
42
main index
ENDIFPurposeTerminate a multiline conditional statement.
SyntaxIF condition THEN{statements}ENDIF
DescriptionWe can extend the IF statement over multiple lines, ifrequired. The way you do this is by making sure there isnothing after the THEN statement and ending it all withthe ENDIF statement.
ExampleDayOfWeek = 5IF DayOfWeek < 6 THEN
PRINT "It is a Weekday"PRINT "Go to Work!"
ENDIFEND
AssociatedELSE, IF THEN
ENDPROCPurposeDefines the end of a PROCedure
SyntaxENDPROC
DescriptionEnd a PROCedure and return to the next command afterthe procedure was called.
ExampleCLSPROC helloENDDEF PROC helloPRINTAT (10,10); "Hello"ENDPROC
AssociatedPROC, DEF PROC
Functions, Constants & Procedures
43
main index
ENVELOPEPurposeEmulate the BBC BASIC sound envelope command.
SyntaxENVELOPE(N,T,PI1,P12,PI3,PN1,PN2,PN3,AA,AD,AS,AR,ALA,ALD)
DescriptionNOTE: This is an experimental function. It might not performentirely as expected. It is also prone to crashing if incorrectvalues are used. Use with caution!
N 1 to 8 Envelope number.
T 0 to 127 Length of each step in hundredths of a second.Add 128 to cancel auto repeat of the pitch envelope.
PI1 −128 to 127 Pitch change per step in section 3PI2 −128 to 127 Change of pitch per step in section 2PI3 −128 to 127 Change of pitch per step in section 1PN1 0 to 255 Number of steps in section 1PN2 0 to 255 Number of steps in section 2PN3 0 to 255 Number of steps in section 3AA −127 to 127 Change of attack amplitude per stepAD −127 to 127 Change of decay amplitude per stepAS −127 to 0 Change of sustain amplitude per stepAR −127 to 0 Change of release amplitude per stepALA 0 to 126 Level at end of the attack phaseALD 0 to 126 Level at end of the decay phase
ExampleENVELOPE(1,2,-2,10,1,80,40,40,127,0,0,0,126,126)SOUND(1, 1, 53, 64)END
AssociatedSOUND
Functions, Constants & Procedures
44
main index
EOFPurposeReturn true if the end of an input file has been reached.
Syntaxendoffile=EOF(handle)
DescriptionThe EOF function returns a TRUE or FALSE indication of the stateof the file pointer when reading the file. It is an error to try toread past the end of the file, so if you are reading a file withunknown data in it, then you must check at well defined intervals(e.g. Before each INPUT#).
Examplehandle=OPEN("eoftest.txt")FOR r = 0 TO 10 LOOP
PRINT# handle, "Record "; rREPEATCLOSE (handle)handle = OPEN("eoftest.txt")WHILE NOT EOF (handle) LOOP
INPUT# handle, record$PRINT record$
REPEATCLOSE (handle)END
AssociatedCLOSE, FFWD, INPUT#, OPEN, PRINT#, REWIND, SEEK
EXPPurposeReturn the exponential value of the specified number.
Syntaxexponential=EXP(number)
DescriptionReturns the exponential value of the specified number. This is eto the power of number where e is the exponential constant(approximately 2.718281828). The exponential function ariseswhenever a quantity grows or decays at a rate proportional to itscurrent value. This is the opposite of the LOG function i.e.EXP(LOG(X)) = X
ExampleREM prints 2.718281828PRINT EXP(1)REM prints 22026.46579PRINT EXP(10)REM prints 10PRINT LOG(EXP(10))END
AssociatedLOG
Functions, Constants & Procedures
45
main index
FADEOFFPurposeFade the display from light to dark
SyntaxFADEOFF
DescriptionFADEOFF initiates a fade from light to dark. The entirescreen display is affected.
ExamplePAPER=0INK=1CLSPRINT "LOADING..."FADEOFFWHILE FADING = true LOOP
UPDATEREPEATFADEONWHILE FADING = true LOOP
UPDATEREPEATEND
AssociatedFADEON, FADING
FADEONPurposeFade the display from dark to light
SyntaxFADEON
DescriptionFADEON initiates a fade from dark to light. The entirescreen display is affected.
ExamplePAPER=0INK=1CLSPRINT "LOADING..."FADEOFFWHILE FADING = true LOOOP
UPDATEREPEATFADEONWHILE FADING = true LOOP
UPDATEREPEATEND
AssociatedFADEOFF, FADING
Functions, Constants & Procedures
46
main index
FADINGPurposeCheck if the display is fading
SyntaxFADING
DescriptionReturns either TRUE (if fade in progress) or FALSE (no fadeactive)
ExamplePAPER=0INK=1CLSPRINT "LOADING..."FADEOFFWHILE FADING = true LOOP
UPDATEREPEATFADEONWHILE FADING = true LOOP
UPDATEREPEATEND
AssociatedFADEON, FADING
FALSEPurposeRepresent the logical "false" value.
SyntaxFALSE
DescriptionRepresents a Boolean value that fails a conditional test. Itis equivalent to a numeric value of 0.
Examplecondition = FALSEIF condition = FALSE THEN
PRINT "Condition is FALSE"ENDIFIF NOT condition THEN
PRINT "Condition is FALSE"ENDIFPRINT "Condition= ";conditionEND
AssociatedTRUE
Functions, Constants & Procedures
47
main index
FFWDPurposeMove the file pointer to the end of a file.
SyntaxFFWD(handle)
DescriptionMove the file pointer back to the end of the file specified byhandle. If you want to append data to the end of an existing file,then you need to call FFWD before writing the data.
Examplehandle=OPEN("ffwdtest.txt")PRINT# handle, "First Line"CLOSE (handle)handle = OPEN ("ffwdtest.txt")FFWD (handle)PRINT# handle, "Appended line"CLOSE (handle)handle = OPEN("ffwdtest.txt")WHILE NOT EOF (handle) LOOP
INPUT# handle, record$PRINT record$
REPEATCLOSE (handle)END
AssociatedCLOSE, EOF, INPUT#, OPEN, PRINT#, REWIND, SEEK
FNPurposeCall a user defined function.
Syntaxresult=FN name({argument}{,argument})
DescriptionCalls the specified user defined function called name with thespecfied arguments. The returned result can then be used by theprogram. Once the function has been executed control returnsto the command following.
ExamplePRINT FN SphereVolume(10)ENDREM Function calculate volume of a sphereREM with radius rDEF FN SphereVolume(r)= (4/3)*PI*r*r*r
AssociatedDEF FN
Functions, Constants & Procedures
48
main index
FONTSIZEPurposeScale the text font.
SyntaxFONTSIZE(scale)
DescriptionChange the size of the text font.
ExampleFOR S=1 TO 10 LOOP
FONTSIZE(S)PRINT "Hello World"
REPEATEND
AssociatedPRINTAT, LOADFONT
FOR LOOPPurposeLoop a specified number of times using a counter.
SyntaxFOR count=start TO end [STEP step] LOOP
statementsREPEAT
DescriptionThe count variable is initially set to start and changes by stepeach time around the loop until count is greater than or equal toend. The optional step, which defaults to 1 may be less than zeroto count backwards. The end of the loop is indicated using theREPEAT.
ExampleREM year into a string arrayDATA "January", "February", "March"DATA "April", "May", "June"DATA "July", "August", "September"DATA "October", "November", "December"DIM Months$(12)FOR Month = 1 TO 12 LOOP
READ Months$(Month)REPEATPRINT "The seventh month is ";Months$(7)END
AssociatedBREAK, CONTINUE, LOOP, LOOP REPEAT, REPEAT UNTIL,UNTIL REPEAT, WHILE REPEAT
Functions, Constants & Procedures
49
main index
FREEIMAGEPurposeRelease an image from memory
SyntaxFREEIMAGE(handle)
DescriptionFrees up the memory space taken up by a stored image
Examplehandle = LOADIMAGE( "sprite1.bmp" )PLOTIMAGE( handle, 0, 0 )UPDATEFREEIMAGE( handle )handle = LOADIMAGE( "sprite2.bmp" )PLOTIMAGE( handle, 100, 100 )UPDATEEND
AssociatedLOADIMAGE, PLOTIMAGE
FULLSCREENPurposeSets the display to full screen mode.
SyntaxFULLSCREEN={TRUE/FALSE}
DescriptionSwitches between full screen or windowed mode. Note this doesnot set the resolution to the screen display mode so unless youset the mode manually you will get a border.
ExampleSETMODE(800,600)FULLSCREEN=0COLOUR=REDRECT(0,0,GWIDTH, GHEIGHT,0)UPDATEWAIT(2)FULLSCREEN=1WAIT(2)END
AssociatedSETMODE
Functions, Constants & Procedures
50
main index
GETPurposeGet a single character code from the keyboard.
Syntaxasciicode=GET
DescriptionThis pauses program execution and waits for you to type a singlecharacter on the keyboard, then returns the value of the keypressed as a numeric variable (ASCII).
ExamplePRINT "Press a key"key = GETPRINT "ASCII Value of key = "; keyEND
AssociatedGET$, INKEY
GET$PurposeGet a single character from the keyboard.
Syntaxkey$ = GET$
DescriptionThis pauses program execution and waits for you to type a singlecharacter on the keyboard, then returns the key as a stringvariable.
ExamplePRINT "Press a key"key$ = GET$PRINT "You Pressed Key: "; key$END
AssociatedGET, INKEY
Functions, Constants & Procedures
51
main index
GETIMAGEHPurposeGet the pixel height of a loaded image.
SyntaxGETIMAGEH(handle)
DescriptionGets the height in pixels of a loaded image
ExampleREM Centre image on screenlogo=LOADIMAGE("/usr/share/fuze/logo.bmp")imageW=GETIMAGEW(logo)imageH=GETIMAGEH(logo)X=(GWIDTH-imageW)/2Y=(GHEIGHT-imageH)/2PLOTIMAGE(logo,X,Y)UPDATEEND
AssociatedGETIMAGEW, LOADIMAGE, PLOTIMAGE
GETIMAGEWPurposeGet the pixel width of a loaded image.
SyntaxGETIMAGEW(handle)
DescriptionGets the width in pixels of an image previously loaded usingLOADIMAGE (using the handle returned by LOADIMAGE).
ExampleREM Centre image on screenlogo=LOADIMAGE("/usr/share/fuze/logo.bmp")imageW=GETIMAGEW(logo)imageH=GETIMAGEH(logo)X=(GWIDTH-imageW)/2Y=(GHEIGHT-imageH)/2PLOTIMAGE(logo,X,Y)UPDATEEND
AssociatedGETIMAGEH, LOADIMAGE, PLOTIMAGE
Functions, Constants & Procedures
52
main index
GETMOUSEPurposeRead values from an attached mouse
SyntaxGETMOUSE(xpos,ypos,buttons)
DescriptionThis reads values for the current state of the mouse. xpos is thehorizontal mouse position, ypos is the vertical position andbuttons is the state of the mouse buttons. You can test whetherthe left button has been pressed by using the logical & operatorto see if bit 0 of the buttons value is set: buttons & 1 will beTRUE. Likewise if the right button is pressed then bit 3 will be setand buttons & 4 will be TRUE.
ExampleCLSMOUSEONLOOP
GETMOUSE(x,y,b)LINETO(x,y)UPDATEREM LOOP colour if left button pressedIF b & 1 THEN
COLOUR = COLOUR MOD 16 + 1ENDIFREM Exit if right button pressed
REPEAT UNTIL b & 4MOUSEOFFEND
AssociatedMOUSEOFF, MOUSEON, MOUSEX, MOUSEY, SETMOUSE
GETPIXELPurposeReturn the colour of the specified pixel.
Syntaxcolour = GETPIXEL(xpos, ypos)
DescriptionThis returns the internal colour code (0-15) of the pixel atthe specified point (xpos,ypos). This is for the "named"colours - e.g. Red, Green etc. It returns -1 if the pixelcolour is not a standard colour - in which case, you needto use GETPIXELRGB.
ExampleCLSCOLOUR = REDXpos = GWIDTH / 2Ypos = GHEIGHT / 2PLOT(Xpos, Ypos)PRINT GETPIXEL(Xpos, Ypos)END
AssociatedGETPIXELRGB
Functions, Constants & Procedures
53
main index
GETPIXELRGBPurposeReturn the RGB colour of the specified pixel.
SyntaxRGBcolour = GETPIXELRGB(xpos, ypos)
DescriptionThis returns the RGB colour of the pixel at the specified point(xpos,ypos). This will return a 24-bit value.
ExampleCLSRGBCOLOUR(49, 101, 206)Xpos = GWIDTH / 2Ypos = GHEIGHT / 2CIRCLE(Xpos, Ypos, 50, TRUE)pixel = GETPIXELRGB(Xpos, Ypos)PRINT "RGB = "; pixelPRINT "Red = "; (pixel >> 16) & 0xFFPRINT "Green = "; (pixel >> 8) & 0xFFPRINT "Blue = "; (pixel >> 0) & 0xFFEND
AssociatedGETPIXEL
GETSPRITEANGLEPurposeReturns a sprite’s current angle
SyntaxGETSPRITEANGLE(spriteIndex)
DescriptionReturns the angle of the sprite with the specified spriteIndex.
Examplesprite = newSprite (1)loadSprite ("logo.png", sprite, 0)angle = 0plotSprite (sprite, gWidth / 2, gHeight / 2, 0)LOOPcls2 setSpriteAngle (sprite, angle) angle = angle + 1 if angle>359 THEN angle=0 printat(0,0);getspriteangle(sprite) UPDATEREPEAT
AssociatedGETSPRITEW, HIDESPRITE, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP
Functions, Constants & Procedures
54
main index
GETSPRITEHPurposeGet the pixel height of a sprite.
SyntaxGETSPRITEH(spriteIndex)
DescriptionReturns the height in pixels of the sprite with the specifiedspriteIndex.
ExampleREM Centre sprite on the screenindex=NEWSPRITE(1)fuzelogo$="logo.bmp"LOADSPRITE(fuzelogo$,index,0)spriteW=GETSPRITEW(index)spriteH=GETSPRITEH(index)X=(GWIDTH-spriteW)/2Y=(GHEIGHT-spriteH)/2PLOTSPRITE(index,X,Y,0)UPDATEEND
AssociatedGETSPRITEW, HIDESPRITE, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP
GETSPRITEWPurposeGet the pixel width of a sprite.
SyntaxGETSPRITEW(spriteIndex)
DescriptionReturns the width in pixels of the sprite with the specifiedspriteIndex.
ExampleREM Centre sprite on the screenindex=NEWSPRITE(1)fuzelogo$="logo.bmp"LOADSPRITE(fuzelogo$,index,0)spriteW=GETSPRITEW(index)spriteH=GETSPRITEH(index)X=(GWIDTH-spriteW)/2Y=(GHEIGHT-spriteH)/2PLOTSPRITE(index,X,Y,0)UPDATEEND
AssociatedGETSPRITEH, HIDESPRITE, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP
Functions, Constants & Procedures
55
main index
GETSPRITEXPurposeGet the X position of a sprite.
SyntaxGETSPRITEX(spriteIndex)
DescriptionReturns the X position in pixels of the sprite with the specifiedspriteIndex.
ExampleupdateMode = 0sprite = newSprite (1)loadSprite ("logo.png", sprite, 0)LOOP
CLS2plotSprite (sprite, gWidth / 2, gHeight / 2, 0)PRINT getSpriteX (sprite)PRINT getSpriteY (sprite)UPDATE
REPEAT
AssociatedGETSPRITEW, HIDESPRITE, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP
GETSPRITEYPurposeGet the Y position of a sprite.
SyntaxGETSPRITEY(spriteIndex)
DescriptionReturns the Y position in pixels of the sprite with the specifiedspriteIndex.
ExampleupdateMode = 0sprite = newSprite (1)loadSprite ("logo.png", sprite, 0)LOOP
CLS2plotSprite (sprite, gWidth / 2, gHeight / 2, 0)PRINT getSpriteX (sprite)PRINT getSpriteY (sprite)UPDATE
REPEAT
AssociatedGETSPRITEH, HIDESPRITE, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP
Functions, Constants & Procedures
56
main index
GHEIGHTPurposeFind the current height of the display.
Syntaxheight=GHEIGHT
DescriptionThis can be read to find the current height of the display ineither high resolution or low resolution pixels.
ExampleREM Draw a circle in the centre of thescreenCLSCOLOUR = blueCIRCLE(GWIDTH/2,GHEIGHT/2,50,TRUE)UPDATEEND
AssociatedGWIDTH, ORIGIN, SETMODE
GRABREGIONPurposeGrab a region of the screen to a temporary buffer
Syntaxhandle = GRABREGION(x, y, width, height)
DescriptionGrab a region of the screen with x and y as the location and withwidth and height in pixels. The region can be recalled by itshandle and pasted using PLOTIMAGE.
ExampleFOR n = 0 TO 15 LOOPRECT(0,n*GHEIGHT/16, GWIDTH, GHEIGHT/16,1)REPEAThandle=GRABREGION(0,0,200,200)CLSPLOTIMAGE(handle, GWIDTH/2, GHEIGHT/2)UPDATEEND
AssociatedCOPYREGION, FREEIMAGE, LOADIMAGE, PLOTIMAGE,SAVEREGION, SAVESCREEN, SCROLLDOWN, SCROLLLEFT,SCROLLRIGHT, SCROLLUP
Functions, Constants & Procedures
57
main index
HIDESPRITEPurposeRemove a sprite from the screen.
SyntaxHIDESPRITE(spriteindex)
DescriptionThis removes the sprite at the specified spriteindex from thescreen. You do not have to erase a sprite from the screen whenyou move it, just call PLOTSPRITE with the new coordinates.
ExampleCLSfuzelogo$="logo.bmp"s1=NEWSPRITE (1)s2=NEWSPRITE (1)LOADSPRITE (fuzelogo$,s1,0)LOADSPRITE (fuzelogo$,s2,0)PLOTSPRITE (s1,100,100,0)PLOTSPRITE (s2,200,200,0)UPDATEWAIT(2)REM Remove a sprite from the screenHIDESPRITE (s2)UPDATEEND
AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SPRITECOLLIDE, SPRITECOLLIDEPP, SPRITEOUT
GWIDTHPurposeReturns the current width of the display.
Syntaxwidth=GWIDTH
DescriptionThis can be read to find current width of the display in eitherhigh resolution or low resolution pixels.
ExampleREM Draw a circle in the centre of thescreenCLSCOLOUR = blueCIRCLE(GWIDTH/2,GHEIGHT/2,50,TRUE)UPDATEEND
AssociatedGHEIGHT, ORIGIN, SETMODE
Functions, Constants & Procedures
58
main index
HLINEPurposeDraw a horizontal line.
SyntaxHLINE(xpos1, xpos2, ypos)
DescriptionDraws a horizontal line on row y, from column xpos1 to columnxpos2.
ExampleCLSCOLOUR=redFOR ypos=0 TO GHEIGHT STEP 100 LOOP
HLINE(0,GWIDTH,ypos)REPEATUPDATEEND
AssociatedLINE, LINETO, VLINE
HTABPurposeSet/Read the current text cursor horizontal position.
SyntaxHTAB=valuevalue=HTAB
DescriptionSet/Read the current text cursor horizontal position.
ExampleCLSFOR xpos = 0 TO TWIDTH STEP 2 LOOP
HTAB=xposPRINT HTAB
REPEATEND
AssociatedHVTAB, VTAB, PRINTAT
Functions, Constants & Procedures
59
main index
HVTABPurposeMove the current text cursor to the specified position.
SyntaxHVTAB(xpos,ypos)
DescriptionThe cursor is moved to the supplied column xpos and line ypos.Note that (0,0) is top-left of the text screen.
ExampleCLSHVTAB(TWIDTH/2-3,THEIGHT/2)PRINT "CENTRE"HVTAB(0,0)END
AssociatedHTAB, VTAB, PRINTAT
IF THENPurposeExecute a statement conditionally.
SyntaxIF condition THEN {statement}
DescriptionThe statement is executed when the condition evaluates to TRUE(not 0). Unlike some implementations of BASIC the THEN isrequired.
ExamplePRINT "Press Space Bar to Continue"LOOP
IF INKEY = 32 THEN BREAKREPEATPRINT "Space Bar Pressed"END
AssociatedELSE, ENDIF, SWITCH
Functions, Constants & Procedures
60
main index
INKEYPurposeGet a single character code from the keyboard withoutpausing.
Syntaxasciicode=INKEY
DescriptionThis is similar to GET except that program execution is notpaused; If no key is pressed, then -1 is returned. The followingconstants are predefined to test for special keys: KeyUp,KeyDown, KeyLeft, KeyRight, KeyIns, KeyHome, KeyDel, KeyEnd,KeyPgUp, KeyPgDn, KeyF1, KeyF2, KeyF3, KeyF4, KeyF5, KeyF6,KeyF7, KeyF8, KeyF9, KeyF10, KeyF11, KeyF12.
ExampleREM Show the ASCII code for the last keypressedLastKey = -1REM Press Esc to QuitLOOP
Key=INKEYIF Key<>-1 AND Key<>LastKey THEN
PRINT "Key Pressed: "; KeyLastKey = Key
ENDIFREPEAT
AssociatedGET, INPUT, SCANKEYBOARD
INKPurposeSet/Read the current text foreground colour.
Syntaxforegroundcolour=INKINK=foregroundcolour
DescriptionSet/Read the current text foreground (ink) colour.
ExamplePAPER=blackCLSstring$="This is multicoloured text"FOR I=1 TO LEN(string$) LOOP
INK=I MOD 15 + 1PRINT MID$(string$,I-1,1);
REPEATINK=whitePRINTEND
AssociatedPAPER
Functions, Constants & Procedures
61
main index
INPUTPurposeRead data from the keyboard into a variable.
SyntaxINPUT [prompt$,] variable
DescriptionWhen FUZE BASIC encounters the INPUT statement, programexecution stops, a question mark(?) is printed and it waits foryou to type something. It then assigns what you typed to thevariable. If you typed in a string when it was expecting a number,then it will assign zero to the number. To stop it printing thequestion mark, you can optionally give it a string to print.
ExampleINPUT "What is your Name? ", Name$PRINT "Hello " + Name$END
AssociatedINKEY
INPUT#PurposeRead data from a file.
SyntaxINPUT# handle,variable
DescriptionThis works similarly to the regular INPUT instruction, but readsfrom the file identified by the supplied handle rather than fromthe keyboard. Note that unlike the regular keyboard INPUTinstruction, INPUT# can only read one variable at a time.
Examplehandle=OPEN("testfile.txt")PRINT# handle,"Hello World"REWIND(handle)INPUT# handle,record$PRINT record$CLOSE (handle)END
AssociatedCLOSE, EOF, FFWD, OPEN, PRINT#, REWIND, SEEK
Functions, Constants & Procedures
62
main index
INTPurposeReturn the integer part of a number.
Syntaxintegerpart=INT(number)
DescriptionReturns the integer part of the specified number.
ExamplePRINT "The integer part of PI is ";PRINT INT(PI)END
LEFTPurposeTurns the turtle to the left (counter clockwise) by thegiven angle.
SyntaxLEFT(angle)
DescriptionTurns the virtual graphics turtle to the left (counter clockwise) bythe given angle in the current angle units.
ExampleREM Draw a box using turtle graphicsCLSCOLOUR=REDMOVE(50)DEGLEFT(90)MOVE(50)PENDOWNFOR I = 1 TO 4 LOOP
LEFT(90)MOVE(100)
REPEATUPDATEEND
AssociatedMOVE, MOVETO, PENDOWN, PENUP, RIGHT, TANGLE
Functions, Constants & Procedures
63
main index
LEFT$PurposeReturn the specified leftmost number of a characters froma string.
Syntaxsubstring$=LEFT$(string$,number)
DescriptionReturns a substring of string$ with number characters from theleft (start) of the string. If number is greater than or equal to thelength of string$ then the whole string is returned.
Examplestring$="The quick brown fox"FOR I=1 TO 20 LOOP
PRINT LEFT$(string$, I)REPEATEND
AssociatedMID$, RIGHT$
LENPurposeReturn the length of the specified character string.
Syntaxlength=LEN(string$)
DescriptionReturns the number of characters in the specified string$.
ExampleString$="The Quick Brown Fox"Chars=LEN(String$)PRINT "String Length is: ";CharsFOR I=0 TO Chars - 1 LOOP
Char$=MID$(String$,I,1)PRINT "Character No. ";I;" is "+Char$
REPEATEND
Functions, Constants & Procedures
64
main index
LINEPurposeDraw a line between two points
SyntaxLINE(xpos1,ypos1,xpos2,ypos2)
DescriptionDraw a line between point (xpos1,ypos1) and point (xpos2,ypos2)in the current COLOUR.
ExampleCLSCOLOUR = limeGH=GHEIGHTGW=GWIDTHLINE(10,10,10,GH-10)LINE(10,GH-10,GW-10,GH-10)LINE(GW-10,GH-10,GW-10,10)LINE(GW-10,10,10,10)UPDATEEND
AssociatedHLINE, LINETO, VLINE
LINETOPurposeDraw a line from the last point plotted.
SyntaxLINETO(xpos1,ypos1)
DescriptionDraws a line from the last point plotted (by the PLOT or LINEprocedures) to point (xpos1,ypos1).
ExampleCLSCOLOUR = yellowORIGIN(10,10)GH=GHEIGHTGW=GWIDTHLINETO(0,GH-20)LINETO(GW-20,GH-20)LINETO(GW-20, 0)LINETO(0,0)UPDATEEND
AssociatedHLINE, LINE, VLINE
Functions, Constants & Procedures
65
main index
LOADIMAGEPurposeLoad an image file into memory.
Syntaxhandle=LOADIMAGE(filename)
DescriptionLoad an image from a file with the specified filename. Thereturned handle can then be used to plot it on the screen withPLOTIMAGE.
ExampleCOLOUR=REDRECT(0,0,50,50,TRUE)COLOUR=WHITELINE(0,50,50,50)LINE(0,25,50,25)LINE(0,25,0,50)LINE(50,25,50,50)LINE(25,0,25,25)LINE(0,0,50,0)SAVEREGION("bricks.bmp",0,0,50,50)handle=LOADIMAGE("bricks.bmp")FOR X=0 TO GWIDTH STEP 50 LOOP
FOR Y=0 TO GHEIGHT STEP 50 LOOPPLOTIMAGE(handle,X,Y)
REPEATREPEATUPDATEEND
AssociatedGETIMAGEH, GETIMAGEW, PLOTIMAGE, FREEIMAGE
LOADMUSICPurposeLoad a music file into memory ready to be played.
Syntaxhandle=LOADMUSIC(filename)
DescriptionLoads an uncompressed music file in wav format (file extension.wav) from the file filename into memory and returns a handlewhich can then be used to play the music using the PLAYMUSICfunction.
Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)END
AssociatedPAUSEMUSIC, RESUMEMUSIC, SETMUSICVOL, STOPMUSIC
Functions, Constants & Procedures
66
main index
LOADSAMPLEPurposeLoad a sound sample into memory ready to be played.
Syntaxhandle=LOADSAMPLE(filename)
DescriptionThe LOADSAMPLE function loads a sound sample from theuncompressed WAV format file called filename and returns ahandle to it so that it can be played using the PLAYSAMPLEfunction. You can load up to 32 sound samples into memory atthe same time.
Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(4.5)END
AssociatedPAUSECHAN, PLAYSAMPLE, RESUMECHAN, SETCHANVOL,STOPCHAN
LOADSPRITEPurposeLoad a sprite from a file into memory.
SyntaxLOADSPRITE(filename$,index,subindex)
DescriptionThis loads a sprite from the supplied filename$ into memory andassociates it with the given sprite index and subindex. The indexis the handle returned by a call to NewSprite and the subindex isthe version of the sprite to allow for animation. The first subindexis 0.
ExampleCLSREM Create a new sprite with 1 versionSpriteIndex=NEWSPRITE(1)REM Load a sprite from a filefuzelogo$="logo.bmp"LOADSPRITE(fuzelogo$,SpriteIndex,0)REM Draw the sprite on the screenPLOTSPRITE(SpriteIndex,200,200,0)UPDATEEND
AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP
Functions, Constants & Procedures
67
main index
LOCALPurposeDefine variables to be local to a user defined procedure orfunction.
SyntaxLOCAL variable
DescriptionAllows a variable name to be reused in a procedure orfunction without affecting its value in the calling program.
ExampleX=10PRINT "Global X="+STR$(X)Proc Test()PRINT "Global X="+STR$(X)ENDDEF PROC Test()
PRINT "Global X="+STR$(X)LOCAL XX=5PRINT "Local X="+STR$(X)
ENDPROC
AssociatedDEF FN, DEF PROC
LOGPurposeReturn the natural logarithm of the specified number.
Syntaxnaturallogarithm = LOG(number)
DescriptionReturns the natural logarithm of the specified number.This is theopposite of the EXP function i.e. LOG(EXP(X)) = X. Logarithms areused in science to solve exponential radioactive decay problemsand in finance to solve problems involving compound interest.
ExampleX = EXP(10)PRINT X // Will print 22026.46579PRINT LOG(X) // Will print 10END
AssociatedEXP
Functions, Constants & Procedures
68
main index
MAXPurposeReturns the larger of two numbers.
Syntaxmaxvalue=MAX(number1,number2)
DescriptionReturns the larger (highest value) of number1 or number2.
ExampleREM Prints the value of number2number1=12.26number2=27.45PRINT MAX(number1, number2)END
AssociatedMIN
Functions, Constants & Procedures
MICROTIMEPurposeFind out how long the program has been running in 1,000,000sof a second.
Syntaxtime=MICROTIME
DescriptionThis returns a number which represents the time that yourprogram has been running in millionths of seconds.
ExampleREM Simple reaction timerWAIT(2)REM Make sure no key pressedWHILE INKEY<>-1 LOOPREPEATstime=MICROTIMEPRINT "Go!"WHILE INKEY=-1 LOOPREPEATetime = MICROTIMEPRINT "Your reaction time is ";PRINT etime-stime; " milliseconds"END
69
main index
MID$PurposeReturn characters from the middle of a string.
SyntaxMID$(string$, start, length)
DescriptionReturns the middle length characters of string$ startingfrom position start. The first character of the string isposition number 0.
ExampleREM Prints Quickstring$="The Quick Brown Fox"PRINT MID$(string$,4,5)END
AssociatedLEFT$, RIGHT$
Functions, Constants & Procedures
MINPurposeReturns the smaller of two numbers.
Syntaxminvalue=MIN(number1,number2)
DescriptionReturns the smaller (lowest value) of number1 or number2.
ExampleREM Prints the value of number1number1=12.26number2=27.45PRINT MIN(number1, number2)END
AssociatedMAX
70
main index
MODE7PLOTIMAGEPurposeExperimental
SyntaxNot telling yet!
DescriptionGreat fun
ExampleErm… early Nintendo kart based racing games !
Associated
MODE7PLOTSPRITEPurposeExperimental
SyntaxNot telling yet!
DescriptionGreat fun
Example
Erm… early Nintendo kart based racing games !
Associated
Functions, Constants & Procedures
71
main index
MOUSEOFFPurposeMake the mouse cursor invisible.
SyntaxMOUSEOFF
DescriptionMake the mouse cursor invisible within the FUZE BASIC window.This is the default value.
ExampleCLSMOUSEONLOOP
GETMOUSE(x,y,b)LINETO(x,y)UPDATEREM LOOP colour if left button pressedIF b & 1 THEN
COLOUR = COLOUR MOD 16 + 1ENDIFREM Exit if right button pressed
REPEAT UNTIL b & 4MOUSEOFFEND
AssociatedGETMOUSE, MOUSEON, MOUSEX, MOUSEY, SETMOUSE
Functions, Constants & Procedures
MOUSEONPurposeMake the mouse cursor visible.
SyntaxMOUSEON
DescriptionMake the mouse cursor visible within the FUZE BASIC window. Itis invisible by default.
ExampleCLSMOUSEONLOOP
GETMOUSE(x,y,b)LINETO(x,y)UPDATEREM LOOP colour if left button pressedIF b & 1 THEN
COLOUR = COLOUR MOD 16 + 1ENDIFREM Exit if right button pressed
REPEAT UNTIL b & 4MOUSEOFFEND
AssociatedGETMOUSE, MOUSEOFF, MOUSEX, MOUSEY, SETMOUSE
72
main index
MOUSEXPurposeTo find the mouse X position
Syntaxvalue = MOUSEX
DescriptionReturns the X position of the current mouse location
ExampleLOOPPRINTAT(0,0); "Mouse X Position="; MOUSEX;" "REPEAT
AssociatedGETMOUSE, MOUSEOFF, MOUSEON, MOUSEY,SETMOUSE
Functions, Constants & Procedures
MOUSEYPurposeTo find the mouse Y position
Syntaxvalue = MOUSEY
DescriptionReturns the Y position of the current mouse location
ExampleLOOPPRINTAT(0,0); "Mouse Y Position="; MOUSEY;" "REPEAT
AssociatedGETMOUSE, MOUSEOFF, MOUSEON, MOUSEX,SETMOUSE
73
main index
MOVEPurposeMove the graphics turtle forward
SyntaxMOVE(distance)
DescriptionThis causes the virtual graphics turtle to move forwards distancein screen pixels. A line will be drawn if the pen is down.
ExampleCLSCOLOUR=REDMOVE(50)DEGLEFT(90)MOVE(50)PENDOWNFOR I = 1 TO 4 LOOP
LEFT(90)MOVE(100)
REPEATUPDATEEND
AssociatedLEFT, MOVETO, PENDOWN, PENUP, RIGHT, TANGLE
Functions, Constants & Procedures
MOVETOPurposeMove the graphics turtle to a point on the screen.
SyntaxMOVETO(xpos,ypos)
DescriptionThis moves the virtual graphics turtle to the absolute location(xpos,ypos). A line will be drawn if the pen is down.
ExampleREM Draw a spiral in the centre of thescreenCLSCOLOUR=REDPENUPMOVETO(GWIDTH/2,GHEIGHT/2)PENDOWNFOR I=2 TO GWIDTH LOOP
MOVE(I)RIGHT(30)
REPEATUPDATEEND
AssociatedLEFT, MOVE, PENDOWN, PENUP, RIGHT, TANGLE
74
main index
NEWSPRITEPurposeCreate a new sprite.
Syntaxindex=NEWSPRITE(count)
DescriptionThis returns an index (or handle) to the internal sprite data. Youneed to use the index returned in all future sprite handlingfunctions/procedures. The count argument specifies the numberof different versions of the sprite.
Example overleaf…
Functions, Constants & Procedures
ExampleCLSCOLOUR=YELLOWCIRCLE(100,100,50,TRUE)SAVEREGION("pac1.bmp",50,50,101,101)COLOUR=BLACKTRIANGLE(100,100,150,125,150,75,TRUE)SAVEREGION("pac2.bmp",50,50,101,101)TRIANGLE(100,100,150,150,150,50,TRUE)SAVEREGION("pac3.bmp",50,50,101,101)CLSpacman=NEWSPRITE(3)LOADSPRITE("pac1.bmp",pacman,0)LOADSPRITE("pac2.bmp",pacman,1)LOADSPRITE("pac3.bmp",pacman,2)FOR X=1 TO GWIDTH STEP 25 LOOP
FOR S=0 TO 2 LOOPPLOTSPRITE(pacman,X,GHEIGHT/2,S)UPDATEWAIT(.1)
REPEATREPEATHIDESPRITE(pacman)END
AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, LOADSPRITE,PLOTSPRITE, SETSPRITETRANS, SPRITECOLLIDE,SPRITECOLLIDEPP
75
main index
NUMFORMATPurposeControl how numbers are formatted.
SyntaxNUMFORMAT(width,decimals)
DescriptionYou can affect the way numbers are printed using theNUMFORMAT procedure. This takes 2 arguments, the widthspecifying the total number of characters to print and thedecimals the number of characters after the decimal point.Numbers printed this way are right-justified with leading spacesinserted if required. NUMFORMAT (0,0) restores the output tothe general purpose format used by default.
ExampleNUMFORMAT(6,4)REM Prints 3.1416PRINT PINUMFORMAT(0,0)REM Prints 3.141592654PRINT PIEND
AssociatedPRINT, PRINTAT
Functions, Constants & Procedures
OPENPurposeOpen a file for read or write.
Syntaxhandle=OPEN(filename$)
DescriptionThe OPEN function opens a file and makes it available forreading or writing and returns the numeric handle associatedwith the file. The file is created if it doesn’t exist, or if it does existthe file pointer is positioned at the start of the file.
Examplehandle = OPEN("testfile.txt")PRINT# handle, "Colin"PRINT# handle, 47CLOSE(handle)handle = OPEN("testfile.txt")INPUT# handle, Name$INPUT# handle, AgeCLOSE(handle)PRINT "Name: " + Name$PRINT "Age: "; AgeEND
AssociatedCLOSE, EOF, FFWD, INPUT#, PRINT#, REWIND, SEEK
76
main index
ORIGINPurposeMove the graphics origin.
SyntaxORIGIN(xpos,ypos)
DescriptionThis changes the graphics origin for the Cartesian plottingprocedures. The xpos, ypos coordinates are always absolutecoordinates with (0,0) being bottom left (the default).
ExampleCLSCOLOUR=yellowREM Move the origin to the screen centreORIGIN(GWIDTH/2, GHEIGHT/2)PLOT(-100,-100)LINETO(-100,100)LINETO(100,100)LINETO(100,-100)LINETO(-100,-100)UPDATEORIGIN(0,0)END
AssociatedGHEIGHT, GWIDTH
Functions, Constants & Procedures
PAPERPurposeSet/Read the current text background colour.
Syntaxbackgroundcolour=PAPERPAPER=backgroundcolour
DescriptionSet/Read the current text background (paper) colour. Clearscreen (CLS) will set the entire background to this colour.
ExamplePRINT "Text background colour "; PAPERPAPER=REDPRINT "Text background colour "; PAPERPAPER=7PRINT "Text background colour "; PAPEREND
AssociatedINK, PAPERON, PAPEROFF
77
main index
PAPEROFFPurposeSwitches the text background colour off.
SyntaxPAPEROFF
DescriptionThis function switches the background text colour off. It can beturned on or off so that the text background does not obscurewhatever is behind it.
ExampleLOOP INK = Orange PaperOn fontSize (RND (10) + 1) printAt (RND(tWidth), RND(tHeight - 1)); "ON"; WAIT(.3) INK = Yellow PaperOff fontSize (RND (10) + 1) printAt (RND(tWidth), RND(tHeight - 1)); "OFF"; WAIT(.3)REPEAT
AssociatedINK, PAPER, PAPERON
Functions, Constants & Procedures
PAPERONPurposeSets text background colour to display
SyntaxPAPERON
DescriptionThis function switches the background text colour on. It can beturned on or off so that the text background does not obscurewhatever is behind it.
ExampleLOOP INK = Orange PaperOn fontSize (RND (10) + 1) printAt (RND(tWidth), RND(tHeight - 1)); "ON"; WAIT(.3) INK = Yellow PaperOff fontSize (RND (10) + 1) printAt (RND(tWidth), RND(tHeight - 1)); "OFF"; WAIT(.3)REPEAT
AssociatedINK, PAPER, PAPEROFF
78
main index
PAUSECHANPurposePause the playing of a sound sample.
SyntaxPAUSECHAN(handle)
DescriptionThis function pauses the playing of the sound sampleassociated with the handle returned by LOADSAMPLE that hasbeen started using PLAYSAMPLE. The sample can be resumedwhere it left off using RESUMECHAN
Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(3)PAUSECHAN(intro)Wait(2)RESUMECHAN(intro)END
AssociatedLOADSAMPLE, PLAYSAMPLE, RESUMECHAN,SETCHANVOL, STOPCHAN
Functions, Constants & Procedures
PAUSEMUSICPurposePause a playing music file
SyntaxPAUSEMUSIC
DescriptionPauses a playing music track which can them be restartedusing RESUMEMUSIC.
Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)PAUSEMUSIC
AssociatedLOADMUSIC, RESUMEMUSIC, SETMUSICVOL, STOPMUSIC
79
main index
PENDOWNPurposeStart drawing using the graphics turtle.
SyntaxPENDOWN
DescriptionThis lowers the “pen” that the virtual graphics turtle is using todraw with. Nothing will be drawn until you execute thisprocedure.
ExampleREM Draw a spiral in the centre of thescreenCLSCOLOUR=REDPENUPMOVETO(GWIDTH/2,GHEIGHT/2)PENDOWNFOR I=2 TO GWIDTH LOOP
MOVE(I)RIGHT(30)
REPEATUPDATEEND
AssociatedLEFT, MOVE, MOVETO, PENUP, RIGHT, TANGLE
Functions, Constants & Procedures
PENUPPurposeStop drawing using the graphics turtle.
SyntaxPENUP
DescriptionThis lifts the “pen” that the virtual graphics turtle uses to draw.You can move the turtle without drawing while the pen is up.
ExampleREM Draw a spiral in the centre of thescreenCLSCOLOUR=REDPENUPMOVETO(GWIDTH/2,GHEIGHT/2)PENDOWNFOR I=2 TO GWIDTH LOOP
MOVE(I)RIGHT(30)
REPEATUPDATEEND
AssociatedLEFT, MOVE, MOVETO, PENDOWN, RIGHT, TANGLE
80
main index
PI / PI2PurposeReturns the value of the constant Pi and Pi divided by 2
Syntaxvalueofpi=PI / valueofpi=PI divided by 2
DescriptionReturns an approximation of the value of the constant pi whichis the ratio of a circle’s circumference to its diameter(approximately 3.141592654) which is widely used inmathematics, specifically trigonomtry and geometry.
ExamplePRINT FN AreaOfCircle(12)ENDDEF FN AreaOfCircle(withRadius)
LOCAL resultresult=PI*withRadius*withRadius
= result
Functions, Constants & Procedures
PINMODEPurposeConfigure the mode of a pin on the Pi’s GPIO.
SyntaxPINMODE(pinno,pinmode)
DescriptionConfigures the mode of a pin on the Pi’s GPIO. It takes anargument which specifies the mode of the pin - input, output orPWM output. The modes are:
0 pinINPUT1 pinOUTPUT2 pinPWM
ExampleREM Set pin 12 to inputPINMODE(12,1)REM Wait for button to be pushedUNTIL DIGITALREAD(12) LOOPREPEATPRINT "Button Pushed"END
AssociatedDIGITALREAD, DIGITALWRITE, PWMWRITE,SOFTPWMWRITE
81
main indexFunctions, Constants & Procedures
PLAYMUSICPurposeStart playing a music track.
SyntaxPLAYMUSIC(handle,repeats)
DescriptionThis function plays a music track previously loaded using theLOADMUSIC function which returns the handle. The repeats arethe number of times to play the track.
Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)END
AssociatedLOADMUSIC, PAUSEMUSIC, RESUMEMUSIC,SETMUSICVOL, STOPMUSIC
PLAYSAMPLEPurposeStart playing a sound sample.
SyntaxPLAYSAMPLE(handle,channel,loops)
DescriptionThis function plays a sound previously loaded using theLOADSAMPLE function which returns the handle. The channel is0, 1, 2 or 3 which lets you play up to 4 concurrent samples. Theloops parameter is different to the repeats one in the PLAYMUSICfunction. Here it means the number of times to loop the sample– zero means no loops which means play it ONCE.
Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(4.5)END
AssociatedLOADSAMPLE, PAUSECHAN, RESUMECHAN, SETCHANVOL,STOPCHAN
82
main index
PLOTPurposeDraw a single point on the screen.
SyntaxPLOT(xpos,ypos)
DescriptionThis plots a single pixel at screen location (xpos,ypos) inthe selected graphics mode in the selected colour. Notethat (0,0) is bottom left by default.
ExampleCLSLOOP
IF INKEY<>-1 THEN BREAKxpos=RND(GWIDTH)ypos=RND(GHEIGHT)COLOUR=RND(16)PLOT(xpos, ypos)UPDATE
REPEATEND
AssociatedLINE, LINETO, MOVETO, RECT. TRIANGLE, CIRCLE, ELLIPSE,COLOUR, RGBCOLOUR
Functions, Constants & Procedures
PLOTIMAGEPurposeDisplay a loaded image on the screen.
SyntaxPLOTIMAGE(handle,xpos,ypos)
DescriptionPlot an image previously loaded using LOADIMAGE (using the handlereturned by LOADIMAGE) on the screen at coordinates (xpos,ypos).
ExampleCOLOUR=REDRECT(0,0,50,50,TRUE)COLOUR=WHITELINE(0,50,50,50)LINE(0,25,50,25)LINE(0,25,0,50)LINE(50,25,50,50)LINE(25,0,25,25)LINE(0,0,50,0)SAVEREGION("bricks.bmp",0,0,50,50)handle=LOADIMAGE("bricks.bmp")FOR X=0 TO GWIDTH STEP 50 LOOP
FOR Y=0 TO GHEIGHT STEP 50 LOOPPLOTIMAGE(handle,X,Y)
REPEATREPEATUPDATEEND
AssociatedGETIMAGEH, GETIMAGEW, LOADIMAGE, FREEIMAGE
83
main index
PLOTSPRITEPurposeDraw a sprite on the screen.
SyntaxPLOTSPRITE(index,xpos,ypos,subindex)
DescriptionThis plots the sprite index and version subindex at thecoordinates (xpos, ypos). The coordinates specify the bottom-leftcorner of the bounding rectangle of the sprite.
ExampleCLSREM Create a new sprite with 1 versionSpriteIndex=NEWSPRITE(1)REM Load a sprite from a filefuzelogo$="/usr/share/fuze/logo.bmp"LOADSPRITE(fuzelogo$,SpriteIndex,0)REM Draw the sprite on the screenPLOTSPRITE(SpriteIndex,200,200,0)UPDATEEND
AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, LOADSPRITE,NEWSPRITE, SETSPRITEALPHA, SETSPRITEANGLE,SETSPRITEFLIP, SETSPRITESIZE, SETSPRITETRANS,SPRITECOLLIDE, SPRITECOLLIDEPP, SPRITEOUT
Functions, Constants & Procedures
POLYENDPurposeDraw the filled polygon started by PolyStart.
SyntaxPOLYEND
DescriptionThis marks the end of drawing a polygon. When this iscalled, the stored points will be plotted on the screen andthe polygon will be filled.
ExampleCLSPROC Hexagon(200,200,50,Red)UPDATEENDDEF Proc Hexagon(x,y,l,c)
COLOUR=cPOLYSTARTPOLYPLOT(x+l,y)POLYPLOT(x+l/2,y-l*SQRT(3/2))POLYPLOT(x-l/2,y-l*SQRT(3/2))POLYPLOT(x-l,y)POLYPLOT(x-l/2,y+l*SQRT(3/2))POLYPLOT(x+l/2,y+l*SQRT(3/2))POLYEND
ENDPROC
AssociatedPOLYPLOT, POLYSTART
84
main indexFunctions, Constants & Procedures
POLYPLOTPurposeAdd a point to a filled polygon.
SyntaxPOLYPLOT(xpos,ypos)
DescriptionThis remembers the given xpos,ypos coordinates as part of afilled polygon. Nothing is actually drawn on the screen until thePolyEnd instruction is executed. Polygons can have a maximumof 64 points.
ExampleCLSPROC Hexagon(200,200,50,Red)UPDATEENDDEF Proc Hexagon(x,y,l,c)
COLOUR=cPOLYSTARTPOLYPLOT(x+l,y)POLYPLOT(x+l/2,y-l*SQRT(3/2))POLYPLOT(x-l/2,y-l*SQRT(3/2))POLYPLOT(x-l,y)POLYPLOT(x-l/2,y+l*SQRT(3/2))POLYPLOT(x+l/2,y+l*SQRT(3/2))POLYEND
ENDPROC
AssociatedPOLYEND, POLYSTART
POLYSTARTPurposeStart drawing a filled polygon.
SyntaxPOLYSTART
DescriptionThis marks the start of drawing a filled polygon.
ExampleCLSPROC Hexagon(200,200,50,Red)UPDATEENDDEF Proc Hexagon(x,y,l,c)
COLOUR=cPOLYSTARTPOLYPLOT(x+l,y)POLYPLOT(x+l/2,y-l*SQRT(3/2))POLYPLOT(x-l/2,y-l*SQRT(3/2))POLYPLOT(x-l,y)POLYPLOT(x-l/2,y+l*SQRT(3/2))POLYPLOT(x+l/2,y+l*SQRT(3/2))POLYEND
ENDPROC
AssociatedPOLYEND, POLYPLOT
85
main indexFunctions, Constants & Procedures
PLOTTEXTPurposeDisplay text using graphic coordinates.
SyntaxPLOTTEXT(“text”, xpos, ypos)
DescriptionThe PRINT command uses the cursor coordinates to display textwhereas PLOTTEXT can position text at a specified pixel location
ExampleLOOP INK = RND (30) fontSize (RND (10) + 1) plotText("HELLO", RND(gWidth), RND(gHeight-1)) UPDATEREPEAT
AssociatedPRINT, PRINTAT
PRINTPurposeOutput text to the screen
SyntaxPRINT {text}{;text}
DescriptionOutputting text to the screen is done via the PRINT command.The PRINT command is quite versatile and will print anycombination of numbers and strings separated by the semi-colon (;). A trailing semi-colon will suppress the printing of a newline.
ExamplePRINT "Hello Colin"PRINT "Hello ";name$="Colin"PRINT name$PRINT "Hello "; name$END
AssociatedNUMFORMAT, PRINTAT
86
main indexFunctions, Constants & Procedures
PRINT#PurposePrint data to a file.
SyntaxPRINT# handle,data
DescriptionThe PRINT# instruction acts just like the regular PRINTinstruction except that it sends data to the file identified by thesupplied file-handle rather than to the screen. Numbers areformatted according to the settings of NUMFORMAT. It isstrongly recommended to only print one item per line if you aregoing to read those items back into a FUZE BASIC programagain.
Examplehandle = OPEN("testfile.txt")PRINT# handle, "Hello World"CLOSE (handle)END
AssociatedCLOSE, EOF, FFWD, INPUT#, OPEN, REWIND, SEEK
PRINTATPurposeSet the text cursor position and print
SyntaxPRINTAT( x, y ); "text"
DescriptionUse to position the text cursor at the specified location andprint. Useful for laying out text and or variables at any preferredscreen location.
Examplename$ = "Sam"age = 10PRINTAT( 0, 5 ); "My name is "; name$PRINTAT( 5, 10 ); "I am "; age ; " yearsold"END
AssociatedCHR$, HTAB, HVTAB, INK,PAPER, PRINT, PRINT, THEIGHT, TWIDTH, VTAB
87
main indexFunctions, Constants & Procedures
PROCPurposeCall a user defined procedure.
SyntaxPROC name({argument}{,argument})
DescriptionCalls the specified user defined procedure called name with thespecified arguments. Once the procedure has been executedcontrol returns to the command following.
ExampleCLSLOOP
x=RND(TWIDTH)y=RND(THEIGHT)c=RND(15)Text$=”Blossom”PROC text(text$, x, y, c)
REPEATENDDEF PROC text(text$, x, y, c) INK=c PRINTAT(x,y); text$ENDPROC
AssociatedDEF PROC, ENDPROC
PWMWRITEPurposeOutput a PWM waveform on the selected pin.
SyntaxPWMWRITE(pinno,pinvalue)
DescriptionThis procedure outputs a PWM waveform on the selected pin.The pin must be configured for PWM mode beforehand. Thevalue set should be between 0 and 100.
ExampleREM Set pin 1 to PWM output modePINMODE(1,2)PWMWRITE (1,50)END
AssociatedDIGITALREAD, DIGITALWRITE, PINMODE
88
main indexFunctions, Constants & Procedures
RADPurposeSet angle units to radians.
SyntaxRAD
DescriptionSwitches the internal angle system to radians. There are 2 * PIradians in a full circle.
ExampleREM Draw an ellipse in the screen centreCLSRADFOR Angle=0 TO 2 * PI STEP 0.01 LOOP
Xpos=100*COS(Angle)+GWIDTH / 2Ypos=50*SIN(Angle)+GHEIGHT / 2PLOT(Xpos,Ypos)
REPEATEND
AssociatedCLOCK, DEG
READPurposeRead data into program variables.
SyntaxREAD variable {,variable}
DescriptionTo get data into your program variables, we use the READinstruction. We can read one, or many items of data at a time.
ExampleREM Load the name of the days of theREM week into a string arrayDATA "Monday", "Tuesday", "Wednesday"DATA "Thursday", "Friday", "Saturday"DATA "Sunday"DIM DaysOfWeek$(7)FOR Day = 1 TO 7 LOOP
READ DaysOfWeek$(Day)REPEATPRINT "The third day of the week is ";PRINT DaysOfWeek$(3)END
AssociatedDATA, RESTORE
89
main indexFunctions, Constants & Procedures
RECTPurposeDraw a rectangle on the screen.
SyntaxRECT(xpos,ypos,width,height,fill)
DescriptionDraws a rectangle at position (xpos,ypos) with width and height.The final parameter, fill is either TRUE or FALSE, and specifiesfilled (TRUE) or outline (FALSE).
ExampleCLSLOOP
COLOUR=RND(16)x=RND(GWIDTH)y=RND(GHEIGHT)w=RND(GWIDTH / 4)h=RND(GHEIGHT / 4)f=RND(2)RECT(x,y,w,h,f)UPDATEIF INKEY<>-1 THEN BREAK
REPEATEND
AssociatedCIRCLE, ELLIPSE, TRIANGLE
REPEAT UNTILPurposeLoop until the specified condition is met.
SyntaxLOOP
{statements}REPEAT UNTIL condition
DescriptionExecute the statements one or more times until the condition isTRUE (not 0).
ExampleNumber=INT(RND(10)) + 1Guess=0REM Guessing GamePRINT "Guess a Number Between 1 and 10"LOOP
INPUT "Enter Your Guess: ", GuessIF (Number<>Guess) THEN
PRINT "Incorrect Guess Again"ENDIF
REPEAT UNTIL Number = GuessPRINT "You are Correct!"END
AssociatedBREAK, CONTINUE, LOOP, LOOP REPEAT, FOR REPEAT,
90
main indexFunctions, Constants & Procedures
RESTOREPurposeReset the DATA pointer.
SyntaxRESTORE
DescriptionWith no lineno specified resets the READ command to the veryfirst DATA statement in the program.
ExampleDATA "Monday", "Tuesday", "Wednesday"DATA "Thursday", "Friday", "Saturday","Sunday"FOR Day = 1 TO 3 LOOP
READ DayOfWeek$REPEATPRINT DayOfWeek$RESTOREFOR Day = 1 TO 4 LOOP
READ DayOfWeek$REPEATPRINT DayOfWeek$END
AssociatedDATA, READ
RESUMECHANPurposeResume the playing of a sound sample.
SyntaxRESUMECHAN(handle)
DescriptionThis function resumes the playing of the sound sampleassociated with the handle returned by LOADSAMPLE that hasbeen started using PLAYSAMPLE and paused using PAUSECHAN.
Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(3)PAUSECHAN(intro)WAIT(2)RESUMECHAN(intro)END
AssociatedLOADSAMPLE, PAUSECHAN, PLAYSAMPLE, SETCHANVOL,STOPCHAN
91
main indexFunctions, Constants & Procedures
RESUMEMUSICPurposeResumes music playing after it has been paused.
SyntaxRESUMEMUSIC
DescriptionResumes the playing of a music track previously pausedusing PAUSEMUSIC.
Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)PAUSEMUSICWAIT(1)RESUMEMUSIC
AssociatedLOADMUSIC, PAUSEMUSIC, SETMUSICVOL, STOPMUSIC
REWINDPurposeMove the file pointer to the start of a file.
SyntaxREWIND(handle)
DescriptionMove the file pointer to the start of the file specified byhandle.
Examplehandle=OPEN ("rewindtest.txt")PRINT# handle,"First Record"PRINT# handle,"Second Record"CLOSE(handle)handle=OPEN("rewindtest.txt")INPUT# handle, record$PRINT record$REWIND(handle)REM reads the first record againINPUT# handle, record$PRINT record$CLOSE (handle)END
AssociatedCLOSE, EOF, FFWD, INPUT#, OPEN, PRINT#, SEEK
92
main indexFunctions, Constants & Procedures
RGBCOLOURPurposeSet the current graphical plot colour to an RGB(Red,Green, Blue) value.
SyntaxRGBCOLOUR(red,green,blue)
DescriptionThis sets the current graphical plot colour to an RGB (Red,Green,Blue) value. The values should be from 0 to 255.
ExampleCLSPRINT "Draw Spectrum"FOR v = 0 TO 255 LOOP
RGBCOLOUR(255,v,0)LINE(v,300,v,400)RGBCOLOUR(v,255,0)LINE(511-v,300,511-v,400)RGBCOLOUR(0,255-v,v)LINE(512+v,300,512+v,400)RGBCOLOUR(0,v,255)LINE(768+v,300,768+v,400)
REPEATUPDATEEND
AssociatedCOLOUR, INK, PAPER
RIGHTPurposeTurns the turtle to the right (clockwise) by the given angle.
SyntaxRIGHT(angle)
DescriptionTurns the virtual graphics turtle to the right (clockwise) bythe given angle in the current angle units.
ExampleCLSPRINT "Draw Pink Hexagon"PENUPCOLOUR = PINKPENDOWNFOR I = 1 TO 6 LOOP
RIGHT(60)MOVE(100)
REPEATEND
AssociatedLEFT, MOVE, MOVETO, PENDOWN, PENUP, TANGLE
93
main indexFunctions, Constants & Procedures
RIGHT$PurposeReturn the specified rightmost number of a charactersfrom a string.
Syntaxsubstring$=RIGHT$(string$,number)
DescriptionReturns a substring of string$ with number characters from theright (end) of the string. If number is greater than or equal to thelength of string$ then the whole string is returned.
ExampleString$="The quick brown fox"FOR I=1 TO 20 LOOP
PRINT RIGHT$(String$, I)REPEATEND
AssociatedLEFT$, MID$
ROTATEIMAGEPurposeReturn the specified rightmost number of a charactersfrom a string.
Syntaxsubstring$=RIGHT$(string$,number)
DescriptionReturns a substring of string$ with number characters from theright (end) of the string. If number is greater than or equal to thelength of string$ then the whole string is returned.
Exampleimage = loadImage ("screen.png")plotImage (image, 0, 0)UPDATEWAIT (2)CLSrotateImage (image, 90)plotImage (image, 0, 0)UPDATEWAIT (2)END
AssociatedLOADIMAGE, SCALEIMAGE
94
main indexFunctions, Constants & Procedures
RNDPurposeGenerate a random number in a given range.
Syntaxrandom=RND(range)
DescriptionThis function returns a random number based on the value ofrange. If range is zero, then the last random number generated isreturned, if range is 1, then a random number from 0 to 1 isreturned, otherwise a random number from 0 up to, but notincluding range is returned.
ExampleDiceRoll=RND(6)+1PRINT "Dice Roll: "; DiceRollCoinToss=RND(2)IF CoinToss=0 THEN
PRINT "Heads"ELSE
PRINT "Tails"ENDIFEND
AssociatedSEED
SAVEREGIONPurposeSave a snapshot of an area of the screen to an image file.
SyntaxSAVEREGION(file$,xpos,ypos,width,height)
Description
Takes a snapshot of an area of the current screen specified bythe rectangle with bottom left at coordinates (xpos,ypos) ofspecified width and height, and saves it to the file named file$ ina bitmap (.bmp) format.
SAVEREGION Example
CLSCOLOUR=YELLOWCIRCLE (100,100,50,TRUE)COLOUR=BLACKTRIANGLE(100,100,150,150,150,50,TRUE)TRIANGLE(100,100,150,125,150,75,TRUE)SAVEREGION ("pac1.bmp",50,50,101,101)CLSpacman=NEWSPRITE(1)LOADSPRITE("pac1.bmp",pacman,0)FOR X=1 TO GWIDTH STEP 25 LOOPPLOTSPRITE(pacman,X,GHEIGHT/2,0)UPDATEWAIT(.1)REPEAT
AssociatedSAVESCREEN
95
main indexFunctions, Constants & Procedures
SAVESCREENPurposeSave a snapshot of the screen to an image file.
SyntaxSAVESCREEN(filename$)
DescriptionThis takes a snapshot of the current screen and saves it tothe filename given in a bitmap (.bmp) format file.
ExampleCLSPRINT "Draw Spectrum"FOR v = 0 TO 255 LOOP
RGBCOLOUR(255,v,0)LINE(v,300,v,400)RGBCOLOUR(v,255,0)LINE(511-v,300,511-v,400)RGBCOLOUR(0,255-v,v)LINE(512+v,300,512+v,400)RGBCOLOUR(0,v,255)LINE(768+v,300,768+v,400)
REPEATUPDATESAVESCREEN("screenshot.bmp")END
AssociatedSAVEREGION
SCALEIMAGEPurposeResize a loaded image.
SyntaxSCALEIMAGE(handle, percent)
DescriptionScales a preloaded image by a specified percentage.
Exampleimage = loadImage ("screen.png")plotImage (image, 0, 0)UPDATEWAIT (2)CLSscaleImage (image, 50)plotImage (image, 0, 0)UPDATEWAIT (2)END
AssociatedLOADIMAGE, ROTATEIMAGE
96
main indexFunctions, Constants & Procedures
SCANKEYBOARDPurposeScan for a key pressed down.
SyntaxSCANKEYBOARD(keycode)
DescriptionAllows you to detect that any of the keys have been pressed(including special keys) and also to detect mutiple keys pressedat the same time. The keycode parameter indicates the key pressto be scanned for e.g scanSpace is the space bar. See the end ofthis guide for a full list of SCANKEYBOARD keycodes.
ExamplePRINT "Press Ctrl-Alt-Delete"LOOP
LCtrl = SCANKEYBOARD(scanLCtrl)LAlt = SCANKEYBOARD(scanLAlt)Delete = SCANKEYBOARD(scanDelete)Reboot = LCtrl AND LAlt AND Delete
REPEAT UNTIL RebootPRINT "Rebooting…"CLEARKEYBOARDEND
AssociatedCLEARKEYBOARD, GET, INKEY, INPUT
SCLOSEPurposeClose an open serial port.
SyntaxSCLOSE(handle)
DescriptionThis closes a serial port and frees up any resources used by it. It’snot strictly necessary to do this when you end your program, butit is considered good practice.
ExampleREM Read a character from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)char$=SGET$(arduino)PRINT char$SCLOSE(arduino)END
AssociatedSGET, SGET$, SOPEN, SPUT, SPUT$, SREADY
97
main indexFunctions, Constants & Procedures
SCROLLDOWNSCROLLLEFTSCROLLRIGHTSCROLLUPPurposeScroll a region of the screen down.
SyntaxSCROLLDOWN(xpos,ypos,width,height,pixels)
DescriptionScroll the region of the screen specified by the rectangleat position (xpos,ypos) with dimensions width X heightdown by the specified number of pixels.
Example overleaf
ExampleCLSW=100 // WidthS=2 // Step SizeX=(GWIDTH-W)/2Y=(GHEIGHT-W)/2COLOUR=WHITERECT(X,Y,W,W,TRUE)RECT(X+W,Y+W,W,W,TRUE)RECT(X-2,Y-2,W*2+4,W*2+4,FALSE)UPDATECOLOUR=BLACKFOR I=1 TO W STEP S LOOP
SCROLLUP(X,Y,W,W*2,S)SCROLLDOWN(X+W,Y,W,W*2,S)UPDATEWAIT(0.01)
REPEATFOR I = 1 TO W STEP S LOOP
SCROLLRIGHT(X,Y+W,W*2,W,S)SCROLLLEFT(X,Y,W*2,W,S)WAIT(0.01)
UPDATEREPEATEND
AssociatedSCROLLLEFT, SCROLLRIGHT, SCROLLUP
98
main indexFunctions, Constants & Procedures
SEEDPurposeSeed the random number generator.
SyntaxSEED=value
DescriptionThis can be assigned to initialise the random number generator,or you can read it to find the current seed.
ExampleSEED=10PRINT RND(100)SEED=10REM Will print the same numberPRINT RND(100)REM Will print a different numberPRINT RND(100)END
AssociatedRND
SEEKPurposeMove the file pointer to any place in the file.
SyntaxSEEK(handle,offset)
DescriptionThe SEEK instruction moves the file pointer to any place in the file. It caneven move the file pointer beyond the end of the file in which case thefile is extended. The argument supplied to SEEK is an absolute numberof bytes from the start of the file. If you are using random access filesand want to access the 7th record in the file, then you need to multiplyyour record size by 7 to get the final location to seek to.
Examplehandle=OPEN("TestFile.txt")recSize = 20FOR recNo=0 TO 10 LOOP
record$ = "Record " + STR$(recNo)pad = recSize - LEN(record$)PRINT# handle,record$;SPACE$(pad)
REPEATREM read the 7th recordSEEK (handle,(recSize+1)*7)INPUT# handle,record$PRINT record$CLOSE(handle)END
AssociatedCLOSE, EOF, FFWD, INPUT#, OPEN, PRINT#, REWIND
99
main indexFunctions, Constants & Procedures
SENSEACCELX / Y / ZPurposeReturns the value of the Raspberry Pi senseHAT accelerometer.
Syntaxvalue=SENSEACCELXvalue=SENSEACCELYvalue=SENSEACCELZ
Description
The Raspberry Pi senseHAT has a number of built in sensors. Theaccelerometer can be accessed with this function.
ExampleCLSLOOPPRINT “Sense Accelerometer X=”; senseAccelXPRINT “Sense Accelerometer Y=”; senseAccelYPRINT “Sense Accelerometer Z=”; senseAccelZREPEATEND
AssociatedsenseCompass, senseGyro
SENSECLSPurposeSets all of the LEDs on the Raspberry Pi senseHAT to off.
SyntaxSENSECLS
Description
Sets an RGB value of 0, 0, 0 to all of the matrix LEDs therebyclearing the display.
ExampleCLSsensePlot(2,2)WAIT (1)senseClsEND
AssociatedsensePlot, senseRect, senseScroll, senseHFlip, senseVflip,senseRGBcolour, senseGetRGB, senseLine
100
main indexFunctions, Constants & Procedures
SENSECOMPASSX / Y / ZPurposeReturns the value of the Raspberry Pi senseHAT compass.
Syntaxvalue=SENSECOMPASSXvalue=SENSECOMPASSYvalue=SENSECOMPASSZ
Description
The Raspberry Pi senseHAT has a number of built in sensors. Thecompass can be accessed with this function.
ExampleCLSLOOPPRINT “Sense Compass X=”; senseCompassXPRINT “Sense Compass Y=”; senseCompassYPRINT “Sense Compass Z=”; senseCompassZREPEATEND
AssociatedsenseAccel, senseGyro,
SENSEGETRGBPurposeReturn the values used by a Raspberry Pi senseHAT LED
SyntaxSENSEGETRGB(xpos, ypos, red, green, blue)
Description
Returns the Red, Green and Blue values from a given LED at thespecified matrix coordinates. It is possible to use this for collisiondetection in games using the senseHAT.
ExampleCLSsenseRGBcolour (0, 0, 255)sensePlot (0, 0)SenseGetRGB (0, 0, R, G, B)PRINT “Red=”; RPRINT “Green=”; GPRINT “Blue=”; BEND
AssociatedsenseCls, sensePlot, senseRect, senseScroll, senseHFlip,senseVflip, senseRGBcolour, , senseLine
101
main indexFunctions, Constants & Procedures
SENSEGYROX / Y / ZPurposeReturns the value of the Raspberry Pi senseHAT gyro.
Syntaxvalue=SENSEGYROXvalue=SENSEGYROYvalue=SENSEGYROZ
Description
The Raspberry Pi senseHAT has a number of built in sensors. Thegyro can be accessed with this function.
ExampleCLSLOOPPRINT “Sense Gyro X=”; senseGyroXPRINT “Sense Gyro Y=”; senseGyroYPRINT “Sense Gyro Z=”; senseGyroZREPEATEND
AssociatedsenseAccel, senseCompass
SENSEHEIGHTPurposeReturns the value of the Raspberry Pi senseHAT height sensor.
Syntaxvalue=SENSEHEIGHT
Description
The Raspberry Pi senseHAT has a number of built in sensors.Height above sea level can be accessed with this function. Note,this does not work well indoors.
ExampleCLSLOOPPRINT “Height”; senseHeightREPEATEND
AssociatedsenseHumidity, sensePressure, senseTemperature
102
main indexFunctions, Constants & Procedures
SENSEHFLIPPurposeHorizontally flips the Raspberry Pi senseHAT LED matrix.
SyntaxSENSEHFLIP
Description
Reverses (flips) the LED matrix display horizontally.
ExampleCLSSenseRGBcolour(255,0,0)senseLine(0,0,0,7)SenseRGBcolour(0,255,0)senseLine(0,7,7,7)LOOPsenseHflipWAIT(1)SenseVflipWAIT(1)END
AssociatedsenseCls, sensePlot, senseRect, senseScroll, senseVflip,senseRGBcolour, senseGetRGB, , senseLine
SENSEHUMIDITYPurposeReturns the value of the Raspberry Pi senseHAT humidity sensor.
Syntaxvalue=SENSEHUMIDITY
Description
The Raspberry Pi senseHAT has a number of built in sensors.Humidity can be accessed with this function.
ExampleCLSLOOPPRINT “Humidity”; senseHumidityREPEATEND
AssociatedsenseHeight, sensePressure, senseTemperature
103
main indexFunctions, Constants & Procedures
SENSELINEPurposeLights a line on the Raspberry Pi senseHAT LED matrix.
SyntaxSENSELINE(x1, y1, x2, y2)
Description
Sets the RGB values, defined by senseRGBcolour, to a line of LEDson the Raspberry Pi senseHAT LED matrix. The line is displayedfrom x1, y1 to x2, y2.
ExampleCLSSenseRGBcolour(255,0,0)senseLine(0,0,0,7)SenseRGBcolour(0,255,0)senseLine(0,7,7,7)LOOPsenseHflipWAIT(1)SenseVflipWAIT(1)END
AssociatedsenseCls, sensePlot, senseRect, senseScroll, senseVflip,senseRGBcolour, senseGetRGB
SENSEPLOTPurposeLights an LED on the Raspberry Pi senseHAT LED matrix.
SyntaxSENSEPLOT(xpos, ypos)
Description
Sets the RGB values, defined by senseRGBcolour, to a single LEDon the Raspberry Pi senseHAT LED matrix.
ExampleCLSSenseRGBcolour(255,0,0)sensePlot(0,0)SenseRGBcolour(0,255,0)sensePlot(7,7)END
AssociatedsenseCls, senseHflip, senseRect, senseScroll, senseVflip,senseRGBcolour, senseGetRGB, senseLine
104
main indexFunctions, Constants & Procedures
SENSEPRESSUREPurposeReturns the value of the Raspberry Pi senseHAT air pressuresensor.
Syntaxvalue=SENSEPRESSURE
Description
The Raspberry Pi senseHAT has a number of built in sensors. Airpressure can be accessed with this function.
ExampleCLSLOOPPRINT “Pressure”; sensePressureREPEATEND
AssociatedsenseHumidity, senseHeight, senseTemperature
SENSERECTPurposeLights a rectangle on the Raspberry Pi senseHAT LED matrix.
SyntaxSENSERECT(xpos, ypos, width, height, fill)
Description
Sets the RGB values, defined by senseRGBcolour, to a rectangle ofLEDs on the Raspberry Pi senseHAT LED matrix. The rectangle isdisplayed from xpos, ypos with a width and height as specified.Fill can be either 0 for an outline or 1 for filled in.
ExampleCLSSenseRGBcolour(255,0,0)senseRect(0,0,7,7,1)SenseRGBcolour(0,255,0)senseRect(0,0,7,7,0)END
AssociatedsenseCls, sensePlot, senseLine, senseScroll, senseVflip,senseRGBcolour, senseGetRGB
105
main indexFunctions, Constants & Procedures
SENSERGBCOLOURPurposeSet the Red, Green and Blue values used by a Raspberry PisenseHAT LED.
SyntaxSENSERGBCOLOUR(red, green, blue)
Description
Sets the Red, Green and Blue values to be used by the senseHATFUZE BASIC drawing commands.
ExampleCLSsenseRGBcolour (255, 0, 0)sensePlot (0, 0)senseRGBcolour (0, 255, 0)sensePlot (3, 3)senseRGBcolour (0, 0, 255)sensePlot (7, 7)END
AssociatedsenseCls, sensePlot, senseRect, senseScroll, senseHFlip,senseVflip, senseLine, senseGetRGB
SENSESCROLLPurposeScrolls the Raspberry Pi senseHAT LED matrix.
SyntaxSENSESCROLL(direction, direction)
DescriptionShifts the Raspberry Pi senseHAT LED matrix in the specifieddirection by the number of pixels indicated.
ExamplesenseCLSsensePlot (2, 2)sensePlot (2, 3)LOOPSenseScroll (0, 2) // two upWAIT(0.1)SenseScroll (2, 0) // two rightWAIT(0.1)SenseScroll (0, -2) // two downWAIT(0.1)SenseScroll (-2, 0) // two leftWAIT(0.1)REPEATEND
AssociatedsenseCls, sensePlot, senseRect, senseRGBcolour, senseHFlip,senseVflip, senseLine, senseGetRGB
106
main indexFunctions, Constants & Procedures
SENSETEMPERATUREPurposeReturns the value of the Raspberry Pi senseHAT heat sensor.
Syntaxvalue=SENSETEMPERATURE
Description
The Raspberry Pi senseHAT has a number of built in sensors.Temperature, in degrees, can be accessed with this function.
ExampleCLSLOOPPRINT “Temperature”; senseTemperatureREPEATEND
AssociatedsenseHumidity, senseHeight, sensePressure
SENSEVFLIPPurposeVertically flips the Raspberry Pi senseHAT LED matrix.
SyntaxSENSEHFLIP
Description
Reverses (flips) the LED matrix display vertically.
ExampleCLSSenseRGBcolour(255,0,0)senseLine(0,0,0,7)SenseRGBcolour(0,255,0)senseLine(0,7,7,7)LOOPsenseHflipWAIT(1)SenseVflipWAIT(1)END
AssociatedsenseCls, sensePlot, senseRect, senseScroll, senseVflip,senseRGBcolour, senseGetRGB, senseLine
107
main indexFunctions, Constants & Procedures
SETCHANVOLPurposeSet the volume of a sound sample.
SyntaxSETCHANVOL(channel,volume)
DescriptionSets the sound sample playback volume on the specifiedchannel where volume is a percentage of the maximum(0-100)
Examplechannel=0chomp=LOADSAMPLE("pacman_chomp.wav")FOR volume=10 TO 100 STEP 10 LOOP
SETCHANVOL(channel,volume)PLAYSAMPLE(chomp,0,0)WAIT(1)
REPEATEND
AssociatedLOADSAMPLE, PAUSECHAN, PLAYSAMPLE, RESUMECHAN,STOPCHAN
SETMODEPurposeSet display width and height
SyntaxSETMODE( width, height )
DescriptionSets the display width and height to the specified. It isgenerally sensible to use standard screen display sizes
ExampleSETMODE( 1280, 720 )PRINT "Hello World"WAIT( 2 )SETMODE( 640, 480 )PRINT "Hello Another World"END
AssociatedGHEIGHT, GWIDTH
108
main indexFunctions, Constants & Procedures
SETMOUSEPurposeMove the mouse pointer to the specified point.
SyntaxSETMOUSE(xpos,ypos)DescriptionMoves the mouse pointer to the screen coordinate (xpos,ypos)
ExampleCLSMOUSEONCOLOUR=WHITERECT(100,100,150,50,TRUE)INK=BLACKPAPER=WHITEPRINTAT(7,38); "Click Me"UPDATEClicked=FALSELOOP
GETMOUSE(X,Y,Z)IF Z <> 0 THEN
IF (X > 100 AND X < 250) THENIF (Y > 100 AND Y < 150) THEN
Clicked=TRUEENDIF
ENDIFENDIF
REPEAT UNTIL ClickedSETMOUSE(GWIDTH/2,GHEIGHT/2)
AssociatedGETMOUSE, MOUSEOFF, MOUSEON, MOUSEX, MOUSEY
SETMUSICVOLPurposeSets the music playback volume.
SyntaxSETMUSICVOL(level)
DescriptionSets the music playback volume where level is apercentage of the maximum (0-100)
Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)
AssociatedLOADMUSIC, PAUSEMUSIC, RESUMEMUSIC, STOPMUSIC
109
main indexFunctions, Constants & Procedures
SETSPRITEALPHAPurposeSets the transparency of a sprite
SyntaxSETSPRITEALPHA( sprite, alpha )
DescriptionSets how transparent a sprite is. An alpha of 0 means it'sinvisible and 255 means it's completely opaque, or solid.
Examplepic = NEWSPRITE( 1 )LOADSPRITE( "/usr/share/fuze/logo.bmp",pic, 0 )FOR alpha = 0 TO 255 LOOPSETSPRITEALPHA( pic, alpha )PLOTSPRITE( pic, GWIDTH / 2, GHEIGHT / 2, 0)UPDATEREPEATEND
AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITEANGLE, SETSPRITEFLIP,SETSPRITEORIGIN, GETSPRITEX, GETSPRITEY
SETSPRITEANGLEPurposeRotate a sprite to the given angle
SyntaxSETSPRITEANGLE( sprite, angle )
DescriptionUse to rotate the specified sprite to the given angle indegrees. 0 is default.
Examplepic = NEWSPRITE( 1 )LOADSPRITE( "/usr/share/fuze/logo.bmp",pic, 0 )FOR angle = 0 TO 360 LOOPSETSPRITEANGLE( pic, angle )PLOTSPRITE( pic, GWIDTH / 2, GHEIGHT / 2, 0)UPDATEREPEATEND
AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITESIZE, SETSPRITEFLIP, SETSPRITEORIGIN,GETSPRITEX, GETSPRITEY
110
main indexFunctions, Constants & Procedures
SETSPRITEFLIPPurposeMirror a sprite in the specified direction
SyntaxSETSPRITEFLIP( sprite, flip )
DescriptionGraphically mirrors (flips) the specified sprite.
0 Reset to default1 mirrored vertically2 mirrored horizontally3 mirrored vertically & horizontally
Examplepic = NEWSPRITE( 1 )LOADSPRITE("/usr/share/fuze/logo.bmp",pic, 0)PLOTSPRITE(pic, gWidth / 2, gHeight / 2, 0)FOR a=3 TO 0 step -1 LOOPSETSPRITEFLIP( pic, a )UPDATEWAIT( 1 )REPEAT
AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITEANGLE, SETSPRITESIZE,SETSPRITEORIGIN, GETSPRITEX, GETSPRITEY
SETSPRITEORIGINPurposeSets the anchor point of a sprite
SyntaxSETSPRITEorigin( sprite, xpos, ypos )
DescriptionUse to set the origin of a specified sprite. When plotting a spriteits default origin is bottom left. You can change this to any pointon the sprite. This example sets it to the middle.
Examplepic = NEWSPRITE( 1 )LOADSPRITE( "logo.png", pic, 0 )LOOPSETSPRITEORIGIN( pic, 0, 0 )Plotsprite( pic, 0, 0, 0)UpdateWait(1)MiddleX=GETSPRITEW(pic)/2MiddleY=GETSPRITEH(pic)/2SETSPRITEORIGIN( pic, MiddleX, MiddleY )PLOTSPRITE( pic, 0, 0, 0)UPDATEREPEAT
AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE, PLOTSPRITE,SETSPRITEANGLE, SETSPRITEFLIP, SETSPRITESIZE, GETSPRITEX,GETSPRITEY
111
main indexFunctions, Constants & Procedures
SETSPRITESIZEPurposeChange the size of a sprite
SyntaxSETSPRITESIZE( sprite, size )
DescriptionSets the sprite to the specified size in percent. 100 is thedefault, therefore 50 is half the size and 300 is three timesas big as the original.
Examplepic = NEWSPRITE( 1 )LOADSPRITE("/usr/share/fuze/logo.bmp",pic, 0)FOR angle = 50 TO 200 LOOPSETSPRITESIZE( pic, size )PLOTSPRITE( pic, GWIDTH / 2, GHEIGHT / 2, 0)UPDATEREPEATEND
AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE,PLOTSPRITE, SETSPRITEANGLE, SETSPRITEFLIP,SETSPRITEORIGIN, GETSPRITEX, GETSPRITEY
SETSPRITETRANSPurposeSet a transparency colour for a given sprite and its sub-sprites.
SyntaxSETSPRITETRANS(spriteId, Red, Green, Blue)
DescriptionIf you specify a transparency colour for a sprite then anypixels in the sprite that are this colour will be transparenti.e. They will show as the background colour. This allows asprite to pass over a background image without blocking itout. You need to load the sprite files first before settingthe transparency colour.
Example (overleaf)
112
main indexFunctions, Constants & Procedures
SETSPRITETRANS Example
CLSRGBCOLOUR(247, 247, 247)RECT(50, 50, 101, 101, TRUE)COLOUR = YELLOWCIRCLE(100, 100, 50, TRUE)SAVEREGION("s3.bmp", 50, 50, 101, 101)CLS2COLOUR = REDMidY = GHEIGHT / 2FOR X = 0 TO GWIDTH STEP 100 LOOP
RECT(X, MidY - 50, 50, 200, TRUE)REPEATCOLOUR = Blacks1 = NEWSPRITE(1)LOADSPRITE("s3.bmp", s1, 0)SETSPRITETRANS(s1, 247, 247, 247)FOR X = 0 TO gWidth STEP 10 LOOP
PLOTSPRITE(s1, X, GHEIGHT / 2, 0)UPDATEWAIT (0.0005)
REPEATEND
AssociatedGETSPRITEH, GETSPRITEW, LOADSPRITE, NEWSPRITE,PLOTSPRITE, RGBCOLOUR
SGETPurposeRead a byte from a serial port.
Syntaxbyte=SGET(handle)
DescriptionFetch a single byte of data from an open serial port and returnthe data as a number. This function will pause programexecution for up to 5 seconds if no data is available. If there isstill not data after 5 seconds, the function will return -1.
ExampleREM Read a byte from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)byte=SGET(arduino)PRINT byteSCLOSE(arduino)END
AssociatedSCLOSE, SGET$, SOPEN, SPUT, SPUT$, SREADY
113
main indexFunctions, Constants & Procedures
SGET$PurposeRead a character from a serial port.
Syntaxcharacter=SGET$(handle)
DescriptionFetch a single byte of data from an open serial port andreturn the data as a single character string. This functionwill pause program execution for up to 5 seconds if nodata is available. If there is still not data after 5 seconds,the function will return an empty string.
ExampleREM Read a character from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)char$=SGET$(arduino)PRINT char$SCLOSE(arduino)END
AssociatedSCLOSE, SGET, SOPEN, SPUT, SPUT$, SREADY
SGNPurposeReturns the sign of the specified number.
Syntaxsign=SGN(number)
DescriptionReturns -1 if the number is negative, 1 otherwise. (Zero isconsidered positive)
ExampleREM Prints 1PRINT SGN(100)PRINT SGN(0)REM Print -1PRINT SGN(-5)END
AssociatedABS
114
main indexFunctions, Constants & Procedures
SHOWKEYSPurposeList the function key definitions
SyntaxSHOWKEYS
DescriptionIt is possible to set the 12 function keys at the top of thekeyboard to user defined values. This command will showwhat the current definitions are. By default function keyF2 is defined to enter the EDIT command and F3 the RUNcommand but it is possible to overwrite these.
ExampleREM Set key F5 to clear screenkeyF5$ = "CLS\n"SHOWKEYS
SINPurposeReturns the sine of the given angle.
Syntaxsine=SIN(angle)
DescriptionReturns the sine of the argument angle in radians. This isthe ratio of the side of a right angled triangle, that isopposite to the angle, to the hypotenuse (the longestside).
ExampleREM Draw an ellipse in the screen centreCLSDEGFOR Angle=0 TO 360 LOOP
Xpos=100*COS(Angle)+GWIDTH/2Ypos=50*SIN(Angle)+GHEIGHT/2PLOT(Xpos,Ypos)
REPEATEND
AssociatedASIN, ATAN, COS
115
main indexFunctions, Constants & Procedures
SOFTPWMWRITEPurposeSynthesize Pulse Wave Modulation to the specified GPIOpin.
SyntaxSOFTPWMWRITE(pinNo,value)
DescriptionThis enables you to simulate an analog output. For exampleinstead of an LED being just on or off you can make it appearbrighter or dimmer. The pinNo parameter is the number of theGPIO output pin. This must first be set to pinSoftPwm. The valueparameter is a percentage (0-100).
ExampleREM Connect an LED to GPIO pin 0PINMODE (0, PINSOFTPWM)FOR I=0 TO 100 LOOP
SOFTPWMWRITE (0,I)WAIT(0.1)
REPEATFOR I=100 to 0 STEP -1 LOOP
SOFTPWMWRITE (0,I)WAIT(0.1)
REPEATEND
AssociatedPINMODE
SOPENPurposeOpens a serial device and makes it available for use.
Syntaxhandle=SOPEN($device,speed)
DescriptionThis opens a serial device and makes it available for our use. Ittakes the name of the serial port and the speed as an argumentand returns a number (the handle) of the device. We can use thishandle to reference the device and allow us to open severaldevices at once. The following baud rates are recognised: 50, 75,110, 134, 150,200, 300, 600, 1200, 1800, 2400, 19200, 3840057600, 115200 and 230400, but do check your local PC anddevices capabilities. The device is always opened with the dataformat set to 8 data bits, 1 stop bit and no parity. Allhandshaking is turned off.
ExampleREM Read a byte from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)byte=SGET(arduino)SCLOSE(arduino)END
AssociatedSCLOSE, SGET, SGET$, SPUT, SPUT$, SREADY
116
main indexFunctions, Constants & Procedures
SOUNDPurposePlay a synthesised sound with the specified parameters(emulates BBC BASIC SOUND command).
Syntaxsound(channel,amplitude,pitch,duration)
DescriptionThe channel is 0 to 3 with 0 being for white noise (static). Theamplitude goes from 0 to -15 where 0 is silent and -15 is fullvolume (-7 being half volume and so on). The duration is in20ths of a second, so 20 represents one second, 10 half a secondand so on. The pitch values are taken from a table which can befound at the end of the manual but, middle C has a value of 53and each note is 4 away from the next. Note that when usedwith a sound envelope amplitude is replaced by the envelopenumber.
ExampleChannel=1Volume=-10FOR Note=1 TO 5 LOOP
READ Frequency,DurationSOUND(Channel,Volume,Frequency,Duration)
REPEATENDDATA 89, 20, 97, 20, 81, 20, 33, 20, 61, 40
AssociatedENVELOPE, TONE
SPACE$PurposeReturns a blank string of the specified length.
Syntaxblankstring=SPACE$(number)
DescriptionReturns a string of blank spaces number characters long.
ExampleBlank$ = SPACE$(100)FOR I=1 TO 20 LOOP
PRINT Blank$REPEATEND
117
main indexFunctions, Constants & Procedures
SPRITECOLLIDEPurposeDetect a sprite collision (fast bounding box)
Syntaxcollision=SPRITECOLLIDE(target)
DescriptionReturns the sprite index of the first sprite that the spriteindex target has collided with, or -1 if there is no collision.It only checks the current sprite location and this is onlyupdated after a screen update LOOP so it is possible to callPLOTSPRITE() and have a sprite overlap but it not bedetected until after the update has happened on screen.
ExampleCLSRGBCOLOUR(254,254,254)RECT(50,50,101,101,TRUE)COLOUR=YELLOWCIRCLE(100,100,50,TRUE)SAVEREGION("s1.bmp",50,50,101,101)COLOUR=REDCIRCLE(100,100,50,TRUE)SAVEREGION("s2.bmp",50,50,101,101)CLS2s1=NEWSPRITE(1)s2=NEWSPRITE(1)LOADSPRITE("s1.bmp",s1,0)LOADSPRITE("s2.bmp",s2,0)FOR X=0 TO GWIDTH STEP 1 LOOP
PLOTSPRITE(s1,X,200,0)PLOTSPRITE(s2,GWIDTH-X-100,200,0)IF SPRITECOLLIDE (s2) <> -1 THEN BREAKUPDATEWAIT(0.0005)
REPEATEND
AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, LOADSPRITE,NEWSPRITE, PLOTSPRITE, SPRITECOLLIDEPP
118
main indexFunctions, Constants & Procedures
SPRITECOLLIDEPPPurposeDetect a sprite collision (pixel perfect)
Syntaxcollision=SPRITECOLLIDEPP(target,accuracy)
DescriptionThis is a slower but more accurate version of SpriteCollide.It first does do a simple bounding box test then checksrow at a time. The accuracy parameter is how many pixelsto skip both horizontally and vertically. This is from 1 to16, where 1 is "perfect" and greater than 1 is lessaccurate, but faster. This will affect the amount of visibleoverlap you get before a collision is detected.
ExampleCLSRECT(50,50,101,101,TRUE)COLOUR=YELLOWCIRCLE(100,100,50,TRUE)SAVEREGION("s1.bmp",50,50,101,101)COLOUR=REDCIRCLE(100,100,50,TRUE)SAVEREGION("s2.bmp",50,50,101,101)CLS2s1=NEWSPRITE(1)s2=NEWSPRITE(1)LOADSPRITE("s1.bmp",s1,0)LOADSPRITE("s2.bmp",s2,0)FOR X=0 TO GWIDTH STEP 1 LOOP
PLOTSPRITE(s1,X,200,0)PLOTSPRITE(s2,GWIDTH-X-100,200,0)IF SPRITECOLLIDEPP(s2,1) <> -1 THEN BREAKUPDATE
REPEATEND
AssociatedGETSPRITEH, GETSPRITEW, HIDESPRITE, LOADSPRITE,NEWSPRITE, PLOTSPRITE, SPRITECOLLIDE
119
main indexFunctions, Constants & Procedures
SPRITEOUTPurposeFind out if a sprite is off screen
Syntaxresult = SPRITEOUT( sprite )
DescriptionIf the sprite is off screen then result is true otherwise it isfalse.
Examplepic = NEWSPRITE( 1 )LOADSPRITE("/usr/share/fuze/logo.bmp",pic, 0)PLOTSPRITE( pic, GWIDTH / 2, GHEIGHT / 2, 0)WHILE NOT SPRITEOUT( pic ) LOOPADVANCESPRITE( pic, 2 )UPDATEREPEATPRINT "GONE!"END
AssociatedHIDESPRITE, PLOTSPRITE
SPUTPurposeSend a byte to an open serial port.
SyntaxSPUT(arduino,byte)
DescriptionSend a single byte of data to an open serial port.
ExampleREM Write a byte to a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)SPUT(arduino,52)SPUT(arduino,50)SCLOSE(arduino)END
AssociatedSCLOSE, SGET, SGET$, SOPEN, SPUT$, SREADY
120
main indexFunctions, Constants & Procedures
SPUT$PurposeSend a character string to an open serial port.
SyntaxSPUT$(arduino,string)
DescriptionSend a string of characters of data to an open serial port.
ExampleREM Write a byte to a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)SPUT$(arduino,"Hello")SCLOSE(arduino)END
AssociatedSCLOSE, SGET, SGET$, SOPEN, SPUT, SREADY
SQRTPurposeReturn the square root of the specified number.
Syntaxsquareroot=SQRT(number)
DescriptionReturns the square root of the argument number. This isthe opposite of multiplying a number by itself i.e. X =SQRT(X * X)
Examplefoursquared=4*4PRINT SQRT(foursquared)END
121
main indexFunctions, Constants & Procedures
SREADYPurposeGet the number of characters available to be read on anopen serial port.
Syntaxcount=SREADY(handle)
DescriptionReturns the number of characters available to be read from anopen serial port. This can be used to poll the device to avoidstalling your program when there is no data available to be read.
ExampleREM Read a character from a serial portarduino=SOPEN("/dev/ttyUSB0", 115200)IF SREADY(arduino) THEN
char$=SGET$(arduino)PRINT char$
ENDIFSCLOSE(arduino)END
AssociatedSCLOSE, SGET, SGET$, SOPEN, SPUT, SPUT$
STOPPurposeStop a running program.
SyntaxSTOP
DescriptionProgram execution is stopped with a message indicatingthe current line number.
ExampleINPUT "Enter the Password: ", pass$IF pass$<>"wibble" THEN
PRINT "Password Incorrect"STOP
ENDIFPRINT "Password Correct"END
AssociatedCONT
122
main indexFunctions, Constants & Procedures
STOPCHANPurposeStop the playing of a sound sample.
SyntaxSTOPCHAN(handle)
DescriptionThis function stops the playing of the sound sampleassociated with the handle returned by LOADSAMPLE thathas been started using PLAYSAMPLE. It cannot be resumedonce stopped.
Examplechannel=0volume=70SETCHANVOL(channel,volume)intro=LOADSAMPLE("pacman_intro.wav")PLAYSAMPLE(intro,channel,0)WAIT(3)STOPCHAN(intro)END
AssociatedLOADSAMPLE, PAUSECHAN, PLAYSAMPLE, RESUMECHAN,SETCHANVOL
STOPMUSICPurposeStop music playing completely.
SyntaxSTOPMUSIC
DescriptionStops a playing music track which cannot then beresumed.
Examplehandle=LOADMUSIC("takeoff.wav")SETMUSICVOL(70)PLAYMUSIC(handle,1)STOPMUSIC
AssociatedLOADMUSIC, PAUSEMUSIC, RESUMEMUSIC,SETMUSICVOL
123
main indexFunctions, Constants & Procedures
STR$PurposeReturns a string version of the supplied number.
Syntaxstring$=STR$(number)
DescriptionReturns a string in the decimal (base 10) representation ofnumber. This is useful if you want to append a number toa string. This is the opposite of the VAL function.
ExamplePRINT "The Answer is "+STR$(42)END
AssociatedVAL
SWAPPurposeSwap the value of two variables.
SyntaxSWAP(value1,value2)
DescriptionThis swaps the value of the 2 variables round. Botharguments must be the same type - i.e. Both numeric orboth string.
Examplelowest=99highest=0IF lowest>highest THEN
SWAP(highest,lowest)ENDIFPRINT "Lowest "; lowestPRINT "Highest ";highestEND
124
main indexFunctions, Constants & Procedures
SWITCHPurposeTest a value against many different values and executedifferent code.
SyntaxSWITCH (variable)
{ CASE value {, value }commands
ENDCASE }[ DEFAULT
commandsENDCASE ]
ENDSWITCH
DescriptionSimplify the writing of multiple IF. . . THEN. . . ELSE statements.
Rules:
• Every SWITCH must have a matching ENDSWITCH.• Every CASE or DEFAULT statement must have a matching
ENDCASE.• Statements after a CASE statement must not run-into another
CASE.• The constants after the CASE statement (and the expression in
the SWITCH statement) can be either numbers or strings, butyou can’t mix both.
ExampleINPUT aSWITCH(a)
CASE 1,2PRINT "You entered 1 or 2"
ENDCASECASE 7
PRINT "You entered 7"ENDCASEDEFAULT
PRINT "You entered something else"ENDCASE
ENDSWITCHEND
AssociatedENDCASE, CASE, ENDSWITCH
125
main indexFunctions, Constants & Procedures
TANPurposeReturn the tangent of the given angle.
Syntaxtangent=TAN(angle)
DescriptionReturns the tangent of the angle in the current angle units. In aright-angled triangle the tangent of an angle is the ratio of thelength of the opposite side to the length of the adjacent side.This is a measure of the steepness of an angle.
ExampleDEGPRINT "Tangent of 45 degrees: "; TAN(45)PRINT "ArcTangent of 1: "; ATAN(1)END
AssociatedACOS, ASIN, ATAN, COS
TANGLEPurposeRead or set the current angle of the turtle.
Syntaxangle=TANGLETANGLE=angle
DescriptionThis can be read or assigned to and represents the current angleof the turtle when using turtle graphics mode (in the currentangle units)
ExampleCLSORIGIN(GWIDTH/2,GHEIGHT/2)CLOCKFOR I = 1 TO 60 LOOP
TANGLE = IMOVETO(0,0)PENDOWNMOVE(100)
REPEATEND
AssociatedLEFT, MOVE, MOVETO, PENDOWN, PENUP, RIGHT
126
main indexFunctions, Constants & Procedures
THEIGHTPurposeThe height in characters of the display.
Syntaxheight=THEIGHT
DescriptionThe height in characters of the display.
ExampleCLStext$="This text is centred in the screen"HVTAB((TWIDTH-LEN(text$))/2,THEIGHT/2)PRINT text$END
AssociatedTWIDTH
TIMEPurposeFind out how long the program has been running in 1000s of asecond.
Syntaxtime=TIME
DescriptionThis returns a number which represents the time that yourprogram has been running in milliseconds.
ExampleREM Simple reaction timerWAIT(2)REM Make sure no key pressedWHILE INKEY<>-1 LOOPREPEATstime=TIMEPRINT "Go!"WHILE INKEY=-1 LOOPREPEATetime = TIMEPRINT "Your reaction time is ";PRINT etime-stime; " milliseconds"END
127
main indexFunctions, Constants & Procedures
TONEPurposePlay a tone with the specified parameters.
SyntaxTONE(channel,volume,frequency,duration)
DescriptionThis plays a simple tone of the given frequency (1 to 5000Hz),volume (%) and duration (0.01 to 20 seconds) on the givenchannel.You can play multiple tones by playing them one after the otherand up to three tones can be played simultaneously on differentchannels.Channel 0 is white noise and the frequency has no bearing onthe sound produced.
ExampleChannel=1Volume=70FOR Note=1 TO 5 LOOP
READ Frequency,DurationTONE(Channel,Volume,Frequency,Duration)
REPEATENDDATA 440, 1, 493, 1, 392, 1, 196, 1, 294 ,2
AssociatedSOUND
TIME$PurposeReturns a string with the current time.
Syntaxnow$=TIME$
DescriptionThis returns a string with the current time in the followingformat: HH:MM:SS. For example: 18:05:45.
ExamplePRINT "The time now is ";PRINT TIME$END
AssociatedDATE$
128
main indexFunctions, Constants & Procedures
TRIANGLEPurposeDraw a triangle on the screen.
SyntaxTRIANGLE (xpos1, ypos1, xpos2, ypos2,xpos3, ypos3, fill)
DescriptionDraws a triangle with its corners at the three given points. Thefinal parameter, fill is either TRUE or FALSE, and specifies filled(TRUE) or outline (FALSE).
ExampleLOOP
COLOUR=RND(16)x1=RND(GWIDTH)x2=RND(GWIDTH)x3=RND(GWIDTH)y1=RND(GHEIGHT)y2=RND(GHEIGHT)y3=RND(GHEIGHT)f=RND(2)TRIANGLE (x1,y1,x2,y2,x3,y3,f)UPDATEIF INKEY<>-1 THEN BREAK
REPEATEND
AssociatedCIRCLE, ELLIPSE, RECT
TRUEPurposeRepresents the logical "true" value.
SyntaxTRUE
DescriptionRepresents a Boolean value that succeeds a conditional test. It isequivalent to a numeric value of 1 (in fact anything other than 0evaluates to TRUE)
Examplecondition=TRUEIF condition=TRUE THEN
PRINT "Condition is TRUE"ENDIFPRINT conditionEND
AssociatedFALSE
129
main indexFunctions, Constants & Procedures
TWIDTHPurposeThe width in characters of the display.
Syntaxwidth=TWIDTH
DescriptionThe width in characters of the display.
Exampletext$="This text is centred horizontally"HTAB=(TWIDTH-LEN(text$))/2PRINT text$END
AssociatedTHEIGHT
UPDATEMODEPurposeSet the video update mode.
SyntaxUPDATEMODE=mode
Description (overleaf)
UPDATEMODE DescriptionThe updateMode determines when the screen is redrawn.Redrawing the screen takes a little time and will slow down aprogram if you do it too often. The value of the mode parametercan be 0, 1, or 2 as follows:0- automatic updates do not happen. Nothing will be drawn onthe screen until the UPDATE command is issued.1-This is the default mode whereby an UPDATE happensautomatically when you output a new line, or the screen scrolls.2-The screen is updated after every PRINT instruction whether ittakes a new line or not.
ExampleCLSINPUT "Update Mode? ",modeIF mode>=0 AND mode<=2 THEN
PRINT "Press space to exit"WAIT(1)UPDATEMODE=modeLOOP
PRINT "Hello World ";REPEAT UNTIL INKEY=32UPDATE
ELSEPRINT "Invalid Update Mode"
ENDIFWAIT(1)END
AssociatedUPDATE
130
main indexFunctions, Constants & Procedures
UNTIL REPEATPurposeLoop until the specified condition is met.
SyntaxUNTIL condition LOOP
{statements}REPEAT
DescriptionExecute the statements zero or more times until thecondition is TRUE (Not 0).Because the test is done at the start of the loop thestatements may not be executed at all
ExampleREM Print 1 to 10count=1UNTIL count>10 LOOP
PRINT countcount=count + 1
REPEATEND
AssociatedBREAK, CONTINUE, LOOP, LOOP REPEAT, FOR REPEAT,REPEAT UNTIL, WHILE REPEAT
UPDATEPurposeUpdate screen graphics.
SyntaxUPDATE
DescriptionGraphics are drawn to a temporary screen buffer ratherthan the visible screen. The UPDATE command copies theworking area to the main display. An update is alsoperformed if your program stops for input, or when youPRINT a new line.ExampleREM Moire patternsLOOP
CLSCOLOUR=RND(15)+1x=RND(GWIDTH)y=RND(GHEIGHT)FOR w=0 TO GWIDTH-1 STEP 3 LOOP
LINE(x,y,w,0)LINE(x,y,w,GHEIGHT-1)
REPEATFOR h=0 TO GHEIGHT-1 STEP 3 LOOP
LINE(x,y,0,h)LINE(x,y,GWIDTH-1,h)
REPEATUPDATE
REPEATEND
AssociatedUPDATEMODE
131
main indexFunctions, Constants & Procedures
VALPurposeReturns the number represented by a character string.
Syntaxnumber=VAL(string$)
DescriptionReturns the number represented by string$. This is the oppositeof the STR$ function.
Examplenow$ =TIME$hh=VAL(LEFT$(now$, 2))mm=VAL(MID$(now$, 3, 2))ss=VAL(RIGHT$(now$, 2))elapsed=hh*3600+mm*60+ssPRINT "Seconds since midnight: "; elapsedEND
AssociatedSTR$
VLINEPurposeDraws a vertical line.
SyntaxVLINE (ypos1,ypos2,xpos)
DescriptionDraws a vertical line on column xpos, from row ypos1 to rowypos2.
ExampleCLSCOLOUR=redFOR xpos=0 TO GWIDTH STEP 100 LOOP
VLINE(0, GHEIGHT, xpos)REPEATUPDATEEND
AssociatedHLINE, LINE, LINETO
132
main index
VTABPurposeSet/Read the current text cursor vertical position.
SyntaxVTAB=valuevalue=VTAB
DescriptionSet/Read the current text cursor vertical position.
ExampleCLSFOR ypos = 0 TO THEIGHT LOOP
VTAB=yposPRINT VTAB
REPEATVTAB=0END
AssociatedHTAB, HVTAB
WAITPurposeWaits for the specified time to elapse.
SyntaxWAIT(time)
DescriptionThis waits (does nothing) for time seconds. This may be aractional number, but the accuracy will depend on the computeryou are running it on, however delays down to 1/100th of asecond should be achievable.
ExampleREM COUNT 10 SecondsCLSSeconds = 0FOR I=1 TO 10 LOOP
WAIT(1)Seconds=Seconds + 1HVTAB(10,10)PRINT Seconds
REPEATPRINT "Elapsed "; TIME/1000END
Functions, Constants & Procedures
133
main index
WHILE REPEATPurposeLoop while the specified condition is met.
SyntaxWHILE condition LOOP
{statements}REPEAT
DescriptionExecute the statements zero or more times while the condition isTRUE (Not 0). Because the test is done at the start of the loopthe statements may not be executed at all.
Examplehandle=OPEN("whiletest.txt")FOR r=0 TO 10 LOOP
PRINT# handle,"Record ";rREPEATCLOSE(handle)handle = OPEN("whiletest.txt")WHILE NOT EOF(handle) LOOP
INPUT# handle, record$PRINT record$
REPEATCLOSE (handle)END
AssociatedBREAK, CONTINUE, LOOP, LOOP REPEAT, FOR REPEAT,REPEAT UNTIL, UNTIL REPEAT
listGamepadsImmediate mode only. Displays a list of connected devices.
numButtons( gamepad )Returns the number of buttons on a specified device
numAxes( gamepad )Returns the number of analog axis on a specified device
numHats( gamepad )Returns the number of HATS on a specified device
numGamepadsReturns the number of devices connected
getAxis( gamepad, axis )Returns the value of a given axis on a specified device
getButton( gamepad, button )Returns the value of a given button on a specified device
getHat( gamepad, hat )Returns the value of a given HAT on a specified device
SetupGamepad( gamepad )Configure a specified device
Joystick and Gamepad commandsFunctions, Constants & Procedures
134
main index
scanBackspacescanTabscanClearscanReturnscanPausescanEscapescanSpacescanExclaimscanQuoteDblscanHashscanDollarscanAmpersandscanQuotescanLeftParenscanRightParenscanAsteriskscanPlusscanCommascanMinusscanPeriodscanSlashscan0
scanAscanBscanCscanDscanEscanFscanGscanHscanIscanJscanKscanLscanMscanNscanOscanPscanQscanRscanSscanTscanUscanV
scanDownscanRightscanLeftscanInsertscanHomescanEndscanPageupscanPagedownscanF1scanF2scanF3scanF4scanF5scanF6scanF7ScanF8scanF9scanF10scanF11scanF12scanF13scanF14ScanF15scanNumLock
scanCapsLockscanScrolLockscanRShiftscanLShiftscanRCtrlscanLCtrlscanRAltscanLAltscanRMetascanLMetascanLSuperscanRSuperscanModescanComposescanHelpscanPrintscanSysReqscanBreakscanMenuscanPowerscanEuroscanUndo
scan1scan2scan3scan4scan5scan6scan7scan8scan9scanColonscanSemiColonScanLessScanEqualsscanGreaterscanQuestionscanAtscanLeftBracketscanBackSlashscanRightBracketscanCaretScanUnderscorescanBackQuote
scanVscanWscanXscanYScanZscanDeletescanKP0scanKP1scanKP2scanKP3scanKP4scanKP5scanKP6scanKP7scanKP8scanKP9scanKpPeriodscanKpDividescanKpMultiplyscanKpMinusscanKpPlusScanKpEnterScanKpEqualsscanUp
ScanKeyboard values
135
main index
Octave Number
Note 1 2 3 4 5 6 7B 0 49 97 145 193 241
A# 0 45 93 141 189 237A 41 89 137 185 233
G# 37 85 133 181 229G 33 81 129 177 225
F# 29 77 125 173 221F 25 73 121 169 217E 21 69 117 165 213
D# 17 65 113 161 209D 13 61 109 157 205 253
C# 9 57 105 153 201 249C 5 53 101 149 197 245
Notes & Octaves for Sound function
fuze.co.uk
FUZE BASICProgrammer’s reference guide£14.99 / $24.99 / €21.99
FUZE BASICProgrammer’s Reference Guide