# Quickstart

### Installation

#### Releases

The latest releases of the Xylo binaries are available [here](https://github.com/giraffekey/xylo/releases/latest).

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

On Linux:

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

On macOS:

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

On Windows:

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

It should output the following:

```
xylo-lang 0.1.2
```

#### Cargo Install

You can install Xylo using Cargo:

```sh
cargo install xylo-lang
```

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

```bash
xylo-lang --version
```

It should output the following:

```
xylo-lang 0.1.2
```

#### Build From Source

To build from source, ensure you have [Git](https://git-scm.com/downloads) and the [Rust programming language](https://www.rust-lang.org/tools/install) installed.

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

```bash
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:

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

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

```bash
xylo --version
```

It should output the following:

```
xylo-lang 0.1.2
```

### 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:

```ocaml
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:

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

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

<figure><img src="https://2901200573-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEfsCB8gokBp1kZeqlrv2%2Fuploads%2FjlwE7kc1bGFPAQTsZGya%2Fflag-blank.webp?alt=media&#x26;token=984b5fc2-a11f-4648-bfda-68fdfc11c82e" alt=""><figcaption></figcaption></figure>

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.

```ocaml
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.

<figure><img src="https://2901200573-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEfsCB8gokBp1kZeqlrv2%2Fuploads%2FbKIO7lM08VLKq7Wm8rl2%2Fflag-small.webp?alt=media&#x26;token=982966cd-98e0-422c-a163-23d68811bfef" alt=""><figcaption></figcaption></figure>

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.

```ocaml
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.

```ocaml
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.

<figure><img src="https://2901200573-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEfsCB8gokBp1kZeqlrv2%2Fuploads%2Fs2mG9X6w0aBcpZQbGLKa%2Fflag-full.webp?alt=media&#x26;token=e0ca0a67-d827-44b3-95dc-cb632d69e3a7" alt=""><figcaption></figcaption></figure>

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