Skip to content

Commit

Permalink
Release v1.3.0
Browse files Browse the repository at this point in the history
Added:
- comp.scl(comp, num)
- quat.scl(quat, num)
- plot.field(vec2field, scl, rgba, domain, origin, weight, res, context)
- plot.d2fdx2(func, scl, rgba, domain, origin, weight, res, context)
- geom.dist(p1, p2)
- geom.distsq(p1, p2)
- vec2.proj(vec2_1, vec2_2)
- vec2.oproj(vec2_1, vec2_2)
- vec2.fromPolar(vec2)
- vec2.fromBipolar(vec2)
- vec2.toPolar(vec2)
- vec2.toBipolar(vec2)
- vec2.field(p, q)
- vec2.fromField(vec2field, vec2)
- vec3.proj(vec3_1, vec3_2)
- vec3.oproj(vec3_1, vec3_2)
- vec3.fromCylindrical(vec3)
- vec3.fromSpherical(vec3)
- vec3.toCylindrical(vec3)
- vec3.toSpherical(vec3)
- vec3.field(p, q, r)
- vec3.fromField(vec3field, vec3)
- vec4.proj(vec4_1, vec4_2)
- vec4.oproj(vec4_1, vec4_2)
- vec4.fromHypercylindrical(vec4)
- vec4.fromHyperspherical(vec4)
- vec4.toHypercylindrical(vec4)
- vec4.toHyperspherical(vec4)
- vec4.field(p, q, r, s)
- vec4.fromField(vec4field, vec4)
- matr.rotater(rad, rady, radz)
- calc.d2fdx2(func, val)
- calc.tangent(func, val)
- calc.normal(func, val)
- calc.binormal(func, val)
- calc.dfdv(func, vec2_pos, vec2_dir)
- calc.dfrdt(func_1, func_2, val)
- calc.grad(funcORvecfield, vec)
- calc.grad2(funcORvecfield, vec)
- calc.div(vecfield, vec)
- calc.curl(vecfield, vec)
- calc.fxydxdy(func, a, b, c, d)
- calc.frdt(funcORvecfield, func, a, b)
- calc.fds(func, a, b, c, d)
- calc.fnds(vecfield, func, a, b, c, d)
- calc.curvature(func, val)

Removed:
- geom.dist2D(p1, p2)
- geom.dist3D(p1, p2)
- vec2.rotate2D(vec2, rad)
- vec3.rotatex(vec3, rad)
- vec3.rotatey(vec3, rad)
- vec3.rotatez(vec3, rad)
- matr.rotater2D(rad)
- matr.rotater3D(radx, rady, radz)

Changed:
- numb.Gaussian(height, mean, deviation)
- real.function(definition, type)
- real.val(func, val)
- real.sqrt(num)
- comp.magset(comp, num)
- quat.magset(quat, num)
- plot.xyplane(scl, rgba, origin, weight, context)
- plot.rOplane(scl, rgba, origin, weight, context)
- plot.function(func, scl, rgba, domain, origin, weight, context)
- plot.comp(comp, scl, rgba, origin, weight, context)
- plot.vec2(vec2, scl, rgba, origin, weight, context)
- plot.field(vec2field, scl, rgba, domain, origin, weight, res, context)
- plot.vec3(vec3, scl, rgba, origin, weight, context)
- plot.matr(matr, scl, rgba, origin, weight, context)
- plot.dfdx(func, scl, rgba, domain, origin, weight, res, context)
- plot.fxdx(func, scl, rgba, domain, origin, weight, res, context)
- plot.convolution(func_1, func_2, scl, rgba, domain, origin, weight, res, context)
- plot.correlation(func_1, func_2, scl, rgba, domain, origin, weight, res, context)
- plot.autocorrelation(func, scl, rgba, domain, origin, weight, res, context)
- plot.Laplace(func, scl, rgba, domain, origin, weight, res, context)
- plot.Fourier(func, scl, rgba, domain, origin, weight, res, context)
- stat.mean(arr, type)
- vec2.magset(vec2, num)
- vec3.magset(vec3, num)
- vec4.magset(vec4, num)
- matr.invert(matr)
- matr.toVector(matr, vec, type, rowORcol)
- calc.dfdx(func, val)
- calc.fxdx(func, a, b)
- calc.mean(func, a, b)
  • Loading branch information
