Pixilang

From Bauman National Library
This page was last modified on 8 June 2016, at 20:43.

Pixilang is a pixel-oriented programming language for small graphics/sound applications and experiments. Originally created by Alexander Zolotov (NightRadio) and Mik Razuvaev (Goglus) for non-programmers, demosceners and designers. It is cross-platform and open source (MIT License).

Versions

1.6

Pixilang 1.6 (August 14 2008) is the last stable branch of 1.x. It runs under GNU/Linux, Microsoft Windows, Microsoft Windows CE и PalmOS operating systems. Main part is distributed under BSD License, while GIF и XM libraries are distributed under GNU General Public License.

2.0

Pixilang 2.0 (August 14 2008) is an experimental version. In terms of functionality it is almost identical to version 1.6 but has built-in JIT-compiler for increased performance on x86 platform. Runs only under Linux and Windows.

3

Pixilang 3 is a new version of the language rewritten almost from scratch. It includes elimination of the flaws of older versions as well as some new features. Version 3 is only partially compatible with versions 1.6 and 2.0.

Main differences from older versions are:

  • a variable can store either integer or floating point numbers;
  • introduced local variables (that are only active within the limits of one function); they differ by using $ symbol in front of the name;
  • the language is ported to OSX, iOS and Android;
  • introduced feature to call a function from system DLLs.

Key features of version 3

  • universal containers (pixi-container) for any type of data;
  • dynamically typed variables (for integer or floating point numbers);
  • functions for sound synthesis and recording;
  • functions for block data processing;
  • supported file formats (load/save): WAV, PNG, JPEG, GIF (animated);
  • supported sound systems: ASIO, DirectSound, MME, ALSA, OSS, JACK (iOS and Linux);
  • native code (external dynamic libraries) support;
  • OpenGL acceleration;
  • MIDI In/Out.

Overview

Pixilang programs are stored in text files (UTF8) with extensions .txt or .pixi. So developers can use their favorite text editor to create/edit these files. Pixilang has no built-in editor.

The 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.

Container structure:

  • two-dimensional table of container elements - this may be some image, text string, piece of audio, or other data;
  • key color, which will be treated as transparent color (with alpha=0);
  • reference to a container with alpha-channel;
  • additional data:
    • properties (use get_prop(), set_prop(), remove_props(), or a . (dot) operator to access them);
    • animation (use Animation functions to access it).

The new container can be created with the new() function or returned by some other function. There are two ways to remove the container:

  • by user through the remove() function;
  • automatically after the end of the program.

There is no automatic garbage collector.

Variable can contain 32-bit signed integer or 32-bit floating point number.

Numbers can be described in different formats. Examples:

  • 33 - decimal;
  • 33.55 - decimal floating point;
  • 0xA8BC - hexadecimal;
  • 0b100101011 - binary;
  • #FF9080 - color, as in HTML; base format is #RRGGBB, where RR - red intensity (from 00 to FF), GG - green intensity; BB - blue intensity.

Container Examples

 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
 c = new( 4, 4 ) //Create a new 2D 4x4 pixel container. Store its ID into the variable x.
 c[ 2, 2 ] = WHITE //Assign the white color to a pixel with coordinates x=2 y=2.
 remove( c ) //Remove this container
str = "Hello" //"Hello" is the string container with five 8-bit characters (UTF-8 encoding).
//This container (with string) will be created only once, during the bytecode generation.
//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 here

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
}

While + Break

a = 0
while( a < 100 )
{
  if a == 10 { break } //If a = 10, break the loop
  //Use breakX operator to break X nested loops. Example: break2
  //Use breakall operator to break all current active loops
  a + 1
}

While + Continue

a = 0
b = 0
while( a < 100 )
{
  if a == 10 { a + 1 continue } //If a = 10, go to the next loop iteration 
                                //           (ignore the next two lines of code)
  a + 1
  b + 1
}

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 first.

