Brush Ninja Help

Free Digital Creativity

← Help Code Ninja

2d Code Commands

Code Ninja is inspired by the Logo programming language. However, where Logo was inspired by the Lisp language Code Ninja is inspired by Javascript. Whilst not the same it has similarities with Javascript that should make a future transition easier.

How it works

The programming language moves a pointer around the drawing image drawing lines wherever it travels. The cursor carries a fictional pen that draws the path. This pen can be raised and lowered so that you can move without drawing. There are simple programming commands such as repeat that allow you to run the same commands multiple times. Since the commands repeat from the point where the previous command ended you can use this to draw repeating patterns.


  • The commands can be written in CAPITAL letters or lowercase letters.
  • They can be on one line or on multiple lines.
  • Code indentation can be whatever you like. The editor will automatically format as best it can.
  • Commands that use custom colours can use any valid CSS/ HTML colour.
  • You can add comments by adding // before the text you want to comment. This can be used to add headings to your code, or explain what you are doing. This makes the code easier to understand.
  • You can use indents and new lines to group related elements making it easier to move around the code.


Many commands have a short and a long version. This makes them a bit quicker to type. You can use whichever version you prefer.

fd X, forward X

Move forward X pixels.

fd 10

bk X, back X, backward X

Move backwards X pixels.

bk 10

rt A, right A

Turn right A degrees.

rt 90

lt A, left A

Turn left A degrees.

lt 90

seta A, setangle A

Set the angle to A degrees.

seta 180

color C, colour C

Change the colour to C. C can be any valid CSS colour using colour names or hexadecimal notation.

color red

colorrand, colourrand

Pick a random colour to draw with.


setbg C

Set the background colour of the drawing. This can be done at any time, whenever you like.

setbg green

width X, setwidth X

Set the width of the drawing line to X pixels.

setwidth 4


Fill the current space with the current colour.


pu, penup

Lift the pen so that you can move the cursor without drawing anything.


pd, pendown

Lower the pen so that you can draw lines as you move around the board.



Go to the center of the image. This is the same location that you start from. This also resets the angle.


setxy X Y, position X Y

Set the x and y location of the cursor.

setxy 10 10

setx X

Set the x position of the cursor.

setx 30

sety Y

Set the y position of the cursor.

sety 140


Hide the triangle cursor on the screen.



Show the triangle cursor on the screen.



Comments are really useful features in programming that allow you to add notes about what you are doing. You can do this in Code Ninja by adding // at the start of the line that you want to be a comment. Everything after the line will be ignored. You can also add a comment after some code.

// This is a comment.
fd 10 // This is also a comment.

Comments can be used for:

  • Adding notes about code.
  • Adding headings to code to make it clearer what is happening.
  • Temporarily removing code to see what happens in different situations.

Random Numbers

To add a bit of randomness we have the ‘rand’ keyword. The rand keyword will pick a random whole number for you. You can control the range of this random number by giving it one or two parameters.

  • rand I: This will pick a random number between 0 and I, where I is any whole number.
  • rand I J: This will pick a random number between I and J inclusive, where both I and J are any whole number.

By default random numbers will be the same each time you run the code. If you want the numbers to be different each time then you should also add the randomize command somewhere.


You can repeat a set of commands a set amount of times. The commands withing the repeat block can also contain repeat blocks. They can also call custom functions.

// Draw a box.
repeat 4 {
	forward 10
	right 90

You can also nest repeat loops inside other repeat loops.

width 2
repeat 30 {
	forward 20 right 12
	repeat 12 {
		forward 10 right 30

Custom Functions

You can group chunks of code as custom functions. These can then be called at any time by writing the name of the function followed by opening and closing brackets.

function randomBox {
	setxy rand 0 512 rand 0 512
	repeat 4 {
		forward 50 right 90
// Draw 50 randomly positioned boxes
repeat 50 {

To make the above example even more random we can randomize the width of the line, the angle of the boxes, and colour of the boxes.

function randomBox {
	seta rand 0 90
	width rand 1 15
	setxy rand 0 512 rand 0 512
	repeat 4 {
		forward 50 right 90
// Draw 50 randomly positioned boxes
repeat 50 {


  • If you are going to fill a shape then lift the pen and move to an empty space before filling, else part of the line will be filled instead.
  • The random colours are designed to be ‘nice’ they will be quite bold and bright and shy away from grey/ dreary colours.
  • Repeat loops can be nested, one inside the other.
  • Functions can be placed anywhere in the code.