Zushah committed Dec 4, 2023
1 parent 38e62cd commit 1f209bb
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 65 deletions.
102 changes: 57 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
<p align="center"><a href="https://www.github.com/Zushah/Chalkboard"><img src="./src/logo.png" width="50%"></a></p>
<p align="center">
<a href="https://www.github.com/Zushah/Chalkboard/releases/tag/v1.2.0"><img src="https://img.shields.io/github/v/release/Zushah/Chalkboard" alt="Latest release"></a>
<a href="https://www.github.com/Zushah/Chalkboard/commits"><img src="https://img.shields.io/github/last-commit/Zushah/Chalkboard" alt="Last commit"></a>
<a href="https://www.jsdelivr.com/package/gh/Zushah/Chalkboard?path=build"><img src="https://data.jsdelivr.com/v1/package/gh/Zushah/Chalkboard/badge" alt="jsDelivr traffic"></a>
<a href="https://www.github.com/Zushah/Chalkboard/releases/tag/v1.3.0" target="_blank"><img src="https://img.shields.io/github/v/release/Zushah/Chalkboard" alt="Latest release"></a>
<a href="https://www.codefactor.io/repository/github/zushah/chalkboard" target="_blank"><img src="https://www.codefactor.io/repository/github/zushah/chalkboard/badge" alt="CodeFactor grade"></a>
<a href="https://www.github.com/Zushah/Chalkboard/commits" target="_blank"><img src="https://img.shields.io/github/last-commit/Zushah/Chalkboard" alt="Last commit"></a>
<a href="https://github.com/Zushah/Chalkboard/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/badge/license-MIT-yellow" alt="Minified size"></a>
<a href="https://www.jsdelivr.com/package/gh/Zushah/Chalkboard?path=build" target="_blank"><img src="https://data.jsdelivr.com/v1/package/gh/Zushah/Chalkboard/badge" alt="JSDelivr traffic"></a>
<br>
<a href="https://zushah.github.io/Chalkboard/home.html">https://zushah.github.io/Chalkboard/home.html</a>
<a href="https://zushah.github.io/Chalkboard/home.html" target="_blank">https://zushah.github.io/Chalkboard/home.html</a>
</p>

# Contents
<ol>
<li><a href="#about">About</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#documentation">Documentation</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#getting-started">Getting Started</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#license">License</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
<li><a href="#contact">Contact</a></li>
</ol>

