• Stars
    star
    1,328
  • Rank 35,391 (Top 0.7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Presentation-quality WebGL math graphing

MathBox

NPM Package Build Status License

Presentation-quality WebGL math graphing

MathBox

MathBox is a library for rendering presentation-quality math diagrams in a browser using WebGL. Built on top of Three.js and ShaderGraph it provides a clean API to visualize mathematical relationships and animate them declaratively.

For background, see the article series on Acko.net.

Presentations:

Demos:

And many more at https://mathbox.org.

Installation

You can install MathBox via npm for use with a bundler like Webpack, or include a global MathBox object onto your page by including the library via CDN.

NPM Package

  • Run the following in your project's directory to install MathBox and Three.js via npm:
npm install mathbox three

Import THREE and MathBox (library and stylesheet), along with a controls instance that you'll pass to the MathBox.mathBox constructor:

import "mathbox/mathbox.css"

import * as THREE from "three"
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"
import * as MathBox from "mathbox"

Install via CDN

Include the following in your HTML header to load all required libraries and styles:

<!-- Install your choice of three.js version from CDN: -->
<script
  type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"
></script>

<!-- Load a Controls instance, making sure that the version matches the Three.js version above: -->
<script
  type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js"
></script>

<!-- Install the latest MathBox, either mathbox.js or mathbos.min.js -->
<script
  type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/mathbox@latest/build/bundle/mathbox.js"
></script>

<!-- Include the MathBox CSS: -->
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/mathbox@latest/build/mathbox.css"
/>

Basic Usage

Construct a MathBox instance by passing initialization options to the mathBox() constructor:

const options = {
  controls: {
    // Orbit controls, i.e. Euler angles, with gimbal lock
    klass: THREE.OrbitControls
  },
};
const root = MathBox.mathBox(options);

Note See threestrap for all available options.

To spawn inside a specific element, pass an HTMLElement with the element option:

const element = document.querySelector("#my-thing");

const options = {
  element: element,
  controls: {
    klass: THREE.OrbitControls
  },
};
const root = MathBox.mathBox(options);

On initialization, mathBox returns a MathBox API object, wrapping the MathBox <root/>. Insert new MathBox nodes into the component tree by calling the method associated with the primitive you'd like to add.

Note See the Primitives doc for a description of all primitives and their properties.

The following code will set up a 3D Cartesian coordinate system with the specified range and scale for its x, y and z axes, and then insert an x and y axis into the scene:

const view = root
  .cartesian({
    range: [
      [-2, 2],
      [-1, 1],
      [-1, 1],
    ],
    scale: [2, 1, 1],
  })
  .axis({
    axis: 1,
  })
  .axis({
    axis: 2,
  });

Use your mouse to click and drag the camera's orientation, and zoom in and out:

2023-01-19 11 32 59

Each primitive call:

  • creates a new element
  • inserts it into the tree
  • returns a version of the API object with its selection focused on the new element.

Calling print() on some selection will print a representation to the console of the selection and any children. For example, view.print() prints the following:

<cartesian
  range={[
    [-2, 2],
    [-1, 1],
    [-1, 1],
  ]}
  scale={[2, 1, 1]}
>
  <axis axis={1} />
  <axis axis={2} />
</cartesian>

Select objects using .select() and a CSS-like selector to get a jQuery-like selection:

root.select("cartesian > axis");

Next, visit the Quick Start page for a more involved example that builds up an animating, interactive mathematical graph with labeled axes.

Docs & Help

For help, see the following resources:

For more involved questions, or just to say hi, please join us in the MathBox Google Group.

Related Projects

Who's using MathBox?

And the many demos listed on this thread of the MathBox Google group.

License

MIT License.

MathBox and ShaderGraph (c) Steven Wittens 2013-2023.

Libraries and 3rd party shaders (c) their respective authors.

More Repositories

1

TermKit

Experimental Terminal platform built on WebKit + node.js. Currently only for Mac and Windows, though the prototype works 90% in any WebKit browser.
JavaScript
4,433
star
2

MathBox.js

MathBox is a (work in progress) library for making presentation-quality math diagrams in WebGL.
JavaScript
1,942
star
3

shadergraph

Functional GLSL Linker
JavaScript
721
star
4

ThreeAudio.js

ThreeAudio helps you create music visualizations in Three.js or tQuery.
JavaScript
531
star
5

CSS3D.js

CSS 3D renderer for Three.js.
JavaScript
366
star
6

fullfrontal

MathBox-based conference talks
JavaScript
339
star
7

fuse10

Front-end for Acko.net 2013
JavaScript
246
star
8

threestrap

Minimal Three.js Bootstrapper
JavaScript
237
star
9

console-extras.js

Enhancements to the JavaScript console object.
JavaScript
127
star
10

NFSpace

Procedural planet generator
C
123
star
11

ShaderGraph.js

(deprecated) Library to build GLSL shaders out of reusable building blocks.
JavaScript
123
star
12

ThreeRTT.js

ThreeRTT helps you create advanced render-to-texture effects in Three.js.
JavaScript
73
star
13

NeverSeenTheSky

Source code for the WebGL demo Never Seen The Sky
JavaScript
53
star
14

iremotepipe

Command-line tool that streams button presses from Apple IR remotes on OS X.
Objective-C
48
star
15

imgui-wgpu-rs

Dear imgui renderer for wgpu-rs.
Rust
29
star
16

DarkSunrise

Music visualizer demo for Christmas Experiments 2013
JavaScript
26
star
17

ThreeBox.js

(dead) ThreeBox provides an improved boilerplate set up for tQuery / Three.js.
JavaScript
23
star
18

jsFsck

Makes Douglas Crockford cry and gives JavaScript debuggers nightmares.
JavaScript
21
star
19

headspace

TypeScript
12
star
20

pixelfactory

MathBox2-based talk about Pixels, MathBox and GPUs.
JavaScript
12
star
21

WikiTLDR

Chrome/Safari Extension. Reformats WikiLeaks cables for readability.
JavaScript
11
star
22

uncolorblind

Uncolor blindness goggles (Web / JS / GLSL)
JavaScript
11
star
23

vscode-headspace

Headspace audio VSCode plugin
JavaScript
4
star