Tauon Basic Help v0.60




Screen

global object and functions related to resolution

Properties:

width
: Number. Width in pixels.
height
: Number. Height in pixels.
mouseX
: Number. Horizontal position in screen coordinates of the Mouse cursor.
mouseY
: Number. Vertical position in screen coordinates of the Mouse cursor.
randX
: Number. Random horizontal position on screen.
randY
: Number. Random vertical position on screen.



Function
setScreenMode
or
Screen.setMode
(mode)

Parameters:

mode : Number or String. Predefined screen modes:
0 - 320x180
1 - 640x360
2 - 1280x720 (default)
3 - 1920x1080
"ZX" - 256x192
"WZX" - 336x192
"ZX81" - 64x48
"CGA" - 320x200
"EGA" - 640x350
"VGA" - 640x480

Examples:

setScreenMode("ZX81");
let c=createSpriteFromBin([
0b00011000,
0b01011010,
0b10111101,
0b11100111,
0b10100101,
0b11111111,
0b10111101,
0b01000010],8,8);
setSpritePos(c,32,24);


Function
setScreenSize
or
Screen.setSize
(width,height)

Set custom screen resolution.

Parameters:

width : Number. Width in pixels.
height : Number. Height in pixels.



Function
clearScreen
or
Screen.clear
(color="#000")

Clear the whole screen. All Sprites and Sprite groups would be detached (but not destroyed) from Screen. Clears Console and Canvas, resets their positions and styles.

Parameters:

color : String. Color value. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to "#000".



Function
setBgColor
or
Screen.setBgColor
(color="#000")

Set the background color. Resets Canvas position and style.

Parameters:

color : String. Color value. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to "#000".



Function
setBorderColor
or
Screen.setBorderColor
(color="#000")

Set border color. Border is visible in some resolutions, when aspect ratio of the virtual Screen doesn't correspond to the physical one.

Parameters:

color : String. Color value. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to "#000".

Examples:

setScreenMode("ZX81");
setBorderColor("red");


Function
isScreenChild
or
Screen.isChild
(node)

Return true if provided node is attached to Screen, false otherwise.

Parameters:

node : Object. Could be Sprite, SpriteGroup or HTMLElement object.

Returns:

Boolean.



Function
appendScreenChild
or
Screen.appendChild
(node)

This function attaches node to the Screen.

Parameters:

node : Object. Could be Sprite, SpriteGroup or HTMLElement object.



Function
removeScreenChild
or
Screen.removeChild
(node)

This function detaches node from the Screen.

Parameters:

node : Object. Could be Sprite, SpriteGroup or HTMLElement object.





Console

global object and functions related to text output



Function
cls
or
clearConsole
or
Console.clear
(...)

Clear consoLe Screen buffer. Fills it with the new content if one or more argument provided.

Parameters:

any number of parameters, separated by coma.



Function
print
or
Console.print
(...)

Add a text line with concatenated parameters to the Console screen buffer.

Parameters:

any number of parameters, separated by coma.

Examples:

print("2+2=",(2+2));

Function
scan
or
Console.scan
()

Get current Console buffer content.

Returns:

String.



Function
setConsoleFont
or
Console.setFont
(color="#FFF",fontSizePx=15,lineHeightPx=20,bold=false)

Set the font parameters to display Console buffer on the screen.

Parameters:

color : String. Color value. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to "#FFF".
fontSizePx : Optional parameter. If omitted equals to 15.
lineHeightPx : Optional parameter. If omitted equals to 20.
bold : Optional parameter. If omitted equals to false.



Function
showConsole
or
Console.show
(bool=true)

Show Console on the Screen.

Parameters:

bool : Boolean. Optional parameter. If omitted equals to true.



Function
hideConsole
or
Console.hide
()

Hide Console from the Screen.





Canvas

global object and functions related to 2D drawing

Properties:

width
: Number. Width in pixels.
height
: Number. Height in pixels.
strokeStyle
: color or style to draw stokes. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.strokeStyle would be used. If boolean false argument passed - no strokes would be drawn.
fillStyle
: color or style to fill current path. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.fillStyle would be used. If boolean false argument passed - the shape won't be filled.
lineWidth
: Number. Line width in pixels.



Function
clearCanvas
or
Canvas.clear
(color="#000",width=Screen.width,height=Screen.height)

Clear the Canvas with color provided. Resets Canvas position and styles.

Parameters:

color : String. Color value. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to "#000".
width : Number. Width in pixels. Optional parameter. If omitted equals to Screen.width.
height : Number. Height in pixels. Optional parameter. If omitted equals to Screen.height.



Function
line
or
Canvas.line
(x1,y1,x2,y2,strokeStyle=true)

Stroke line from (x1,y1) to (x2,y2) with color provided (or with Canvas.strokeStyle).

Parameters:

x1 : Number. Horizontal position in Canvas coordinates of the starting point.
y1 : Number. Vertical position in Canvas coordinates of the starting point.
x2 : Number. Horizontal position in Canvas coordinates of the destination point.
y2 : Number. Vertical position in Canvas coordinates of the destination point.
strokeStyle : color or style to draw stokes. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.strokeStyle would be used. If boolean false argument passed - no strokes would be drawn. Optional parameter. If omitted equals to true.



Function
circle
or
Canvas.circle
(x,y,radius,strokeStyle=true,fillStyle=false)

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
radius : Number. Defines the radius in pixels.
strokeStyle : color or style to draw stokes. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.strokeStyle would be used. If boolean false argument passed - no strokes would be drawn. Optional parameter. If omitted equals to true.
fillStyle : color or style to fill current path. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.fillStyle would be used. If boolean false argument passed - the shape won't be filled. Optional parameter. If omitted equals to false.



Function
fillCircle
or
Canvas.fillCircle
(x,y,radius,fillStyle=true)

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
radius : Number. Defines the radius in pixels.
fillStyle : color or style to fill current path. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.fillStyle would be used. If boolean false argument passed - the shape won't be filled. Optional parameter. If omitted equals to true.



Function
rect
or
Canvas.rect
(x,y,width,height,strokeStyle=true,fillStyle=false)

Stroke and/or fill rectangle at (x,y) position with (width,height) dimensions.

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
width : Number. Width in pixels.
height : Number. Height in pixels.
strokeStyle : color or style to draw stokes. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.strokeStyle would be used. If boolean false argument passed - no strokes would be drawn. Optional parameter. If omitted equals to true.
fillStyle : color or style to fill current path. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.fillStyle would be used. If boolean false argument passed - the shape won't be filled. Optional parameter. If omitted equals to false.



Function
fillRect
or
Canvas.fillRect
(x,y,width,height,fillStyle=true)

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
width : Number. Width in pixels.
height : Number. Height in pixels.
fillStyle : color or style to fill current path. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.fillStyle would be used. If boolean false argument passed - the shape won't be filled. Optional parameter. If omitted equals to true.



Function
ellipse
or
Canvas.ellipse
(x,y,radiusX,radiusY,rotation,strokeStyle=true,fillStyle=false)

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
radiusX : Number. Defines the horizontal radius in pixels.
radiusY : Number. Defines the vertical radius in pixels.
rotation : Number. Absolute rotation angle in Radians. Use degToRad() function to easily convert from degrees to radians.
strokeStyle : color or style to draw stokes. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.strokeStyle would be used. If boolean false argument passed - no strokes would be drawn. Optional parameter. If omitted equals to true.
fillStyle : color or style to fill current path. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.fillStyle would be used. If boolean false argument passed - the shape won't be filled. Optional parameter. If omitted equals to false.



Function
fillEllipse
or
Canvas.fillEllipse
(x,y,radiusX,radiusY,rotation,fillStyle=false)

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
radiusX : Number. Defines the horizontal radius in pixels.
radiusY : Number. Defines the vertical radius in pixels.
rotation : Number. Absolute rotation angle in Radians. Use degToRad() function to easily convert from degrees to radians.
fillStyle : color or style to fill current path. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.fillStyle would be used. If boolean false argument passed - the shape won't be filled. Optional parameter. If omitted equals to false.



Function
plot
or
putPixel
or
Canvas.putPixel
(x,y,colorOrRGB=Canvas.fillStyle)

Put a single pixel on Canvas

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
colorOrRGB : String or Array. Color value. In case if array is passed, it should contain 3 or 4 integers in range 0 to 255, representing color component values [Red, Ggreen, Blue, Alpha]. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to Canvas.fillStyle.

Examples:

plot(100,100,"red");
putPixel(101,100,[127,255,63]);
Canvas.putPixel(102,100,"#FF00FF");


Function
point
or
getPixel
or
Canvas.getPixel
(x,y,hexFormat=false)

