Big Unicorn a simple programming language - --- Description of language --- Statement types --- Sample programs
Enter program:             

Program listing (display only - don't type in here!)

Description of language

Unicorn is a simple language for producing pretty effects!
All you need to use it is this webpage. If you want, you can save it onto your own computer (click on 'File', then 'Save As').
The program works within a grid of squares called the universe.
You can paint any square, move to another square, turn, test the colour of a square, and so on.

How to run a program

Enter program into the text box. (Try S2 M4 )

If you want to see an expanded listing and check for errors, click on 'Check code'. This isn't essential, since it's done automatically when you run the program, but it's a good idea. Correct any errors.

Click on 'Run program'. If it seems to be in an infinite loop, click on 'Stop program'.

If the program isn't working, change whatever is wrong in the text box, click on 'Run program' again. (This is called debugging.) If you can't see what's happening, click on 'Step program' instead. This does one instruction every time you click on it. The current line of the program is indicated and all variables get displayed.

Before running the program, you can paint squares directly into the universe. Click on the coloured square you want, then click in the universe. Then your program can use these squares. When you want to run the program, click on 'Run (no clear)' or 'Step (no clear)', or you will wipe out the squares you have just painted!

There is no way to save a program. But if you write a program you like, you can copy and paste it into a word processing document, or a Notepad text file, and save that. In fact, the programs are so short, you can even write them down on paper. Be careful not to make mistakes!

Syntax of language

A program is made up of statements. Each statement does something. A statement is usually 2 characters long and you type all the statements of a program into the text box, one after another, without using 'Enter'. It is very quick to type in a program!

Statement types

Detailed description of language for a longer explanation of what each instruction type does, with some examples.

AAdd 1Simple variableAdds 1 to variable defined by V.
BBegin loopcounterStarts loop counter at 1. Counter used by N or any statement needing a number.
CColourcolour numberSets colour used by P. Doesn't paint anything itself
DDirectiondirection numberD0 right, D1 down, D2 left, D3 up, D4-D7 diagonal. Doesn't change position
EElseno operandComes after I or R and gives alternative block of statements.
FFlood universecolour numberPaints whole universe same colour
GGonumber of squaresChanges position in current direction (without painting anything)
HHighest randomnumberThis limits the range of random numbers
IIf current square iscolour numberStatements dependent on this start with .
JJump to positionposition idJumps to position and direction set up by K
KKeep positionposition idRemembers current position and direction - this will be used by J
LLimitnumber of timesThis is the loop limit (B - N)
MMovenumber of squaresMoves current square along number of squares, shuffling the others back
NNextcounterAdd 1 to loop counter. If less than (L), return to start of loop defined by (B)
OOption slow runlength of timePuts a pause after each instruction so you can watch it working
PPaintnumber of squaresUses colour set by S.
QQuit programno operandQuits program at this point
colour numberQuits if current square is this colour
Rif Random number =numberStatements dependent on this start with .
SSquarecolour numberColours one square
TTurn clockwisenumber of right anglesChanges direction. Either turns D0-D3 or D4-D7
UUniverseoption number What happens if you go outside the universe
U0 (default) stops program
U1 will move onto opposite edge
U2 moves X to opposite edge and next Y
U3 returns to centre
U4 returns to centre and clears screen
U5 bounces off edge of universe
U6 moves X to start of line but invalid Y stops program
VSet VariablevariableSets variable to current square's colour. Used by A, Z or statement needing number
WWaitlength of timePuts a pause at this point so you can watch it working
XSet horizontal positionsquare numberChanges position - X0 is left-hand edge
YSet vertical positionsquare numberChanges position - Y0 is bottom edge
ZSet variable to ZerovariableSets variable to zero. Used by A, Z or statement needing number

Initial values

X4This is roughly the middle of the universe
Direction0Facing right
Colour6A blue square
Maximum random number9 
Universe option0Program stops if you go outside universe

Detailed description of language

Unicorn is a simple programming language which is designed to be used by children. You can produce interesting effects very quickly, and see exactly what is going on. All the action takes place in a 'universe' which is a grid of squares. The instruction format is very simple, so it is easy to type in a program without mistakes (see
syntax of language). It is also easy to run and test a program (see how to run a program). Here are the different instructions types, grouped together logically. Do not try to use all of them at once! Try them out one instruction type at a time, until you understand exactly what it does. You probably won't need most of them! If you want to try out any of the examples given below, either type them, or copy and paste them, into the program text box, and then click on 'Run program'.

Sample Programs

If you want to try out any of the programs given below, either type them, or copy and paste them, into the
program text box, and then click on 'Run program'. Try to figure out how they work. If you use 'Step program' and look at the cursor, the direction, the current colour and the values of the identifiers, this will help.

l4 b$ p t1 n$
c d0 x1 y p d3 x y1 p
b$ p$ t1 n$
Silly alien
s b$ m$ t1 n$
b% s? w7 n%
Patchwork Quilt
u2 l b% s? g1 w1 n%
u5 s m w2 d4 m
Random walk (Will it fall off the top or bottom of the universe?)
u6 h2 x0 s b$ w3 r1 .d4 e .d7 m1 n$
Multiplication table patterns
u2 l b$ f0 x0 y0 s9 g$ b& s$ l$ b* g1 i9 .s$ .w10 .n$ .q n* n&
Prime numbers (they're the stars)
u2 f x0 y c p x0 y0 k# c p2 j# l b$ g$ i .j# .n$ .q g$ b& s g$ i .j# .n$ .q w4 n&
Pretty patterns (click on 'Stop program' if you get bored with it)
x y l10000 b* i0 .c .t1 i .c .t3 i .c .t3 i .c0 .t1 p1 g1 w1 n*
Binary counter
d2 x k# b* b% i .s .g1 .n% s w7 j# n*
Binary adder (Generates two random numbers, then adds them)
d2 x y k# h2 l5 b% g1 k$ r? .s e .s d1 r? .c e .c g1 p1 g2 p1 j$ n% b* j# d2 g1 k# q0 i .n* d1 g3 i .s .n* s d2 b& g1 i .s .n& s n*
Group together (click on 'Stop program' if you get bored with it)
u2 x1 y0 d0 k# l b s? g1 n b! j# i0 .q v@ z* a* b$ g1 i@ .a* .n$ k& t2 m* i0 .n! j& n$
Sort (click on 'Stop program' if you get bored with it)
u2 x0 y0 d2 k\ g2 l b$ s? g1 n$ l9 b# c# j\ g1 k^ l999 b& j^ i# .t2 .b% .g1 .t2 .m1 .k\ .i0 ..n& .t2 .g1 .n% g1 i0 .n# .q k^ n&

My name is Jo Edkins - index to all my websites

© Jo Edkins 2004