Nivalis
Desmos-like function plotter using webasm
Install / Use
/learn @sxyu/NivalisREADME
Nivalis Plotter
A Desmos-like interactive function plotter in C++ supporting implicit functions and real-time critical point/intersection finding. Under the hood: features an expression parser, expression (AST) evaluator, symbolic differentiator and expression simplifier, which can be used directly through the shell.
-
Live online demo using WebAssembly: https://funcplot.com Mirror: https://www.ocf.berkeley.edu/~sxyu/plot/
-
Pre-built binaries for Windows 10 and Ubuntu 16/18 LTS (x86-64) in https://github.com/sxyu/nivalis/releases

Dependencies
- C++ 17
- Boost 1.58+ (Optional, only need math)
- OpenGL3
- and GLEW, glfw3, Dear ImGui which are included in repo
Installation
- I offer instructions for Ubuntu and Windows (since I only have access to these systems) and Webasm (through emscripten)
Ubuntu 16+
- Install CMake from https://cmake.org/download/
- If you already have an older version: I do not guarantee version <3.14 will work, but you may try
- Install a modern version of GCC which supports C++17 (GCC 7 will work)
- Install OpenGL3
sudo apt update && sudo apt install -y pkg-config mesa-common-dev freeglut3 freeglut3-dev
- For Readline functionality in Nivalis shell (like history), also install libreadline-dev
- Configure project with CMake:
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release- CMake options:
- To force disable Boost math add
-DUSE_BOOST_MATH=OFFto this command (some functions like digamma, beta will become unavailable) - To force using glfw3 in the repo (as opposed to the one you installed) use
-DUSE_SYSTEM_GLFW=OFF - To disable OpenGL/Dear ImGui and force using Nana, add
-DUSE_OPENGL_IMGUI=OFFto this command
- To force disable Boost math add
- Build project:
make -j8 - Optionally: install by
sudo make install
Windows 10
- Install CMake from https://cmake.org/download/
- Install Visual Studio 2017+, if not already present. I used 2017
- Configure project with CMake:
mkdir build && cd build && cmake .. -G"Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release- CMake options:
- To force disable Boost math add
-DUSE_BOOST_MATH=OFFto this command (some functions like digamma, beta will become unavailable) - To force using glfw3 in the repo (as opposed to the one you installed) use
-DUSE_SYSTEM_GLFW=OFF
- To force disable Boost math add
- Build project:
cmake --build . --config Release, or open the solution in VS and build in "Release" configuration manually
Emscripten (building on Ubuntu)
- Install emscripten 3.1.16. Support for later emscripten is not guaranteed. https://emscripten.org/docs/getting_started/downloads.html (replace latest with 3.1.16)
- Configure project with CMake:
cd build-emcc && emcmake cmake ..
- Build:
make -j8- Python3 is required
- jinja2 and css_html_js_minify are required for templating:
pip3 install jinja2 css_html_js_minify
- Host
build-emcc/out/on a server and open index in a browser.- Using Python 3: in build-emcc/out/, run:
python3 -m http.serverthen runfirefox localhost:8000
- Using Python 3: in build-emcc/out/, run:
- To deploy, simply upload all files in
build-emcc/outonto a server
Testing
- Tests are built by default. To disable, add
-DBUILD_TESTS=OFFto cmake command line - Linux:
make testto run tests (with ctest), or just manually run test/test_* - Alternatively, Windows/Linux:
ctestto run tests ctest --verboseto get more information (error line number etc.)
Usage
Plotter GUI
- Web app: https://www.ocf.berkeley.edu/~sxyu/plot/
- Alternitively, run the
./nivplotbinary to open GUI - Background window (plotter)
- Drag mouse (or arrow keys) to move, scroll (or
=/-) to zoom Ctrl/Altand=/-to zoom asymmetrically- Mouse over a marked point (minimum/maximum/intersection etc) to see label+coordinates
- Click any point on an explicit function to see the x-value and function value
- Drag mouse (or arrow keys) to move, scroll (or
- Function window (editor)
Eto edit function expressions (or click the textbox)- Function expressions can be:
- Functions parameterized by
xe.g.x^2ory=ln(x)orx^3=y. Syntax is same as in shel - Implicit function (less detail, no subpixel render):
e.g.
x=3orabs(x)=abs(y)orcos(x)=sin(y)orcos(x*y) = 0 - Inequalities (explicit/implicit): e.g.
x<y,cos(y)<sin(y),x^2>y - Parametric:
(<x-expr>, <y-expr>), where expressions should be in terms ofte.g.(4*sin(4*t), 3*sin(3*t)) - Polar:
r=<expr>, where<expr>should be in terms of anglete.g.r = 1-cos(t)-After entering a parametric/polar function, inputs will appear to allow adjusting bounds ont(you can directly set the value or drag t min, t max to change)- Polar inequalities are not currently supported due to limitations in current graphics engine
- Polylines: draws a series of points and lines e.g.
(5,1), or(1,1), (2,2), (a,b)- If size 1, e.g.
(1,2), it draws a single point - If size >1, e.g.
(1,2),(2,3), draws all points and connects them in order - If any point coordinate contains only a single variable, e.g.
(p,q), then the point can be dragged with your mouse to adjustp,q(note: this functionality is implemented in a super hacky way)
- If size 1, e.g.
- 2D Geometry Primitives
- Line/polygon:
%poly [polyline expression], e.g.%poly (0,0),(1,1),(2,0). Similar to polyline but closes the path automatically. - Rectangle:
%rect (ax, ay) (bx, by)e.g.%rect (0,0),(1,1) - Circle:
%circ radius @ (cenx, ceny) - Ellipse:
%ellipse (rx, ry) @ (cenx, ceny) - Filling: replace
%<command>with%f<command>to fill the primitive, for example%fpolyor%frect - Borderless filling: replace
%<command>with%F<command>to fill the primitive AND remove the border, for example%Fpolyor%Frect %circleis an alias for%circand%rectanglefor%rect
- Line/polygon:
- Text:
%text text-to-draw @ (posx, posy)e.g.%text hello world @ (0,0). The text will be center-aligned. Left/right whitespaces will be trimmed. - Inline function definition:
a = 3,f(x,y,z) = x+y+z,zz = a+b+cetc - Note if the left-hand-side has no parentheses, this defines a function with no arguments and not a variable; e.g.zz = ...is equivalent tozz() = .... This is more conventient in the plotter as it allows variables to depend on other variables. - Comment: any function starting with
#will be ignored - The expression syntax is standard and mostly Python-like. For details, see the next section (shell).
- Functions parameterized by
- Updates plot automatically
- Function expressions can be:
- Click
+ New functionto add a function. Click textbox to highlight functions. Alternatively, useUp/Downarrow keys in textbox to switch between functions or add a new one (by going beyond the bottomost existing function) - Click the x button to delete the current function
- Desktop only: Reference: Click the
? Helpbutton for a reference documenting functions/operators etc.- It is similar to this page
- Shell: Click the
Shellbutton to get a virtual shell popup; this is in the function editor in the desktop GUI, top navbar in the web app. See next section for usage. Some use cases,- Evaluate a function you entered at some point. For example,
if you entered
gamma(x)*digamma(x)in the textbox labelledf0, you can enterf0(5)in the shell to evaluategamma(5)*digamma(5) - Define custom functions to use in the function editor. For example,
define
sec(x) = 1/cos(x), or even a function with multiple arguments - Set variables manually, e.g.
C = 3.5 - Use the symbolic differentiation/expression simplification engine
% <expr>e.g.% diff(x)[x]
- Evaluate a function you entered at some point. For example,
if you entered
- View window: top right; in web app, click
Viewon top rightCtrl+Hor click the reset view button (home icon in web app) to reset the view to initial zoom, around origin- Modify the bounds numbers on the View window to change view (minx maxx miny maxy) manually
- Sliders window (attached below function window in web GUI)
- Click
+ New sliderto add slider - Once added, change first textbox to change variable to modify when moving slider
- Second/third boxes are lower/upper bounds for the slider
- Click x button to delete slider
- Click on slider below to change the variable value
- E.g. if variable is
a, you can writea*xin some function (in the Function window) and then drag the slider to see the function change smoothly
- Click
Shell
- Run
./nivalis- Or use the shell built into the desktop GUI/web app; see previous section
- Enter expressions to evaluate them
- Exponentiation is
^, other operators are standard:+-*/%- Note
*is required: e.g.2sin(0.5x)is not valid, you need to write2*sin(0.5*x)
- Note
- Comparison operators:
<,>,<=,>=,==/=(but=can mean assignment statement in shell; all mean equality/inequality in plotter) - Logical operators:
&,|for and/or (e.g.x<0 & x>-1)- Related functions:
not(_),xor(_, _)
- Related functions:
- Function call:
<func_name>(<arg>[, <arg>, ...]); a functionfwith no arguments can be called with eitherf()or justf.- Some mathematical functions available: `sqrt exp exp2 ln log10 log2 log sin cos tan asin acos atan sinh cosh tanh abs sgn max min floor ceil round fact gamma digamma t
- Exponentiation is
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
