VectorFields
A native desktop app visualizing vector fields. A vector field basically just associates each point in a space with some vector. In this case, the vector represents the velocity of the given point. Or in other words, the app simulates and visualizes where each point would go if it followed said vector.
Each point's vector is computed via a function, that you can change yourself.
Demo
Disclaimer: The colors have changed by now, but I didn't bother to re-record yet. The functioning of the app is still the same as in the recording shown below.
Installing
There are pre-built binaries for Windows x86_64, which you can find in the release tab on the side. The app should also run on most other operating systems, but you will have to build it yourself then (see below for instructions).
Simply download and extract the zip file and run the VectorFields.exe
.
If you want to use the app as your screen-saver, you must follow the following steps:
- Download and extract the zip as usual. You can store the files wherever you want
- Rename
VectorFields.exe
toVectorFields.scr
- Right-Click on
VectorFields.scr
and clickinstall
. The app might start, but you can just close it. There should also be a window letting you decide after how many minutes you want the screen saver to appear. - You need to copy the
assets
folder toC:/Windows/System32
so Windows can find the correct font. Otherwise the font will look very weird. - Enjoy your screen-saver. You can interact with the app as usual. You exit the screen-saver by exiting the application (via Escape)
Building
To build the executable, you need both gcc
and make
installed and in your path.
After you downloaded the source code, simply navigate to its root folder and run build.bat
/build.sh
. You should then find the executable under bin/VectorFields
.
Alternatively you can also just run run.bat
/run.sh
to both build and run the executable.
All dependencies are packaged in the deps/
folder and are built along with the executable, so no prior setup should be required.
Dependencies
- raylib to draw shapes onto the screen in a cross-platform way
- ail for ui and common utilities that I wrote myself
Usage
To exit the application, press F4
or Escape
when the input box is not selected. After waiting 5 seconds, the input box will hide automatically and be deselected. You can also press Escape
or click somewhere else to deselect it.
When the input box is not selected, you can press F
to toggle fullscreen.
When the input box is not selected, you can press P
to make a screenshot. The screenshot will be stored in your current working directory (which usually should be the same folder that the executable is in).
By scrolling or by pinching in/out on your touchpad, you can zoom in/out of the Vector Field.
With Tab
you can automatically change to function to a random function.
You can also manually change the function, that is used to create the Vector Field. You will see it applied in real time.
Your function needs to be written in a paranthesized prefix notation (similar to Lisp).
The variables x
and y
correspond to the x- and y-coordinates of the points in the field. They are normalized to between -1 and 1, with (0, 0) being the center-point of the window.
The result needs to be a 2D vector (constructed with vec2
), which describes the direction by which the given point moves.
The length of the resulting vector influences the color with which it is drawn. The longer the vector, the more blue and saturated it becomes.
When changing the function, you have currently access to the following functions:
vec2
: Constructs a 2D vector. This should only be used as the outermost function+
: Adds as many operands as provided-
: Subtracts as many operands as provided from the first operand. If only one operand was provided, it negates said operand instead*
: Multiplies as many operands as provided/
: Divides as many operands as provided from the first operand. If only one operand was provided, it's multiplicative inverse is created instead%
: Calculates the remainder after dividing the second from the first operand**
: Raises the first operand by the power of the next operands. As of now,**
is treated like a left-associative operation instead of a right-associative one as usual in mathssin
: Takes one argument and computes the sine of that valuecos
: Takes one argument and computes the cosine of that valuetan
: Takes one argument and computes the tangent of that valuemax
: Takes the maximum of two argumentsmin
: Takes the minimum of two argumentsclamp
: Clamps the valuex
by the givenmin
andmax
values. Arguments should be provided in the following order:x min max
lerp
: Linearly interpolates betweenmin
andmax
by the valuet
. Arguments should be provided in the following order:t min max
sqrt
: Returns the square root of the argumentabs
: Returns the absolute value of the argumentlog
: Returns the natural logarithm of the argument
Further, you have access to the following variables:
x
: The point's x-coordinatey
: The point's y-coordinatexn
: The absolute value of the point's x-coordinateyn
: The absolute value of the point's y-coordinatee
: Euler's number epi
: Pi
Inspiration
I got the idea for this project after seeing the anvaka and LowByteProductions create similar projects (albeit for the web):
- anvaka's "Fieldplay": Website; Source
- LowByteProduction's "Flow-Fields": YouTube Video; Source