# About
The Chalkboard library is a JavaScript namespace that provides a plethora of both practical and abstract mathematical functionalities for its user. It was created by [Zushah](https://www.github.com/Zushah) during 2022 and 2023. As of [version 1.2.0](https://www.github.com/Zushah/Chalkboard/releases/tag/v1.2.0), Chalkboard has 342 different commands. The library is not only available for standard JavaScript but also for [Proccesing.js](https://www.processing.org/) (compatible with [Khan Academy](https://www.khanacademy.org/cs/chalkboard/6708642430369792)), as well. Chalkboard's website can be visited [here](https://zushah.github.io/Chalkboard/home.html).
The Chalkboard library is a JavaScript namespace that provides a plethora of both practical and abstract mathematical functionalities for its user. It was developed by [Zushah](https://www.github.com/Zushah) during 2022 and 2023 and then [released](https://github.com/Zushah/Chalkboard/releases/tag/v1.0.0) on November 6, 2023. As per the latest release of [v1.3.0](https://www.github.com/Zushah/Chalkboard/releases/tag/v1.3.0), Chalkboard has 380 different commands. The library is available for regular JavaScript as well as [Proccesing.js](https://www.processing.org/) (fully compatible with [Khan Academy](https://www.khanacademy.org/cs/chalkboard/6708642430369792)). Chalkboard's website can be visited [here](https://zushah.github.io/Chalkboard/home.html).

# Installation
If your JavaScript project is being run within an HTML webpage, you can import the latest version of the Chalkboard library into it with this line:
```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/Zushah/Chalkboard@1.2.0/src/Chalkboard.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/Zushah/Chalkboard@1.3.0/src/Chalkboard.min.js"></script>
```
Alternatively, you can simply download the [latest release](https://www.github.com/Zushah/Chalkboard/releases/tag/v1.2.0) and put the relevant files in your project's directory.
Alternatively, you can simply download the [latest release](https://www.github.com/Zushah/Chalkboard/releases/tag/v1.3.0) and put the relevant files in your project's directory.

More methods and details about installing Chalkboard can be read [here](https://zushah.github.io/Chalkboard/installation.html).

# Documentation
These are all thirteen Chalkboard categories with a brief description of what they're mostly about, listed in the order they appear in the source code:
These are all thirteen Chalkboard categories with a brief description of what they're mostly about, and listed in the order they appear in the source code:
- `numb` - Number-theory-related operations
- `real` - Real-valued operations and functions
- `comp` - Complex numbers and their operations
- `quat` - Quaternions and their operations
- `plot` - Plotting real-valued functions
- `geom` - Geometric operations
- `trig` - All 24 trigonometric functions
- `stat` - Statistical operations
- `vec2` - Two-dimensional vectors and their operations
- `vec3` - Three-dimensional vectors and their operations
- `vec4` - Four-dimensional vectors and their operations
- `matr` - Several-dimensional matrices and their operations
- `calc` - Calculus and advanced mathematical operations in general
- `real` - Real-valued function operations
- `comp` - Complex number operations
- `quat` - Quaternion operations
- `plot` - Plotting functions and function operations
- `geom` - Geometric formulae operations
- `trig` - Trigonometric function operations
- `stat` - Statistical array operations
- `vec2` - Two-dimensional vector operations
- `vec3` - Three-dimensional vector operations
- `vec4` - Four-dimensional vector operations
- `matr` - Multidimensional matrix operations
- `calc` - Single- and multi-variable calculus operations

There are also four "global" commands in Chalkboard, which are:
- `README()` - Prints basic information about Chalkboard in the console
- `LOGO()` - Draws the Chalkboard logo
- `PI()` - Computes pi
- `E()` - Computes e
- `PI()` - Computes the number pi
- `E()` - Computes the number e

The comprehensive Chalkboard documentation can be visited [here](https://zushah.github.io/Chalkboard/documentation.html).

# Example
Every Chalkboard command first starts with typing "Chalkboard" followed by a period, then the name of the category of the command (all categories are listed above in the [documentation](#documentation) section) with another period, and lastly the desired command itself.
# Getting Started
After installing Chalkboard into your program, you can immediately get started with using it. Every Chalkboard command begins with typing "Chalkboard" followed by a period, then the name of the category of the command (all categories are listed above in the [documentation](#documentation) section) with another period, and lastly the desired command itself.
```js
Chalkboard.category.command(params);
```
Expand All @@ -64,46 +66,56 @@ Here is some code that shows off only a few basic features of Chalkboard:
const cb = Chalkboard; // Chalkboard is a nice name but it's also long

let f = cb.real.function("Math.cos(2 * x)"); // f(x) = cos(2x)
let Ff = cb.calc.Fourier(f, 2); // The Fourier transform of f at x = 2
let dfdx = cb.calc.dfdx(f, 2); // Derivative of f at x = 0
let fxdx = cb.calc.fxdx(f, 0, 2); // Antiderivative of f from x = 0 to x = 2
let fourier = cb.calc.Fourier(f, 2); // Fourier transform of f at x = 2

let f = cb.vec3.field("x", "y", "z"); // f(x, y, z) = (x, y, z)
let r = cb.real.function(["Math.cos(s) * Math.cos(t)", "Math.sin(s) * Math.cos(t)", "Math.sin(t)"], "surf"); // r(s, t) = (cos(s)cos(t), sin(s)cos(t), sin(t))
let fnds = cb.calc.fnds(f, r, cb.PI(-1/2), cb.PI(1/2), 0, cb.PI(2)); // Flux of the radial vector field through the unit sphere

let primes = cb.numb.primeArr(0, 100); // Array of prime numbers between 0 and 100
let midPrime = cb.stat.median(primes); // Median number in the primes array

let z = cb.comp.new(1, 1); // z = 1 + i
let zsqsqrt = cb.comp.sqrt(cb.comp.sq(z)); // sqrt(z^2) = z

let r = cb.real.function(["Math.cos(t)", "Math.sin(t)"], "para"); // r(t) = (cos(t), sin(t))
let r = cb.real.function(["Math.cos(t)", "Math.sin(t)"], "curv"); // r(t) = (cos(t), sin(t))
cb.plot.xyplane(2); // Draws the Cartesian coordinate plane
cb.plot.function(r, 2, [0, cb.PI(1/2)]); // Draws r(t) from t = 0 to t = π/2
cb.plot.function(r, 2, [0, cb.PI(1/2)]); // Plots r(t) from t = 0 to t = π/2

let a = cb.vec3.new(1, 2, 3); // Vector a = (1, 2, 3)
let b = cb.vec3.new(4, 5, 6); // Vector b = (4, 5, 6)
let c = cb.vec3.new(7, 8, 9); // Vector c = (7, 8, 9)
let axbxc = cb.vec3.vectorTriple(a, b, c); // Triple cross product between a, b, and c
cb.vec3.print(axbxc); // Prints the vector axbxc in the console

let A = cb.matr.new([0, 1, 1], // A is a 3x3 matrix
[1, 0, 1],
[1, 1, 0]);
let Ai = cb.matr.invert(A); // Ai is the inverse of A
let AAi = cb.matr.mul(A, Ai); // AAi is the product of A and Ai
cb.matr.print(AAi); // Prints AAi in the console
cb.vec3.print(axbxc); // Prints axbxc in the console

let m = cb.matr.new([0, 1, 1, 1, 1], // m is a 5x5 matrix
[1, 0, 1, 1, 1],
[1, 1, 0, 1, 1],
[1, 1, 1, 0, 1],
[1, 1, 1, 1, 0]);
let mi = cb.matr.invert(m); // mi is the inverse of m
let mmi = cb.matr.mul(m, mi); // mmi is the product of m and mi
cb.matr.print(mmi); // Prints mmi in the console
```
More examples that are more interesting can be viewed [here](https://zushah.github.io/Chalkboard/examples.html).
More examples (which are more interesting) can be seen [here](https://zushah.github.io/Chalkboard/examples.html) with their source code [here](https://github.com/Zushah/Chalkboard/tree/main/examples).

# Contributing
<ol>
<li>Clone Chalkboard's GitHub repository onto your PC.</li>
<li>Pull the latest code from the repository and make a new branch based on the main branch. It is recommended to use a Git client such as GitHub Desktop.</li>
<li>Find the folder on your PC where the repository has been cloned to and make your contributions.</li>
<li>Clone or fork Chalkboard's GitHub repository.</li>
<li>If you cloned the repository, pull the latest code and make a new branch based on the main branch. If you forked it, then just make sure it's based on the main branch.</li>
<li>Make your contributions to your branch or fork.</li>
<li>If you're adding new features or modifying the functionalities of old ones, please make sure you do the same for both editions (JavaScript and Processing.js) of the library.</li>
<li>When you're done, commit the changes to your branch with a detailed description.</li>
<li>Publish your branch to GitHub.</li>
<li>When you're done, commit the changes to your branch or fork with a detailed description.</li>
<li>Publish your branch or fork to GitHub.</li>
<li>Open a pull request. It will be reviewed soon and then merged to the main branch.</li>
</ol>

# License
The Chalkboard library is available under the [MIT License](https://www.opensource.org/license/mit/).
The Chalkboard library is available under the [MIT License](https://www.opensource.org/license/mit/) which can be viewed [here](https://github.com/Zushah/Chalkboard/blob/main/LICENSE).

# Acknowledgements
Thanks to [Bhavjit Chauhan](https://github.com/bhavjitChauhan) for his [contribution](https://github.com/Zushah/Chalkboard/commit/d3f0a82f0c2b1351f391908ef2d6f78403881259) to [v1.3.0](https://www.github.com/Zushah/Chalkboard/releases/tag/v1.3.0).

# Contact
[GitHub](https://www.github.com/Zushah)\
Expand Down
81 changes: 81 additions & 0 deletions examples/fluid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
The Chalkboard Library ===> https://www.github.com/Zushah/Chalkboard
Version 1.3.0 Example Program: Fluid Flow
Authored by Zushah ===> https://www.github.com/Zushah
*/

// Get the JavaScript Canvas API
var ctx = document.getElementById("canvas").getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

var cb = Chalkboard; // Initialize Chalkboard as cb

// Vector field adapted from "Learning about Hamiltonian Monte Carlo" by @betanalpha and @rlmcelreath which can be found here: https://github.com/anvaka/fieldplay/blob/main/Awesome%20Fields.md
// Vector field defined as F(x, y) = (-y, -x/(1 + x^2)^2)
var F = cb.vec2.field("y", "-x / ((1 + x * x) * (1 + x * x))");

// Basic particle system to simulate the fluid flow
class Particle {
constructor() {
this.pos = cb.vec2.new(cb.numb.random(-canvas.width / 2, canvas.width / 2), cb.numb.random(-canvas.height / 2, canvas.height / 2)); // Position vector
this.vel = cb.vec2.new(0, 0); // Velocity vector
this.ppos = this.pos; // Previous position vector
}
update() {
// Update the particle's position and velocity
this.vel = cb.vec2.magset(cb.vec2.fromField(F, cb.vec2.scl(this.pos, 1/100)), 5); // Velocity direction depends on the (scaled) vector field, velocity magnitude is set to always be 10
this.pos = cb.vec2.add(this.pos, this.vel); // Velocity is added to the position
}
constrain() {
// Constrain the particle position within the canvas
// The canvas coordinates are within -width/-height and width/height so that the Cartestian point (0, 0) is in the center of the canvas
if(this.pos.x > canvas.width / 2) {
this.pos.x = -canvas.width / 2;
this.ppos = this.pos;
}
if(this.pos.x < -canvas.width / 2) {
this.pos.x = canvas.width / 2;
this.ppos = this.pos;
}
if(this.pos.y > canvas.height / 2) {
this.pos.y = -canvas.height / 2;
this.ppos = this.pos;
}
if(this.pos.y < -canvas.height / 2) {
this.pos.y = canvas.height / 2;
this.ppos = this.pos;
}
}
draw() {
// Draw the particle
ctx.strokeStyle = "rgba(0, 0, 255, 0.1)";
ctx.lineWidth = 1;
ctx.save();
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.beginPath();
ctx.moveTo(this.pos.x, this.pos.y)
ctx.lineTo(this.ppos.x, this.ppos.y);
ctx.stroke();
ctx.restore();
this.ppos = this.pos;
this.update();
this.constrain();
}
}
// Create 500 particles in the particles array
var particles = [];
for(var i = 0; i < 500; i++) {
particles.push(new Particle());
}

// Draw everything
ctx.fillStyle = "rgb(0, 0, 0)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
function main() {
for(var i = 0; i < particles.length; i++) {
particles[i].draw();
}
window.requestAnimationFrame(main);
}
window.requestAnimationFrame(main);
4 changes: 2 additions & 2 deletions examples/hyperbolics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
The Chalkboard Library ===> https://www.github.com/Zushah/Chalkboard
Version 1.2.0 Example Program: Hyperbolic Functions
Version 1.3.0 Example Program: Hyperbolic Functions
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand All @@ -18,7 +18,7 @@ function main() {
cb.plot.xyplane(1, [0, 0, 0], [canvas.width / 2, canvas.height / 2], 2);

// Plot the unit hyperbola with a parametric function (see: https://en.wikipedia.org/wiki/Hyperbola)
var f = cb.real.function(["(t * t + 1) / (2 * t)", "(t * t - 1) / (2 * t)"], "para");
var f = cb.real.function(["(t * t + 1) / (2 * t)", "(t * t - 1) / (2 * t)"], "curv");
cb.plot.function(f, 1, [100, 100, 255], [0, 10], [canvas.width / 2, canvas.height / 2], 4);
cb.plot.function(f, 1, [100, 100, 255], [-10, 0], [canvas.width / 2, canvas.height / 2], 4);

Expand Down
2 changes: 1 addition & 1 deletion examples/mandelbrot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
The Chalkboard Library ===> https://www.github.com/Zushah/Chalkboard
Version 1.2.0 Example Program: Mandelbrot Set
Version 1.3.0 Example Program: Mandelbrot Set
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand Down
4 changes: 2 additions & 2 deletions examples/matr-donut.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
The Chalkboard Library ===> https://www.github.com/Zushah/Chalkboard
Version 1.2.0 Example Program: Matrix Donut
Version 1.3.0 Example Program: Matrix Donut
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand Down Expand Up @@ -39,7 +39,7 @@ function main() {
ctx.restore();

// Make the donut rotate with a rotation matrix
var r = cb.matr.rotater3D(cb.trig.toRad(1), cb.trig.toRad(1), cb.trig.toRad(1));
var r = cb.matr.rotater(cb.trig.toRad(1), cb.trig.toRad(1), cb.trig.toRad(1));
for(var i = 0; i < points.length; i++) {
var buffer = cb.vec3.toMatrix(points[i]); // Create a buffer matrix which has the donut's points
var rbuffer = cb.matr.mul(r, buffer); // Multiply the rotation matrix with the buffer matrix
Expand Down
2 changes: 1 addition & 1 deletion examples/newton.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
The Chalkboard Library ===> https://www.github.com/Zushah/Chalkboard
Version 1.2.0 Example Program: Newton's Method
Version 1.3.0 Example Program: Newton's Method
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand Down
4 changes: 2 additions & 2 deletions examples/quat-donut.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
The Chalkboard Library ===> https://www.github.com/Zushah/Chalkboard
Version 1.2.0 Example Program: Quaternion Donut
Version 1.3.0 Example Program: Quaternion Donut
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand All @@ -27,7 +27,7 @@ function main() {
ctx.fillRect(0, 0, canvas.width, canvas.height);

// Make the donut rotate with a rotation quaternion
var r = cb.quat.fromAxis(cb.vec3.new(1, 1, 1), theta);
var r = cb.quat.fromAxis(cb.vec3.normalize(cb.vec3.new(1, 1, 1)), theta);
var qoints = []; // We'll say that "qoints" are the new rotated points
for(var i = 0; i < points.length; i++) {
qoints.push(cb.quat.toRotation(r, points[i]));
Expand Down

0 comments on commit 1f209bb

Please sign in to comment.