|
PixilangV3Manual
What is PixilangPixilang — cross-platform programming language for graphic/sound applications. BasicsThe basis of the Pixilang - are containers and variables. Container is a two-dimensional array of elements. Each element is the number in a specific format. Each container has one format for all its elements. Each container has its own unique ID number. Variable can contain 32-bit signed integer (for example 25) or 32-bit floating point number (for example 33.44). The simplest example of the use of containers and variables x = new( 4 ) //Create a new container with 4 pixels. Store its ID into the variable x. x[ 2 ] = WHITE //Assign the white color to a pixel with number 2. remove( x ) //Remove this container str = "Hello" //"Hello" is the container with five characters. //Such containers with strings are created on the stage of compilation of your program. //You don't need to delete them manually. str[ 0 ] = 'h' //Change first character from 'H' to 'h'. a = 4 //Global variable
fn function()
{
$k = 2 //Local variable
function2 = {
//Body of another function
$x = 899.334 //Local variable
//$k is not accessible here
}
//$x is not accessible here
}
//$k and $x are not accessible herePaths and file namesIn examples //File is located in several directories relative to the current location of the pixi-program: "folder1/folder2/folder3/prog.pixi" //File is in the current working directory // for Linux/Windows/OSX: in the same folder with Pixilang; // for iOS: documents; // for WinCE: root of local filesystem (/); "1:/prog.pixi" //File is in the user's directory (for example /home/alex in Linux): "2:/prog.pixi" //File is in the temporary directory: "3:/prog.pixi" Built-in operators//if, else
if a == b
{ /*This code is executed if a equals b*/ }
else
{ /*This code is executed otherwise*/ }
if x == 4 && y == 2
{ /*This code is executed if x equals 4 and y equals 2*/ }
//while
a = 0
while( a < 3 )
{
//This code is executed while a less than 3
a + 3
}
//go, goto
m1:
a + 1
goto m1 //Go to the m1 label
//halt, stop
halt //Stop the program here
//include
include "prog2.txt" //Include code from prog2.txt
//fn
fn fff( $x, $y ) //Declare function fff with parameters $x and $y
{
//Function fff body
ret //Simple return from the function
ret( 4 ) //Return with value 4
}The following table lists the mathematical operators. Priority 0 - the highest, such operations will be executed in the first place.
Built-in constantsContainer types
Sizes
File formats
Colors
Alignment
EffectsEffect types for effector() function:
AudioFlags for set_audio_callback() function:
MIDIFlags for midi_get_device(), midi_open_port() functions:
Events
EVT field numbers:
Mathematical
Data processing operationsFor op_cn() function:
For op_cn(), op_cc() function:
For op_cc() function:
For op_ccn() function:
For generator() function:
Sampler
Sample info field numbers:
Sample info flags:
Native code constants
Constants for POSIX compatibility
Various
Built-in global variables
Reserved container propertiesThese properties can be created after the load() function:
Built-in functionsWork with containers (memory allocation)newCreate new data container. Note: immediately after its creation, the container may contain some random values. You should clean it up or fill it with useful data. Parameters ( xsize, ysize, type )
Return value Number of the container, or -1 (error). Examples p = new() //Create 1x1 container. Element type = pixel. p = new( 4 ) //Create 4x1 container. Element type = pixel. p = new( 4, 4 ) //Create 4x4 container. Element type = pixel. p = new( 4, 4, INT32 ) //Create 4x4 container. Element type = INT32. removeRemove a container. Parameters ( pixi )
Examples p = new() //Create new container remove( p ) //Remove it resizeResize a container. Parameters ( pixi, xsize, ysize, type )
Return value 0 - successful; 1 - error. Examples p = new( 4, 4 ) //Create new container resize( p, 32, 32 ) //Resize it from 4x4 to 32x1 resize( p, -1, 64 ) //Resize it from 32x32 to 32x64 remove( p ) //Remove convert_typeConvert the type of a container. Parameters ( pixi, new_type ) cleanClean a container (fill with zeroes or with selected values). Parameters ( dest_cont, v, offset, count )
Examples p = new() //Create new container clean( p ) //Clean with zero clean( p, 3 ) clean( p, 3, 0, 24 ) //Fill 24 elements with value 3 remove( p ) //Remove cloneMake a duplicate of the container. Parameters ( pixi )
Return value Number of the new container, or -1 (error). copyCopy container elements from src to dest. Parameters ( dest, src, dest_offset, src_offset, count, dest_step, src_step )
Examples //Copy all elements from img1 to img2: copy( img2, img1 ) //Copy elements 8...200 from img1 to img2: copy( img2, img1, 8, 8, 200 ) //Copy elements 8...400 from img1 to img2 with step 2: copy( img2, img1, 8, 8, 200, 2, 2 ) Return value Number of copied elements. get_sizeGet size of a container (number of elements). Parameters ( pixi )
Examples p = new( 8, 8 ) //Create a new container 8x8 size = get_size( p ) //Save its size to the "size" variable remove( p ) get_xsizeGet width of a container. Parameters ( pixi )
Examples p = new( 8, 8 ) //Create a new container 8x8 xsize = get_xsize( p ) //Save its width to the "xsize" variable remove( p ) get_ysizeGet height of a container. Parameters ( pixi )
Examples p = new( 8, 8 ) //Create a new container 8x8 ysize = get_xsize( p ) //Save its height to the "ysize" variable remove( p ) get_esizeGet the size of the element of a container (in bytes). Parameters ( pixi )
Examples p = new( 8, 8, INT32 ) //Create a new container 8x8; element type = INT32 esize = get_esize( p ) //Save its element's size to the "esize" variable //Now esize = 4. remove( p ) get_typeGet the type of the element of a container Parameters ( pixi )
Examples p = new( 8, 8, FLOAT32 ) //Create a new container 8x8; element type = FLOAT32 type = get_type( p ) //Save its element's type to the "type" variable //Now type = FLOAT32. remove( p ) get_propGet property value of the container. Each container can have unlimited number of properties. Parameters ( pixi, prop_name, def_value )
Return value Value of selected property. set_propSet property value of the container. Parameters ( pixi, prop_name, value )
Examples p = new( 8, 8, INT32 ) //Create a new container set_prop( p, "speed", 777 ) //Add "speed" property to this container v = get_prop( p, "speed" ) //Read the value of "speed" property remove_propsRemove all properties of the selected container. Parameters ( pixi ) Stringsnum_to_strAliases: num2str. Convert number to string. Parameters ( str, num )
Examples v = 45.64 s = "" num_to_str( s, v ) fputs( s ) fputs( "\n" ) str_to_numAliases: str2num. Convert string to number. Parameters ( str )
Return value Numeric value. Examples a = str_to_num( "-55.44" ) b = a + 4 File formatsloadExamples c = load( "smile.jpg" ) saveParameters ( pixi, filename, format, quality )
Examples c = load( "smile.jpg" ) save( c, "smile.png", FORMAT_PNG ) save( c, "smile2.jpg", FORMAT_JPEG ) //Quality = 85 (default) save( c, "smile3.jpg", FORMAT_JPEG, 100 ) //Quality = 100 GraphicsframeDraw current screen on display and delay for selected number of milliseconds. Parameters ( delay, x, y, xsize, ysize )
set_screenSet current screen. Parameters ( pixi )
get_screenGet current screen. Return value Container's number. set_zbufParameters ( zbuf_container ) Set container with Z-buffer. Must be INT32. get_zbufget_colorGet color by r,g,b (red,green,blue). Parameters ( red, green, blue )
Return value Color. get_redGet red component intensity in a selected color. Parameters ( color ) Return value Red component intensity. From 0 to 255. get_greenGet green component intensity in a selected color. Parameters ( color ) Return value Green component intensity. From 0 to 255. get_blueGet blue component intensity in a selected color. Parameters ( color ) Return value Blue component intensity. From 0 to 255. get_blendGet an intermediate color value between two selected colors. Parameters ( c1, c2, v )
Return value Intermediate color. transpSet transparency. Parameters ( t )
get_transpclearClear current screen. Parameters ( color ) dotDraw a dot. Parameters ( x, y, color ) dot3dDraw a dot in 3D. Parameters ( x, y, z, color ) get_dotGet a dot's color. Parameters ( x, y ) Return value Color. get_dot3dGet a dot's color in 3D. Parameters ( x, y, z ) Return value Color. lineDraw a line. Parameters ( x1, y1, x2, y2, color ) line3dDraw a line in 3D. Parameters ( x1, y1, z1, x2, y2, z2, color ) boxDraw a rectangle. Parameters ( x, y, xsize, ysize, color ) fboxDraw a filled rectangle. Parameters ( x, y, xsize, ysize, color ) pixiDisplay the container with the picture. Parameters ( pixi_cont, x, y, color, xscale, yscale, src_x, src_y, src_xsize, src_ysize )
Examples pixi( image ) pixi( image, 10, 20 ) pixi( image, 30, 40, GREEN ) pixi( image, 90, 20, GREEN, 0.5, 0.5 ) set_key_colorSet / reset the color of transparency in the container. Parameters ( pixi, color )
get_key_colorset_alphaAttach a container with alpha channel to another container. Alpha channel should be of type INT8. Parameters ( pixi, alpha )
get_alphaShow text on the screen. Parameters ( text, x, y, color, align )
Examples print( "Hello Pixi!", 0, 0 ) //color = WHITE; centered; print( "line1\nline2", 50, 50, RED ) //centered; print( "line1\nline2", -50, 50, RED, TOP | LEFT ) //alignment = top left; get_text_xsizeParameters ( text, align ) Return value Text width in pixels. get_text_ysizeParameters ( text, align ) Return value Text height in pixels. set_fontParameters ( first_char_utf32, font_image, xchars, ychars ) get_fontParameters ( char_utf32 ) Return value Container ID with font for selected character. effectorApply an effect to selected screen area. Coordinates of this function can't be changed by t_xxx transformation functions. Parameters ( type, power, color, x, y, xsize, ysize, x_step, y_step ) Animationpack_framePack current frame (from container data to hidden storage with frames). Frame number must be stored in the "frame" container property. Parameters ( pixi ) unpack_frameUnpack current frame (from hidden storage with frames to container data). Frame number must be stored in the "frame" container property. Parameters ( pixi ) create_animCreate the hidden storage with frames (animation) in the selected container. Parameters ( pixi ) remove_animRemove the hidden storage with frames (animation) from the selected container. Parameters ( pixi ) clone_frameClone current frame. Frame number must be stored in the "frame" container property. Parameters ( pixi ) remove_frameRemove current frame. Frame number must be stored in the "frame" container property. Parameters ( pixi ) playEnable auto-play mode. Frame will be changed automatically during the pixi() function call. Parameters ( pixi ) stopDisable auto-play mode. Parameters ( pixi ) TransformationCoordinate system transformation. t_resetReset transformation. t_rotateParameters ( angle, x, y, z ) t_translateParameters ( x, y, z ) t_scaleParameters ( x, y, z ) t_get_matrixGet transformation matrix (4x4 FLOAT). Parameters ( matrix_container ) t_set_matrixSet transformation matrix (4x4 FLOAT). Parameters ( matrix_container ) t_mul_matrixMultiply transformation matrix (4x4 FLOAT). Current matrix = current matrix * matrix_container Parameters ( matrix_container ) t_pointTransform point (container with 3 elements of type FLOAT). Parameters ( point_coordinates ) Audioset_audio_callbackParameters ( callback, userdata, freq, format, channels, flags ) Examples fn audio_callback( $stream, $userdata, $channels, $frames, $time )
{
generator( OP_SIN, $channels[ 0 ], 0, 32767 / 2, 0.1, 0 ) //Left channel
generator( OP_SIN, $channels[ 1 ], 0, 32767 / 2, 0.1, 0 ) //Right channel
ret(1)
}
//Start audio:
set_audio_callback( audio_callback, 0, 22050, INT16, 2, AUDIO_FLAG_INTERP2 )//Stop audio: set_audio_callback( -1 ) enable_audio_inputParameters ( disable_enable ) get_note_freqParameters ( note, finetune )
Return value Note frequency in Hz. MIDImidi_open_clientParameters ( client_name ) Return value Client ID. midi_close_clientParameters ( client_id ) midi_get_deviceParameters ( client_id, device_num, flags ) Return value Selected device name, or -1 if not exists. midi_open_portParameters ( client_id, port_name, device_name, flags ) Return value Port ID. midi_reopen_portParameters ( client_id, port_id ) midi_close_portParameters ( client_id, port_id ) midi_get_eventParameters ( client_id, port_id, data_cont ) Return value Size of current MIDI event (in bytes). midi_get_event_timeParameters ( client_id, port_id ) Return value Time of current event (in system ticks). midi_next_eventGo to the next event. Parameters ( client_id, port_id ) midi_send_eventParameters ( client_id, port_id, data_cont, data_size, t ) Timestart_timerStart selected timer. Parameters ( timer_num ) get_timerGet value (in milliseconds) of selected timer. Parameters ( timer_num ) Return value 32bit value (in milliseconds) of selected timer. get_yearget_monthget_dayget_hoursget_minutesget_secondsget_ticksGet current system tick counter (32bit). get_tpsGet number of system ticks per second. sleepParameters ( delay )
Eventsget_eventGet a new event from the system. Return value 0 - no events. 1 - event is received and placed into a container EVT. set_quit_actionSet the program's behavior when receiving event EVT_QUIT. Parameters ( action )
Possible values for the action parameter:
Threadsthread_createParameters ( thread_function, user_data ) Return value Thread number or -1 if error occurred. thread_destroyParameters ( thread_num, timeout_ms ) Return value 0 if the thread closed successfully. mutex_createExamples new_mutex = mutex_create() mutex_lock( new_mutex ) mutex_unlock( new_mutex ) mutex_destroy( new_mutex ) mutex_destroymutex_lockmutex_trylockmutex_unlockMathematicalacosacoshasinasinhatanatanhceilcoscoshexpexp2expm1absfloormodloglog2log10powsinsinhsqrttantanhrandrand_seedData processingNote: data processing functions can't work with dynamic containers. op_cnExecute data processing operation. Operands: 1) container (c); 2) numerical value (n). Parameters ( opcode, pixi, num, x, y, xsize, ysize )
Examples //Add 32 to the whole container img: op_cn( OP_ADD, img, 32 ) //Add 32 to 128..256th elements of the container img: op_cn( OP_ADD, img, 32, 128, 128 ) //Add 32 to two-dimensional region (8,8,32,32) of elements: op_cn( OP_ADD, img, 32, 8, 8, 32, 32 ) op_ccExecute data processing operation. Operands: 1) container (c); 2) container (c). Operation expression: for each element of pixi1: pixi1[ i ] = pixi1[ i ] OP pixi2[ i ] Parameters ( opcode, pixi1, pixi2 ) - for whole container pixi1
Parameters ( opcode, pixi1, pixi2, dest_x, src_x, xsize ) - for 1D region Parameters ( opcode, pixi1, pixi2, dest_x, dest_y, src_x, src_y, xsize, ysize ) - for 2D region op_ccnExecute data processing operation. Operands: 1) container (c); 2) container (c) 3) numerical value (n). Operation expression: for each element of pixi1: pixi1[ i ] = pixi1[ i ] OP pixi2[ i ] / num Parameters ( opcode, pixi1, pixi2, num ) - for whole container pixi1
Parameters ( opcode, pixi1, pixi2, num, dest_x, src_x, xsize ) - for 1D region Parameters ( opcode, pixi1, pixi2, dest_x, dest_y, num, src_x, src_y, xsize, ysize ) - for 2D region generatorGenerate a signal. Parameters ( opcode, pixi, phase, amplitude, delta_x, delta_y, x, y, xsize, ysize )
Examples //Generate a sine wave to the whole container img: generator( OP_SIN, img, 0, 1, 0.1, 0.1 ) //Generate a rough sine wave to the whole container img: generator( OP_SIN8, img, 0, 1, 0.1, 0.1 ) //Generate a sine wave to 8...128 elements of the container img: generator( OP_SIN, img, 0, 1, 0.1, 0.1, 8, 128 ) //Generate a sine wave to region (8,8,32,32) of the container img: generator( OP_SIN, img, 0, 1, 0.1, 0.1, 8, 8, 32, 32 ) samplerParameters ( sample_info ) Examples sample_data = new( 256, 1, INT16 ) //16bit sample sample_info = new( SMP_INFO_SIZE, 1, INT32 ) clean( sample_info ) sample_info[ SMP_DEST ] = buffer //Destination container sample_info[ SMP_DEST_OFF ] = 0 //Destination offset sample_info[ SMP_DEST_LEN ] = 256 //Destination length sample_info[ SMP_SRC ] = sample_data sample_info[ SMP_SRC_OFF_H ] = 0 //Sample offset (left part of fixed point value) sample_info[ SMP_SRC_OFF_L ] = 0 //Sample offset (right part of fixed point value from 0 to 65535) sample_info[ SMP_LOOP ] = 0 //Loop start sample_info[ SMP_LOOP_LEN ] = 128 //Loop length (or 0, if no loop) sample_info[ SMP_VOL1 ] = 0 //Start volume sample_info[ SMP_VOL2 ] = 32768 //End volume (32768 = 1.0) sample_info[ SMP_DELTA ] = ( 1 << 16 ) //Delta; fixed point (real_value * 65536) sample_info[ SMP_FLAGS ] = SMP_FLAG_INTERP4 | SMP_FLAG_PINGPONG //Cubic spline interpolation and ping-pong loop sampler( sample_info ) //Go! envelope2pApply gain and DC-offset two-points envelope to selected container area. Without clipping. Parameters ( data_cont, v1, v2, offset, size, dc_offset1, dc_offset2 )
fftPerform a fast fourier transform. Parameters ( inverse, im, re, size ) replace_valuesFor each element of dest container: dest[ i ] = values[ (unsigned)src[ i ] ]. The dest container must have the same type as the values. Parameters ( dest, src, values )
Examples //Convert 8-bit image with palette to the screen pixel format: replace_values( scr, img8, palette ) Dialogsfile_dialogOpen file dialog. Parameters ( dialog_name, mask, id, default_name )
Return value Container number with selected file name. Or -1 if file not selected. Container must be deleted manually. Native codedlopenOpen dynamic library (for example - .DLL file in Windows, or .SO file in Linux). Parameters ( lib_file_name ) Return value Library ID or -1 if error occured. dlcloseClose dynamic library. Parameters ( lib_id ) dlsymGet symbol (function or variable) from dynamic library. Parameters ( lib_id, symbol_name, format, calling_convention )
Return value Symbol ID or -1 if error occured. dlcallCall the function from dynamic library. Parameters ( lib_id, symbol_id, optional_function_parameters ) System functions (compatibility with POSIX)fopenThe fopen() function shall open the file whose pathname is the string pointed to by filename, and associates a stream with it. Parameters ( filename, mode )
Return value Upon successful completion, fopen() shall return ID of the object controlling the stream. Otherwise, 0 shall be returned. Examples f = fopen( "/tmp/data.txt", "rb" ) //Open file data.txt for reading fclose( f ) //...and close it. fcloseThe fclose() function shall cause the stream to be flushed and the associated file to be closed. Parameters ( stream ) Return value Upon successful completion, fclose() shall return 0. Examples f = fopen( "/tmp/data.txt", "rb" ) //Open file data.txt for reading. c = fgetc( f ) //Get a byte from this file. fclose( f ) //Close the stream. fputcPut a byte on a stream. Parameters ( c, stream ) Examples f = fopen( "/tmp/data.txt", "wb" ) //Open file data.txt for writing. fputc( 0x12, f ) //Put a byte 0x12 to this file. fclose( f ) //Close the stream. fputsPut a string on a stream. Parameters ( s, stream ) Examples f = fopen( "/tmp/data.txt", "wb" ) //Open file data.txt for writing. str = "Hello!" fputc( str, f ) //Put a string "Hello!" to this file. fclose( f ) //Close the stream. fwriteThe fwrite() function shall write, from the container data, up to size bytes, to the stream pointed to by stream. Parameters ( data, size, stream ) Return value The fwrite() function shall return the number of bytes successfully written, which may be less than size if a write error is encountered. Examples f = fopen( "/tmp/data.txt", "wb" ) //Open file data.txt for writing. str = "Hello!" fwrite( str, 2, f ) //Put first two bytes from the string "Hello!" to this file. fclose( f ) //Close the stream. fgetcGet a byte from a stream. Parameters ( stream ) Return value Upon successful completion, fgetc() shall return the next byte from the input stream pointed to by stream. fgetsGet a string from a stream. Parameters ( s, n, stream ) Examples string = new( 256, 1, INT8 ) f = fopen( "/tmp/data.txt", "rb" ) //Open file data.txt for reading. fgets( string, 256, f ) //Get a string from this file. fclose( f ) //Close the stream. freadThe fread() function shall read into the container pointed to by data up to size bytes, from the stream pointed to by stream. Parameters ( data, size, stream ) Return value Upon successful completion, fread() shall return the number of bytes successfully read which is less than size only if a read error or end-of-file is encountered. feofTest end-of-file indicator on a stream. Parameters ( stream ) Return value The feof() function shall return non-zero if and only if the end-of-file indicator is set for stream. fflushFlush a stream. Parameters ( stream ) fseekReposition a file-position indicator in a stream. Parameters ( stream, offset, origin )
ftellReturn a file offset in a stream. Parameters ( stream ) Return value Upon successful completion, ftell() shall return the current value of the file-position indicator for the stream measured in bytes from the beginning of the file. Examples //One of the ways to get the file size: f = fopen( "/tmp/data.txt", "rb" ) fseek( f, 0, SEEK_END ) size_of_file = ftell( f ) fclose( f ) remove_fileParameters ( filename ) rename_fileParameters ( old_filename, new_filename ) copy_fileParameters ( source_filename, destination_filename ) strcatAppends a copy of the source string to the destination string. Both strings can be with terminating null character or without it (if the size of the container = number of characters in the string). Size of the source string can be changed after this function executes. Parameters ( destination, source ) strcmpCompares the string str1 to the string str2. Both strings can be with terminating null character or without it (if the size of the container = number of characters in the string). Parameters ( str1, str2 ) Return value A zero value indicates that both strings are equal. A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite. strlenReturns the length of string str. String can be with terminating null character or without it (if the size of the container = number of characters in the string). Parameters ( str ) Return value Length of string str. strstrReturns the offset of the first occurrence of str2 in str1, or a -1 if str2 is not part of str1. Parameters ( str1, str2 ) Return value Offset of the first occurrence of str2 in str1, or a -1 if str2 is not part of str1. sprintfWrites into the container str a string consisting on a sequence of data formatted as the format argument specifies. Parameters ( str, format, ... ) Return value On success, the total number of characters written is returned. On failure, a negative number is returned. systemIssue a OS command. Parameters ( command ) Return value system() shall return the termination status of the command. Examples //Remove some file: system( "rm /tmp/data.txt" ) argcReturns the number of arguments. argvReturns the container with selected argument. Parameters ( n ) Examples if argc >= 4
{
a = argv( 3 )
remove( a )
}exitQuit from Pixilang. Examples exit( 4 ) //Exit with code 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||