Logo Programming Sample Code

This article details the usage of the CSharpLogo program, which is a basic port of the iconic Logo programming language. The program compiles logo source code into an HTML file and uses SVG's to display the output.

Installation


Download or clone the CSharpLogo repository from https://github.com/syedhussim/CSharpLogo.git.

git clone https://github.com/syedhussim/CSharpLogo.git

Usage


The program accepts two command line arguments. The first argument is the full file path to the source code. The second argument is the path to the HTML output file.

dotnet run /path/to/source/code /path/to/output.html

Standard Commands


CommandDescription
homeReturn to the centre of the canvas.
penupInk on the canvas is turned off.
pendownInk on the canvas is turned on.
setpencolorSets the pen colour.
forwardMoves the cursor forward.
rightTurns right.
leftTurns left.
repeatControl flow function. Repeats code withing code block.

Extended Commands


CommandDescription
setcanvasSets the canvas width, height and background colour.
randpencolorSets a random pen color.
funcCreates a user defined function.

Examples



To draw a square use the FORWARD and LEFT commands as shown below.

Listing 1

FORWARD 100
LEFT 90
FORWARD 100
LEFT 90
FORWARD 100
LEFT 90
FORWARD 100

The REPEAT command is used to repeat a block of code. The code sample below shows how to draw a square by repeating the FORWARD and LEFT commands.

Listing 2

REPEAT 4 [
    FORWARD 100
    LEFT 90
]
Recent Articles