Priority Operator Description Result Example
0  % Modulo (remainder) Integer a = b % 4
0 / Division Floating point a = b / 4
0 div Integer division Integer a = b div 4
0 * Multiplication Depends on the operands a = b * 4
1 + Addition Depends on the operands a = b + 4
1 - Subtraction Depends on the operands a = b - 4
2 >> Bitwise right shift Integer a = b >> 4
2 << Bitwise left shift Integer a = b << 4
3 == Equal to Integer 1 or 0 if a == b {}
3  != Not equal to Integer 1 or 0 if a != b {}
3 < Less than Integer 1 or 0 if a < b {}
3 > Greater than Integer 1 or 0 if a > b {}
3 <= Less than or equal to Integer 1 or 0 if a <= b {}
3 >= Greater than or equal to Integer 1 or 0 if a >= b {}
4 | Bitwise OR Integer a = b | 4
4 ^ Bitwise XOR Integer a = b ^ 4
4 & Bitwise AND Integer a = b & 4
5 || Logical OR Integer 1 or 0 if a || b {}
5 && Logical AND Integer 1 or 0 if a && b {}

Code examples

Here are some basic examples for Pixilang V3:

//Load and display a picture from the file:
img = load( "image.jpg" )
s: pixi( img )
frame()
go s
// Display a picture on a screen with scaling and dyeing it green:
img = load( "image.jpg" )
s: pixi( img, 0, 0, GREEN, 2, 2 )
frame()
go s
// Load and play GIF-animation:
img = load( "animation.gif" )
play( img )
s: pixi( img )
frame()
go s

Here is also a basic example for Pixilang V1.6 or V2.0:

//Simple animation example for Pixilang 1.6 or 2.0
//Write color #003050 to the variable o
o = #003050
//Describe an animated picture (pixi), 
//that consists of two frames:
logo = "
.o...ooo...o.
..o..o.o..o..
...ooooooo...
...ooooooo...
.ooooooooooo.
.o.ooooooo.o.
oo.........oo
+
.o...ooo...o.
..o..o.o..o..
...ooo.ooo...
...ooooooo...
.ooooooooooo.
.o.ooooooo.o.
oo.........oo
"
//Now we make the language to transform this picture 
//from text format into graphic:
make_pixi( logo ) 
//This variable will store scaling factor:
zm = 20 
//Метка:
start: 
//Set transparency to 64:
transp( 64 ) 
//Clear the screen with white color. But not fully, just slightly 
//because transparency is set to 64:
clear( #FFFFFF )
//Set transparency to 256 (opaque):
transp( 256 ) 
//Draw our picture logo at 0,0 coordinates with scaling zm:
pixi( logo, 0, 0, zm ) 
//Decrease the scaling by 1:
zm - 1 
//Display the result and wait for 100 milliseconds:
frame( 100 ) 
//Jump to label start:
go start

The result can be seen here

Applications created with Pixilang

  1. Virtual ANS - a software simulator of the unique Russian synthesizer ANS. It is a full-featured professional tool which allows you to create unusual, deep, atmospheric sounds. With this app you can draw a complete piece of music, or convert sound to image (sonogram) and then make some complex sonogram modifications.
  2. PixiTracker - a simple and fun tool to quickly create musical sketches, chip tunes and sound experiments. Without requiring a lot of musical knowledge!
  3. PixiVisor - a revolutionary tool for audio-visual experiments. It consists of two parts: Transmitter and Receiver. Transmitter converts the low-resolution video (stream from camera, static image or GIF animation) to sound in real time, pixel by pixel (progressive scan). So any image or animation can be transferred to the other devices through the sound. Receiver converts the sound (from microphone or Line-in input) back to video. You can set the color palette for this video, and record it to animated GIF file.
  4. Soul Resonance - audio-visual album.
  5. Micro Synths:
    • PixelWave - Experimental synth with old school pixel interface.
    • SpectrumGen is a bit like the PixelWave experimental synth, but now you can draw the spectrum of sound!
  6. Northern Forests and Dragon's Game videos - rendering program is written in Pixilang

Links

  1. Project Official Site
  2. Pixilang V3 Manual (ENG)
  3. Pixilang on Wikibooks - it's not as filled with content as the russian one but still contains some information
  4. Pixilang on Google Code