Quickstart
Install the Xylo CLI and render an image of the Japanese flag
Last updated
Install the Xylo CLI and render an image of the Japanese flag
Last updated
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:
On macOS:
On Windows:
It should output the following:
You can install Xylo using Cargo:
To ensure it is installed, check the version of the CLI in your command line:
It should output the following:
When you have the required tool set, clone and build the repository:
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:
To ensure it is installed, check the version of the CLI in your command line:
It should output the following:
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:
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:
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.
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.
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.
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.