🎨
Xylo Docs
  • Introduction
  • Getting Started
    • Quickstart
  • Guides
    • Random Rotations
  • Syntax
    • Primitives
    • Functions
  • Control Flow
  • Builtin Functions
    • System
    • Math
    • Comparison
    • List
    • Randomness
    • Shape
    • Color
Powered by GitBook
On this page
  • Installation
  • Writing Code
Export as PDF
  1. Getting Started

Quickstart

Install the Xylo CLI and render an image of the Japanese flag

PreviousIntroductionNextRandom Rotations

Last updated 4 days ago

Installation

Releases

The latest releases of the Xylo binaries are available .

To ensure it is installed, check the version of the CLI in your command line.

On Linux:

cd [path]/[to]/[downloads]
./xylo_ubuntu --version

On macOS:

cd [path]/[to]/[downloads]
./xylo_macos --version

On Windows:

cd C:\[path]\[to]\[downloads]
xylo_windows.exe --version

It should output the following:

xylo-lang 0.1.0

Cargo Install

You can install Xylo using Cargo:

cargo install xylo-lang

To ensure it is installed, check the version of the CLI in your command line:

xylo-lang --version

It should output the following:

xylo-lang 0.1.0

Build From Source

When you have the required tool set, clone and build the repository:

git clone https://github.com/giraffekey/xylo
cd xylo
cargo build --release

This will build the Xylo CLI in the target directory.

If you're on Linux, you can copy the executable into your root /usr/bin folder for easy access:

sudo cp target/release/xylo-lang /usr/bin/xylo

To ensure it is installed, check the version of the CLI in your command line:

xylo --version

It should output the following:

xylo-lang 0.1.0

Writing Code

Xylo is a functional programming language. This means that it emphasizes the use of functions as the primary building blocks for constructing programs. It also means that all variables are immutable; once they are assigned, they cannot be changed.

The main function in a Xylo program is the root function. The purpose of the root function is to return a single shape or a list of shapes to be rendered to an image.

Let's get started with a simple piece of Xylo code:

root = FILL

This program renders a single FILL shape, which simply fills the entire image with the color white.

Save this code to a file named art.xylo. Then, use the following command to generate an image:

xylo generate art.xylo --width 600 --height 400

If all goes well, you should see a 600x400 image generated at art.png.

Looks good! But seems a bit empty.

Let's add a red circle to the center of the image. To do so, we can add a CIRCLE with a 50% lightness value. Shapes default to 100% lightness, which is always white, so if we want the circle to be visible we'll need to change its lightness with the l function.

root = FILL : l 0.5 CIRCLE

Here you can see that we used the : operator. This is called the compose operator and it can be used to compose two shapes together. In this case, we are combining the FILL shape with the CIRCLE shape.

Additionally, we are using the l function, which takes in two arguments. The first argument is a lightness value from 0 to 1. In this case we set it to 0.5, which means 50%. The second argument is the shape we are modifying the lightness of.

After running the generate command, you should see that art.png has changed.

If you look very, very closely, you should be able to see the circle. However, it's pretty small, isn't it?

Luckily, we can use the s function to scale the shape. All we need is an x and y value.

root = FILL : s 100 100 (l 0.5 CIRCLE)

The s function takes three arguments. The first and second arguments are scaling the circle by 100 pixels on the x and y axes respectively. The third argument takes in a shape; since the l function returns a shape, we can simply use its output.

There is a shorter way to write this code, however. Xylo also provides the sx function to scale only the x axis and the sy function to scale only the y axis. In our case, we want to scale both axes by the same value. We can use the ss function for this.

root = FILL : ss 100 (l 0.5 CIRCLE)

Let's run the generate command one last time. The image at art.png should now be similar to the Japanese flag.

Great! You're now on your way to becoming a creative coder with Xylo!

To build from source, ensure you have and the installed.

here
Git
Rust programming language