Categorygithub.com/willowiscool/vsf
repositorypackage
1.0.0
Repository: https://github.com/willowiscool/vsf.git
Documentation: pkg.go.dev

# README

VSF

A program to visualize sorting algorithms written in Lua

VSF Circle GIF

Installation

First, make sure you have all of the dependencies listed here. Next, just run go get -u github.com/vityavv/vsf to install it.

Usage

Basic Command Line Usage

Run vsf with the vsf command: vsf <lua file> [config file]

There are a few example lua files in the sorts directory and an example config file called defaults.json. The config file is optional.

Config File

The config file is a JSON file. You can see an example of this in the defaults.json file. Here are the keys and their meanings:

KeyMeaningDefault
list_lengthThe length of the list to be sorted500
block_widthThe width of each displayed block2
block_height_multThe amount each block's height is multiplied by when displayed*1
showerThe shower to use. See belowrect
sleepHow long to sleep before showing something, in milliseconds10
bgAn array of four values from 0-255, representing the RGBA color of the background[0, 0, 0, 255]
fgThe foreground color (color of the blocks), in the same manner[255, 255, 255, 255]
changedThe color that changed blocks are shown[255, 0, 0, 255]
rainbowWhether to use a rainbow or not. If true, bg, fg, and changed are ignoredfalse
vsyncWhether to use VSync or notfalse
fpsfilterHow many frames to use when calculating FPS. If you're unsure, the default should be fine30

*: block_height_mult is actually a float and not an int, but you should only use values less than one if you use shell or circle as your shower (see below)

Writing Sorts

Sorts are written in Lua. You must have a function called sort, which takes an array (table) as its argument. That function will be called with the random list at the start. You must then call the function show whenever you make a change in that array. The show function takes an array of the same length as the original. Check the sorts folder for examples.

Showers

Here is a list of showers and their respective special settings:

ShowerNotes
rectThe default shower. Refer to the descriptions of the keys above
pointRefer to the descriptions of the keys above
shellUses block_heigh_mult to determine the width of the shell; ignores block_width
circleSame as shell, but for this mode it is recommended to set rainbow to true
hoopsSame as cricle, including the rainbow part
blockSame as rect, but you should use rainbow for this one too