Get color of a single pixel on Canvas. By default returns an array [Red,Green,Blue,Alpha]. If hexFormat parameter provided will return color in hex format (#FFFFFF).

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
hexFormat : Boolean. Pass boolean true to receive the result in hex format (like "#FFFFFF"). Optional parameter. If omitted equals to false.



Function
setStrokeStyle
or
Canvas.setStrokeStyle
(strokeStyle)

Set the Canvas.strokeStyle property. This style would be applied to all consecutive stroke operations.

Parameters:

strokeStyle : color or style to draw stokes. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.strokeStyle would be used. If boolean false argument passed - no strokes would be drawn.



Function
setFillStyle
or
Canvas.setFillStyle
(fillStyle)

Set the Canvas.fillStyle property. This style would be applied to all consecutive fill operations.

Parameters:

fillStyle : color or style to fill current path. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. If boolean true argument passed current Canvas.fillStyle would be used. If boolean false argument passed - the shape won't be filled.



Function
setLineWidth
or
Canvas.setLineWidth
(lineWidth=1)

Set Canvas.lineWidth property, changing the line width for all consecutive line drawing operations.

Parameters:

lineWidth : Number. Line width in pixels. Optional parameter. If omitted equals to 1.



Function
showCanvas
or
Canvas.show
(bool=true)

Show Canvas on the Screen.

Parameters:

bool : Boolean. Optional parameter. If omitted equals to true.



Function
hideCanvas
or
Canvas.hide
()

Hide Canvas from the Screen.



Function
setCanvasFont
or
Canvas.setFont
(color="#FFF",fontSizePx=15,bold=false)

Set the font parameters to display with the following Canvas.fillText or Canvas.strokeText functions. Alters Canvas.fillStyle and Canvas.strokeStyle.

Parameters:

color : String. Color value. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to "#FFF".
fontSizePx : Optional parameter. If omitted equals to 15.
bold : Optional parameter. If omitted equals to false.



Function
fillText
or
Canvas.fillText
(text, x, y, maxWidth=undefined)

Parameters:

text : String.
x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
maxWidth : Number. The maximum number of pixels wide the text should be when rendered. Optional parameter. If omitted equals to undefined.



Function
strokeText
or
Canvas.strokeText
(text, x, y, maxWidth=undefined)

Parameters:

text : String.
x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
maxWidth : Number. The maximum number of pixels wide the text should be when rendered. Optional parameter. If omitted equals to undefined.



Function
measureText
or
Canvas.measureText
(text)

Measure provided text, using current font metrics.

Parameters:

text : String.

Returns:

TextMetrics object that contains following properties: width, actualBoundingBoxLeft, actualBoundingBoxRight, fontBoundingBoxAscent, fontBoundingBoxDescent, actualBoundingBoxAscent, actualBoundingBoxDescent, emHeightAscent, emHeightDescent, hangingBaseline, alphabeticBaseline, ideographicBaseline.



Function
beginPath
or
Canvas.beginPath
()

Starts a new sub-path.



Function
closePath
or
Canvas.closePath
()

Closes the current sub-path, drawing straight line to the start of the path. Call Canvas.fill() or Canvas.stroke() later to fill or stroke the current path.



Function
moveTo
or
Canvas.moveTo
(x, y)

Move the starting point of a new sub-path to (x, y)

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.



Function
lineTo
or
Canvas.lineTo
(x, y)

Connect the current pen position and (x, y) with the straight line in current sub-path. Call Canvas.stroke() later to stroke the current path.

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.



Function
bezierCurveTo
or
Canvas.bezierCurveTo
(cpx, cpy, cp2x, cp2y, epx, epy)

Parameters:

cpx : Number. Horizontal position in Canvas coordinates of the control point.
cpy : Number. Vertical position in Canvas coordinates of the control point.
cp2x : Number. Horizontal position in Canvas coordinates of the second control point.
cp2y : Number. Vertical position in Canvas coordinates of the second control point.
epx : Number. Horizontal position in Canvas coordinates of the end point.
epy : Number. Vertical position in Canvas coordinates of the end point.



Function
quadraticCurveTo
or
Canvas.quadraticCurveTo
(cpx, cpy, epx, epy)

Parameters:

cpx : Number. Horizontal position in Canvas coordinates of the control point.
cpy : Number. Vertical position in Canvas coordinates of the control point.
epx : Number. Horizontal position in Canvas coordinates of the end point.
epy : Number. Vertical position in Canvas coordinates of the end point.



Function
arc
or
Canvas.arc
(x, y, radius, startAngle, endAngle, anticlockwise=undefined)

Parameters:

x : Number. Horizontal position in Canvas coordinates.
y : Number. Vertical position in Canvas coordinates.
radius : Number. Defines the radius in pixels.
startAngle : Number. Angle in Radians, counted clockwise. Use degToRad() function to easily convert from degrees to radians.
endAngle : Number. Angle in Radians, counted clockwise. Use degToRad() function to easily convert from degrees to radians.
anticlockwise : Boolean. Optional. If set to true function will draw the ellipse counter-clockwise. Optional parameter. If omitted equals to undefined.



Function
arcTo
or
Canvas.arcTo
(x1, y1, x2, y2, radius)

Parameters:

x1 : Number. Horizontal position in Canvas coordinates of the starting point.
y1 : Number. Vertical position in Canvas coordinates of the starting point.
x2 : Number. Horizontal position in Canvas coordinates of the destination point.
y2 : Number. Vertical position in Canvas coordinates of the destination point.
radius : Number. Defines the radius in pixels.



Function
fill
or
Canvas.fill
()

Fill the current sub-path with Canvas.fillStyle



Function
stroke
or
Canvas.stroke
()

Stroke the current sub-path with Canvas.strokeStyle



Function
putImageData
or
Canvas.putImageData
(imageData, dx, dy, sx=0, sy=0, width=imageData.width, height=imageData.height)

Parameters:

imageData : ImageData object. Contains following properties: data (one-dimensional array containing the pixel data in the RGBA order), height (height of the area), width (width of the area)
dx : Number. Horizontal position in Canvas coordinates to draw the image.
dy : Number. Vertical position in Canvas coordinates to draw the image.
sx : Number. Horizontal coordinate of the sub-rectangle of the source image. Optional parameter. If omitted equals to 0.
sy : Number. Vertical coordinate of the sub-rectangle of the source image. Optional parameter. If omitted equals to 0.
width : Number. Width in pixels. Optional parameter. If omitted equals to imageData.width.
height : Number. Height in pixels. Optional parameter. If omitted equals to imageData.height.

Examples:

let imgdata=getImageData(0,0,64,64);
putImageData(imgdata,Screen.randX,Screen.randY,0,0,32,32);


Function
getImageData
or
Canvas.getImageData
(sx, sy, width, height)

Parameters:

sx : Number. Horizontal coordinate of the sub-rectangle of the source image.
sy : Number. Vertical coordinate of the sub-rectangle of the source image.
width : Number. Width in pixels.
height : Number. Height in pixels.

Returns:

ImageData object. Contains following properties: data (one-dimensional array containing the pixel data in the RGBA order), height (height of the area), width (width of the area)

Examples:

let imgdata=getImageData(0,0,64,64);
putImageData(imgdata,Screen.randX,Screen.randY,0,0,32,32);


Function
drawImage
or
Canvas.drawImage
(image, dx, dy)

Draw Image or Sprite on Canvas. Make sure image is loaded and ready before drawing (use Sprite.isReady or Sprite.whenReady functions for Sprites).

Parameters:

image : Object. Could be Sprite or HTMLImageElement object.
dx : Number. Horizontal position in Canvas coordinates to draw the image.
dy : Number. Vertical position in Canvas coordinates to draw the image.



Function
drawImage
or
Canvas.drawImage
(image, dx, dy, dWidth, dHeight)

Draw Image or Sprite on Canvas. Make sure image is loaded and ready before drawing (use Sprite.isReady or Sprite.whenReady functions for Sprites).

Parameters:

image : Object. Could be Sprite or HTMLImageElement object.
dx : Number. Horizontal position in Canvas coordinates to draw the image.
dy : Number. Vertical position in Canvas coordinates to draw the image.
dWidth : Number. Width of the image rectangle on Canvas.
dHeight : Number. Height of the image rectangle on Canvas.



Function
drawImage
or
Canvas.drawImage
(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)

Draw Image or Sprite on Canvas. Make sure image is loaded and ready before drawing (use Sprite.isReady or Sprite.whenReady functions for Sprites).

Parameters:

image : Object. Could be Sprite or HTMLImageElement object.
sx : Number. Horizontal coordinate of the sub-rectangle of the source image.
sy : Number. Vertical coordinate of the sub-rectangle of the source image.
sWidth : Number. Width of the sub-rectangle of the source image.
sHeight : Number. Height of the sub-rectangle of the source image.
dx : Number. Horizontal position in Canvas coordinates to draw the image.
dy : Number. Vertical position in Canvas coordinates to draw the image.
dWidth : Number. Width of the image rectangle on Canvas.
dHeight : Number. Height of the image rectangle on Canvas.





Audio

global object and functions related to sound and music



Function
say
or
Audio.say
(text,lang="en-US")

Say the text using Text-to-speech engine.

Parameters:

text : String.
lang : Language constant:
"de-DE" - German
"en-GB" - United Kingdom English
"en-US" - United States English (default)
"es-ES" - Spanish
"fr-FR" - French
"it-IT" - Italian
"ru-RU" - Russian (Cyrillic characters not supported yet - use translit).
Optional parameter. If omitted equals to "en-US".



Function
setVolume
or
Audio.setVolume
(volume,channel=0)

Set volume for the audio channel specified.

Parameters:

volume : Number. Should be in range 0.00 to 1.00
channel : Audio channel number. Optional parameter. If omitted equals to 0.



Function
setOscillatorType
or
Audio.setOscillatorType
(oscillatorType,channel=0)

Set the oscillator type for the audio channel specified. Clears the channel.

Parameters:

oscillatorType : String. Supported types are: "sine","square","sawtooth","triangle".
channel : Audio channel number. Optional parameter. If omitted equals to 0.



Function
clearAudio
or
Audio.clear
(channel=0)

Clear the audio channel play queue. Stops sound generation.

Parameters:

channel : Audio channel number. Optional parameter. If omitted equals to 0.



Function
playSoundFrequency
or
Audio.playSoundFrequency
(frequency,duration,fade=0,channel=0)

Add specified frequency to the audio channel play queue.

Parameters:

frequency : Number. Frequency of the sound in Hz.
duration : Number. Duration of the sound in Seconds.
fade : Number. Specifies how much sound should fade through the duration in range 0.00 to 1.00 Optional parameter. If omitted equals to 0.
channel : Audio channel number. Optional parameter. If omitted equals to 0.



Function
playMidiNote
or
Audio.playMidiNote
(note,duration,fade=0,channel=0)

Add the frequency corresponding to the MIDI note number to the audio channel play queue.

Parameters:

note : Number. Note number as per MIDI specification in range 0 to 127
duration : Number. Duration of the sound in Seconds.
fade : Number. Specifies how much sound should fade through the duration in range 0.00 to 1.00 Optional parameter. If omitted equals to 0.
channel : Audio channel number. Optional parameter. If omitted equals to 0.



Function
beep
or
Audio.beep
(pitch,duration,channel=0)

Add simple beep sound to the audio channel play queue. Command is similar to the one found in ZX Spectrum Basic. Be aware that argument order differs. ZX Basic BEEP 1,0 equals to Tauon Basic beep(0,1).

Parameters:

pitch : Number. Pitch of the sound, given in semitones above middle C. Use negative numbers for notes below middle C.
duration : Number. Duration of the sound in Seconds.
channel : Audio channel number. Optional parameter. If omitted equals to 0.



Function
playMusic
or
Audio.playMusic
(musicNotationString,channel=0)

Parse music notation string and add resulting frequencies to the audio channel play queue.

Parameters:

musicNotationString : The notation might start with BPM character sequence, for example, "BPM120"
This defines the Tempo of the music. The default Tempo is 120.
You can set the current Octave with the O character, followed by the octave number (0-9). For example "O3" sets the third octave as a default one for the notes that will follow. The default octave is 4.
Capital letters represent single Note: C, D, E, F, G, A, B.
R character represents Rest (pause). It is treated as a Note by the engine, so all duration modifications could be applied.
# (sharp) symbol before Note raises the Note by a semitone (half-step up), for example, sharp C could be written as "#C".
b (small B letter) before Note lowers the Note by a semitone (half-step down), for example, flat D could be written as "bD".
To modify the octave of the Note - add a single number just after the Note: "C5" equals C from the fifth octave. "C+" will shift the octave up and "C-" - down. This octave shift doesn't affect the notes that will follow.
You can control the duration of notes that will follow using the L modifier. With L0 being the longest (Semibreve) and L6 being shortest (Hemidemisemiquaver).
The multiply character "*" after the Note will increase its duration by the factor of two. Two characters will increase Note duration by the factor of four.
The slash character "/" after the Note will decrease its duration by half. Two slashes will decrease Note duration by the factor of four.
The dot "." character after the Note increases duration by half. Two dots ".." will increase the duration by 1/2+1/4 and so on.
Underscore "_" character specifies that the current note is beamed with the following one.

channel : Audio channel number. Optional parameter. If omitted equals to 0.



Function
getRemainTime
or
Audio.getRemainTime
(channel=0)

Get the remaining play queue length (in seconds) for the audio channel specified.

Parameters:

channel : Audio channel number. Optional parameter. If omitted equals to 0.

Returns:

Number. Remaining play queue length (in seconds)





Sprite

global object and functions related to Sprite manipulation



Function
createSpriteFromEmoji
or
Sprite.createFromEmoji
(emoji,size,paperColor,clampWidth,clampHeight)

Create Sprite from one or more emoji character.

Parameters:

emoji : String. One or more emoji character. TwemojiMozilla font would be used to draw glyphs.
size : Number. Font size (in pixels) to draw characters with. Resulting Sprite height would be bigger than the number provided.
paperColor : String. Background color for the Sprite. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed.
clampWidth : Number. Clamp the width of the resulting Sprite object to the provided value in pixels.
clampHeight : Number. Clamp the height of the resulting Sprite object to the provided value in pixels.

Returns:

Reference to the newly created Sprite object. It might take some time for Sprite to load and initialize. Use Sprite.isReady and Sprite.whenReady functions if you wish to clone the Sprite or draw it on Canvas.



Function
createSpriteFromChar
or
Sprite.createFromChar
(character,size,inkColor,paperColor,clampWidth,clampHeight,fontFace)

Create Sprite from one or more font character.

Parameters:

character : String. One or more character. SourceCodePro font would be used to draw glyphs.
size : Number. Font size (in pixels) to draw characters with. Resulting Sprite height would be bigger than the number provided.
inkColor : String. Color to draw character with. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed.
paperColor : String. Background color for the Sprite. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed.
clampWidth : Number. Clamp the width of the resulting Sprite object to the provided value in pixels.
clampHeight : Number. Clamp the height of the resulting Sprite object to the provided value in pixels.
fontFace : String. "SourceCodePro" and "TwemojiMozilla" font faces are supported.

Returns:

Reference to the newly created Sprite object. It might take some time for Sprite to load and initialize. Use Sprite.isReady and Sprite.whenReady functions if you wish to clone the Sprite or draw it on Canvas.



Function
createSpriteFromData
or
Sprite.createFromData
(pixelData,width,height,paletteIndex=0)

Create Sprite from image data string. Each character represents index in palette [0..9A..Z] and defines color of the single pixel. The two default palettes have 17 colors [0..G]. You can use ' ' space character in the string to draw transparent pixel.

Parameters:

pixelData : String. Each character represents index in palette [0..9A..Z] and defines color of the single pixel. The two default palettes have 17 colors [0..G]. You can create more palettes with setPalette function.
width : Number. Width in pixels.
height : Number. Height in pixels.
paletteIndex : Number. Palette index to use. By default Tauon Basic has two palettes with indexes 0 and 1. You can create new or modify existing palette with setPalette function. Optional parameter. If omitted equals to 0.

Returns:

Reference to the newly created Sprite object. It might take some time for Sprite to load and initialize. Use Sprite.isReady and Sprite.whenReady functions if you wish to clone the Sprite or draw it on Canvas.



Function
createSpriteFromBin
or
Sprite.createFromBin
(bytesArray,width,height,inkColor="#FFFFFFFF",paperColor="#00000000")

Create Sprite from binary data array. Each element of the array would be treated as a binary number [0..255]. Each bit of that number will define 8 pixels of the Sprite. All bits equal to 1 would produce pixels with inkColor. Bits equal to 0 - with paperColor. If paperColor parameter is omitted, a transparent color would be used.

Parameters:

bytesArray : Array of bytes in range 0 to 255. Each element of the array will define 8 pixels of the Sprite.
width : Number. Width in pixels.
height : Number. Height in pixels.
inkColor : String. Color to draw character with. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to "#FFFFFFFF".
paperColor : String. Background color for the Sprite. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed. Optional parameter. If omitted equals to "#00000000".

Returns:

Reference to the newly created Sprite object. It might take some time for Sprite to load and initialize. Use Sprite.isReady and Sprite.whenReady functions if you wish to clone the Sprite or draw it on Canvas.

Examples:

let f=createSpriteFromBin([126,255,219,255,195,231,255,126],8,8);
setSprite(f,640,360,0,0,4,4);


Function
loadSpriteFromUrl
or
Sprite.loadFromUrl
(url)

Parameters:

url : String. Uniform Resource Locator. Could point to external address to load image from the web or could contain in-line data.

Examples:

let droid=loadSpriteFromUrl("http://tauonelectronics.com/home/droid.png");

let dot=loadSpriteFromUrl("data:image/png;base64,"+
"iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAA"+
"HElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4O"+
"HwAAAABJRU5ErkJggg==");


Function
loadSpriteFromFile
or
Sprite.loadFromFile
(fileName)

Parameters:

fileName : Local filesystem relative path (relative to the current path of the script) and file name.

Examples:

let sky=loadSpriteFromFile("/TauonBasicExamples/DinoOnTheRun/dino_run.png");

Function
createSpriteGroup
or
Sprite.createGroup
(...)

Create new SpriteGroup object and add it to the Screen. Pass various Sprites as parameters to add them to the group. You can add more Sprites later using spriteGroup.appendChild function.

Parameters:

any number of parameters, separated by coma.



Function
showSprite
or
Sprite.show
(sprite,bool=true)

Parameters:

sprite : previously created or loaded Sprite object.
bool : Boolean. Optional parameter. If omitted equals to true.



Function
hideSprite
or
Sprite.hide
(sprite)

Parameters:

sprite : previously created or loaded Sprite object.



Function
setSprite
or
Sprite.set
(sprite,px,py,pz,rotation,scaleX,scaleY)

Parameters:

sprite : previously created or loaded Sprite object.
px : Number. Horizontal position in Screen coordinates.
py : Number. Vertical position in Screen coordinates.
pz : Number. Z-index of the object. An element with greater z-index is always in front of an element with a lower z-index.
rotation : Number. Absolute rotation angle in Radians. Use degToRad() function to easily convert from degrees to radians.
scaleX : Number. Absolute horizontal Sprite scale factor.
scaleY : Number. Absolute vertical Sprite scale factor.



Function
setSpritePos
or
Sprite.setPos
(sprite,px,py,pz)

Set the Sprite position.

Parameters:

sprite : previously created or loaded Sprite object.
px : Number. Horizontal position in Screen coordinates.
py : Number. Vertical position in Screen coordinates.
pz : Number. Z-index of the object. An element with greater z-index is always in front of an element with a lower z-index.



Function
setSpriteRot
or
Sprite.setRot
(sprite,rotation)

Set Sprite rotation around it's center in Radians.

Parameters:

sprite : previously created or loaded Sprite object.
rotation : Number. Absolute rotation angle in Radians. Use degToRad() function to easily convert from degrees to radians.

Examples:

setSpriteRot(mySprite,degToRad(180));
Sprite.setRot(mySprite,3.14159);


Function
setSpriteScale
or
Sprite.setScale
(sprite,scaleX,scaleY=scaleX)

Parameters:

sprite : previously created or loaded Sprite object.
scaleX : Number. Absolute horizontal Sprite scale factor.
scaleY : Number. Absolute vertical Sprite scale factor. Optional parameter. If omitted equals to scaleX.



Function
setSpriteOpacity
or
Sprite.setOpacity
(sprite,opacity=1.0)

Parameters:

sprite : previously created or loaded Sprite object.
opacity : Number. Should be in range 0.00 to 1.00 Optional parameter. If omitted equals to 1.0.

Examples:

Sprite.setOpacity(mySprite,0.5);
setSpriteOpacity(0.25);


Function
setSpriteFilter
or
Sprite.setFilter
(sprite,filter="none")

Apply CSS filter to the Sprite.

Parameters:

sprite : previously created or loaded Sprite object.
filter : String. Supported filters are: none, blur(), brightness(), contrast(), drop-shadow(), grayscale(), hue-rotate(), invert(), opacity(), saturate(), sepia() Optional parameter. If omitted equals to "none".

Examples:

setSpriteFilter(mySprite,"blur(10px)");
Sprite.setFilter(mySprite,"contrast(50%)");
Sprite.setFilter(mySprite,"grayscale(50%)");
Sprite.setFilter(mySprite,"hue-rotate(90deg)");


Function
isSpriteReady
or
Sprite.isReady
(sprite)

Returns true if Sprite is loaded and fully initialized.

Parameters:

sprite : previously created or loaded Sprite object.



Function
whenSpriteReady
or
Sprite.whenReady
(sprite,callback)

Calls callback function when Sprite is loaded and fully initialized.

Parameters:

sprite : previously created or loaded Sprite object.
callback : Function reference. Function to call when operation finishes.



Function
cloneSprite
or
Sprite.clone
(sprite)

Returns cloned Sprite or Spritegroup. Make sure the source Sprite is ready or function will throw an error.

Parameters:

sprite : previously created or loaded Sprite object.

Returns:

Reference to the newly created Sprite object. It might take some time for Sprite to load and initialize. Use Sprite.isReady and Sprite.whenReady functions if you wish to clone the Sprite or draw it on Canvas.



Function
destroySprite
or
Sprite.destroy
(sprite)

Detaches Sprite from the Screen and frees all resources associated with the Sprite object.

Parameters:

sprite : previously created or loaded Sprite object.





Time

global object containing information related to time and frames

Properties:

time
: Number. Time since the current program is started in seconds.
deltaTime
: Number. Time passed since the last frame in seconds.
smoothDeltaTime
: Number. Smoothed value of the time passed since the last frame.
now
: Number. Current system time in milliseconds.
fps
: Number. Average FPS.
ticks
: Number. Ticks passed since the program started.





Math

global object and functions related to mathematics

Properties:

E
: Euler's constant and the base of natural logarithms (approximately 2.71828)
PI
: The ratio of a circle's circumference to its diameter (approximately 3.14159)
LN2
: Natural logarithm of 2 (approximately 0.69314)
LN10
: Natural logarithm of 10 (approximately 2.30259)
LOG2E
: Base-2 logarithm of E (approximately 1.44270)
LOG10E
: Base-10 logarithm of E (approximately 0.43429)



Function
abs
or
Math.abs
(X)

Returns the absolute value of X



Function
atan
or
Math.atan
(X)

Returns the arctangent of X



Function
cos
or
Math.cos
(X)

Returns the cosine of X



Function
exp
or
Math.exp
(X)

Returns E raised to power of X, where X is the argument, and E is Euler's constant



Function
int
or
Math.trunc
(X)

Returns the integer portion of X



Function
ln
or
Math.log
(X)

Returns the natural logarithm of X



Function
pow
or
Math.pow
(X,Y)

Returns base X to the exponent power of Y



Function
rnd
or
Math.random
()

Returns a pseudo-random number in range 0 to 1



Function
sin
or
Math.sin
(X)

Returns the sine of X



Function
sqrt
or
Math.sqrt
(X)

Returns the positive square root of X



Function
tan
or
Math.tan
(X)

Returns the tangent of X



Function
round
or
Math.round
(X)

Returns X rounded to the nearest integer



Function
degToRad
or
Math.degToRad
(degrees)

Parameters:

degrees : Number. Angle in Degrees units.

Returns:

Number. Angle in Radians units.

Examples:

print("180 Degrees equals to ",degToRad(180)," Radians");

Function
radToDeg
or
Math.radToDeg
(radians)

Parameters:

radians : Number. Angle in Radians units.

Returns:

Number. Angle in Degrees units.





Built-in functions



Function
alert
(text)

Show an alert box with a specified text and an OK button.

Parameters:

text : String.



Function
confirm
(text)

Show a dialog box with OK and Cancel buttons. Returns true if "OK" button pressed, false otherwise.

Parameters:

text : String.



Function
prompt
(text, default)

Show a dialog box with a specified text, input field, and an OK button. Returns user inputted string.

Parameters:

text : String.
default : String. The default value.



Function
parseInt
(str, radix)

Return the integer value parsed from the argument string.

Parameters:

str : String.
radix : Number. An integer between 2 and 36 that represents the base of the numeral system. Optional.

Returns:

Number.

Examples:

print("7C0 in HEX equals to ",parseInt("7C0",16)," in DEC system");

Function
parseFloat
(str)

Return the float value parsed from the argument string.

Parameters:

str : String.

Returns:

Number.



Function
end
()

Return to IDE or exit from the application if in standalone mode.



Function
isMouseDown
(btnCode)

Returns true if mouse button is currently down.

Parameters:

btnCode : Number. 0 - left mouse button. 2 - right mouse button.



Function
isKeyDown
(keyCode)

Returns true if keyboard key with specified scan code is pressed.

Parameters:

keyCode : Number. Keyboard key code. Some useful codes are:
[1] key - 49, [A] key - 65, [Enter] - 13, [Space] - 32, [F1] key - 112.



Function
setPalette
(paletteIndex,colorArray=[])

Parameters:

paletteIndex : Number. Palette index to use. By default Tauon Basic has two palettes with indexes 0 and 1. You can create new or modify existing palette with setPalette function.
colorArray : Array. Each element of the array should be a string containing valid color. Both English color names ("yellow","red") and hex format (short "#F90" or long "#FF0000") forms are supported. Optional parameter. If omitted equals to [].



Function
rgbaToColor
(rgba=[255,255,255,255])

Parameters:

rgba : Array. Should contain 3 or 4 integers in range 0 to 255, representing color component values [Red, Ggreen, Blue, Alpha]. Optional parameter. If omitted equals to [255,255,255,255].

Returns:

String. Color value. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed.



Function
colorToRGBA
or
hexColorToRGBA
(color)

Parameters:

color : String. Color value. English color name ("yellow","red") or hex format (short "#F90" or long "#FF0000") allowed.

Returns:

Array. Should contain 3 or 4 integers in range 0 to 255, representing color component values [Red, Ggreen, Blue, Alpha].



Function
palToHex
or
paletteCharToHexColor
(colorIndex,paletteIndex=0)

Get color corresponding to the colorIndex index from the paletteIndex palette.

Parameters:

colorIndex : String. or Number. Color index in the Palette. Supported indexes are from "0" to "9" and from "A" to "Z". If argument of Number type provided it would be treated as numeical color index.
paletteIndex : Number. Palette index to use. By default Tauon Basic has two palettes with indexes 0 and 1. You can create new or modify existing palette with setPalette function. Optional parameter. If omitted equals to 0.



Function
endOnAnyKey
(bool=true)

Call this function with argument false to prevent program termination on any keypress.

Parameters:

bool : Boolean. Optional parameter. If omitted equals to true.



Function
shellExec
(cmd,callback)

Execute Linux shell command and pass the result to the callback function when done.

Parameters:

cmd : String. Linux shell command to execute.
callback : Function reference. Function to call when operation finishes.



Function
log
(...)

Adds text to the IDE console

Parameters:

any number of parameters, separated by coma.



Function
debug
(...)

Adds debug text message to the IDE console

Parameters:

any number of parameters, separated by coma.



Function
warning
(...)

Adds warning mesasge to the IDE console

Parameters:

any number of parameters, separated by coma.



Function
error
(...)

Adds an error description to the IDE console and terminates the program execution

Parameters:

any number of parameters, separated by coma.





Built-in event handlers

Define following functions in the code to handle events.



Function
onUpdate
()

If you define this function it would be called by the engine 50-60 times per second.

Examples:

function onUpdate(){
print("Time since program start: "+Time.time);
}


Function
onKeyDown
(keyCode)

Parameters:

keyCode : Number. Keyboard key code. Some useful codes are:
[1] key - 49, [A] key - 65, [Enter] - 13, [Space] - 32, [F1] key - 112.

Examples:

function onKeyDown(keyCode){
print("Keyboard Key Down: ",keyCode);
}


Function
onKeyUp
(keyCode)

Parameters:

keyCode : Number. Keyboard key code. Some useful codes are:
[1] key - 49, [A] key - 65, [Enter] - 13, [Space] - 32, [F1] key - 112.



Function
onMouseDown
(btnCode)

Parameters:

btnCode : Number. 0 - left mouse button. 2 - right mouse button.



Function
onMouseUp
(btnCode)

Parameters:

btnCode : Number. 0 - left mouse button. 2 - right mouse button.



Function
onMouseMove
(mouseX,mouseY)

Parameters:

mouseX : Number. Horizontal position in screen coordinates of the Mouse cursor.
mouseY : Number. Vertical position in screen coordinates of the Mouse cursor.

Examples:

function onMouseMove(mouseX,mouseY){
print("Mouse pos: ",mouseX," ",mouseY);
}