Skip to content

Commit

Permalink
Release v2.0.0
Browse files Browse the repository at this point in the history
Added:
- APPLY(object, callback)
- vect: { ... }
- VERSION
- VERSIONALIAS

Removed:
- ChalkboardProcessing.js
- plot.vec3(vec3, config)
- quat.fromVector(vec3)
- vec2: { ... }
- vec3: { ... }
- vec4: { ... }

Changed:
- Rewrote everything with TypeScript, applied ESLint and Prettier, and remade the website with TypeDoc, so basically everything has been changed
- comp.define(realDefinition, imagDefinition)
- comp.init(a, b)
- LOGO(x, y, s, context)
- matr.init(matrix)
- matr.mulVector(matr, vect)
- plot.definition(func, config)
- quat.init(a, b, c, d)
- real.define(definition, type)
- tens.init(tensor)
- vect.init(x, y, z, w)
  • Loading branch information
Zushah committed Jan 8, 2024
1 parent 521e790 commit 5950134
Show file tree
Hide file tree
Showing 36 changed files with 7,780 additions and 4,588 deletions.
17 changes: 17 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/indent": ["error", 4],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/prefer-as-const": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-types": "off",
"no-self-assign": "off",
"no-prototype-builtins": "off",
"no-var": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parser": "typescript",
"printWidth": 200,
"tabWidth": 4,
"singleQuote": false,
"trailingComma": "none"
}
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# Chalkboard changelog
All notable changes of every update of the Chalkboard library are recorded in this file.

## [v2.0.0 al-Khwarizmi](https://www.github.com/Zushah/Chalkboard/releases/tag/v2.0.0) - 01/08/2024
The tenth release of the Chalkboard library.
Commits: [`v1.7.0...v2.0.0`](https://www.github.com/Zushah/Chalkboard/compare/v1.7.0...v2.0.0)
- Rewrote everything in TypeScript, applied ESLint and Prettier, and remade the website with TypeDoc
- Added `APPLY` which applies a callback function in an element-wise manner on a complex number, matrix, quaternion, tensor, or vector
- Added the `vect` category which merges the `vec2`, `vec3`, and `vec4` categories into one
- Added `VERSION` and `VERSIONALIAS` which return the installed version and its alias, respectively
- Removed the `vec2`, `vec3`, and `vec4` categories
- Removed `quat.fromVector` because it's been replaced by `vect.toQuaternion`
- Removed `plot.vec3` because it was weird
- Changed everything due to the TypeScript rewrite and the vector categories merge
- Changed all of the `.new` commands to be renamed as `.init`
- Changed `real.function` to be renamed as `real.define`, `comp.function` to be renamed as `comp.define`, and `plot.function` to be renamed as `plot.definition`
- Changed `LOGO` to draw the logo as a circle instead of a square
- Changed `matr.mulvec` to be renamed as `matr.mulVector`
- Fixed `matr.mulVector`` which didn't work when the rows of the matrix equaled the dimension of the vector
- Discontinued the Processsing.js edition of the library, meaning it will no longer be updated and it will only be available on the Khan Academy release (it will no longer be available on GitHub)

## [v1.7.0 Descartes](https://www.github.com/Zushah/Chalkboard/releases/tag/v1.7.0) - 01/01/2024
The ninth release of the Chalkboard library.
Commits: [`v1.6.0...v1.7.0`](https://www.github.com/Zushah/Chalkboard/compare/v1.6.0...v1.7.0)
Expand Down
135 changes: 81 additions & 54 deletions README.md

Large diffs are not rendered by default.

Binary file modified assets/Chalkboard-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
656 changes: 656 additions & 0 deletions dist/Chalkboard.d.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/Chalkboard.d.ts.map

Large diffs are not rendered by default.

4,997 changes: 4,997 additions & 0 deletions dist/Chalkboard.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/Chalkboard.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Chalkboard documentation
The documentation for [Chalkboard v1.7.0 Descartes](https://www.github.com/Zushah/Chalkboard/releases/tag/v1.7.0) can be visited [here](https://zushah.github.io/Chalkboard/documentation.html/). Its source code is located [here](https://www.github.com/Zushah/zushah.github.io/blob/main/Chalkboard/documentation.html).
The documentation for [Chalkboard v2.0.0 al-Khwarizmi](https://www.github.com/Zushah/Chalkboard/releases/tag/v2.0.0) can be visited [here](https://zushah.github.io/Chalkboard). Its source code is located [here](https://www.github.com/Zushah/zushah.github.io/blob/main/Chalkboard).
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Chalkboard examples
Six basic programs made by Zushah that utilize [Chalkboard v1.7.0 Descartes](https://www.github.com/Zushah/Chalkboard/releases/tag/v1.7.0) are located in this directory.
Six basic programs made by Zushah that utilize [Chalkboard v2.0.0 al-Khwarizmi](https://www.github.com/Zushah/Chalkboard/releases/tag/v2.0.0) are located in this directory.

They can be viewed in action here:
- [fluid.js](https://zushah.github.io/Chalkboard/examples/fluid.html)
Expand All @@ -9,4 +9,4 @@ They can be viewed in action here:
- [newton.js](https://zushah.github.io/Chalkboard/examples/newton.html)
- [quat-donut.js](https://zushah.github.io/Chalkboard/examples/quat-donut.html)

The main webpage for the examples can be visited at the [Chalkboard website](https://zushah.github.io/Chalkboard/examples.html).
The main webpage for the examples can be visited at the [Chalkboard website](https://zushah.github.io/Chalkboard/examples/index.html).
26 changes: 13 additions & 13 deletions examples/fluid.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.7.0 Descartes Example Program: Fluid Flow
Version 2.0.0 al-Khwarizmi Example Program: Fluid Flow
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand All @@ -12,36 +12,36 @@ canvas.height = window.innerHeight;
var cb = Chalkboard; // Initialize Chalkboard as cb

// Vector field defined as F(x, y) = (-y, -x/(1 + x^2)^2), adapted from "Learning about Hamiltonian Monte Carlo" which can be found here: https://github.com/anvaka/fieldplay/blob/main/Awesome%20Fields.md
var F = cb.vec2.field("y", "-x / ((1 + x * x) * (1 + x * x))");
var F = cb.vect.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); // Velocity vector
this.pos = cb.vect.random(-canvas.width / 2, canvas.width / 2, 2); // Position vector
this.vel = cb.vect.init(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 5
this.pos = cb.vec2.add(this.pos, this.vel); // Velocity is added to the position
this.vel = cb.vect.magset(cb.vect.fromField(F, cb.vect.scl(this.pos, 1/100)), 5); // Velocity direction depends on the (scaled) vector field, velocity magnitude is set to always be 5
this.pos = cb.vect.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) {
if (this.pos.x > canvas.width / 2) {
this.pos.x = -canvas.width / 2;
this.ppos = this.pos;
}
if(this.pos.x < -canvas.width / 2) {
if (this.pos.x < -canvas.width / 2) {
this.pos.x = canvas.width / 2;
this.ppos = this.pos;
}
if(this.pos.y > canvas.height / 2) {
if (this.pos.y > canvas.height / 2) {
this.pos.y = -canvas.height / 2;
this.ppos = this.pos;
}
if(this.pos.y < -canvas.height / 2) {
if (this.pos.y < -canvas.height / 2) {
this.pos.y = canvas.height / 2;
this.ppos = this.pos;
}
Expand All @@ -64,15 +64,15 @@ class Particle {
}
// Create 500 particles in the particles array
var particles = [];
for(var i = 0; i < 500; i++) {
for (var i = 0; i < 500; i++) {
particles.push(new Particle());
}

// Draw everything
ctx.fillStyle = "rgb(0, 0, 0)";
ctx.fillStyle = "black";
ctx.fillRect(0, 0, canvas.width, canvas.height);
function main() {
for(var i = 0; i < particles.length; i++) {
for (var i = 0; i < particles.length; i++) {
particles[i].draw();
}
window.requestAnimationFrame(main);
Expand Down
26 changes: 13 additions & 13 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.7.0 Descartes Example Program: Hyperbolic Functions
Version 2.0.0 al-Khwarizmi Example Program: Hyperbolic Functions
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand All @@ -13,14 +13,14 @@ var cb = Chalkboard; // Initialize Chalkboard as cb

var theta = 0;
function main() {
ctx.fillStyle = "rgb(255, 255, 255)";
ctx.fillStyle = "white";
ctx.fillRect(0, 0, canvas.width, canvas.height);
cb.plot.xyplane({lineWidth: 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)"], "curv");
cb.plot.function(f, {strokeStyle: "rgb(100, 100, 255)", domain: [0, 10], lineWidth: 4});
cb.plot.function(f, {strokeStyle: "rgb(100, 100, 255)", domain: [-10, 0], lineWidth: 4});
var f = cb.real.define(["(t * t + 1) / (2 * t)", "(t * t - 1) / (2 * t)"], "curv");
cb.plot.definition(f, {strokeStyle: "rgb(100, 100, 255)", domain: [0, 10], lineWidth: 4});
cb.plot.definition(f, {strokeStyle: "rgb(100, 100, 255)", domain: [-10, 0], lineWidth: 4});

// The two main hyperbolic trigonometric functions, hyperbolic sine (sinh) and hyperbolic cosine (cosh)
var x = cb.trig.cosh(theta);
Expand All @@ -39,12 +39,12 @@ function main() {
ctx.moveTo(0, -y * 100);
ctx.lineTo(x * 100, -y * 100);
ctx.stroke();
ctx.fillStyle = "rgb(0, 0, 0)";
ctx.fillStyle = "black";
ctx.beginPath();
ctx.ellipse(x * 100, -y * 100, 5, 5, 0, 0, cb.PI(2));
ctx.fill();
ctx.restore();
ctx.fillStyle = "rgb(0, 0, 0)";
ctx.fillStyle = "black";
ctx.font = "50px Times New Roman";
ctx.fillText("x² - y² = 1", 20, 70);
ctx.fillText("θ = " + theta.toFixed(2), 20, 120);
Expand All @@ -55,34 +55,34 @@ function main() {
ctx.fillText("sech(θ) = " + cb.trig.sech(theta).toFixed(2), 20, 370);
ctx.fillText("coth(θ) = " + cb.trig.coth(theta).toFixed(2), 20, 420);
ctx.fillText("arcsinh(θ) = " + cb.trig.arcsinh(theta).toFixed(2), 20, 470);
if(cb.trig.arccosh(theta) !== undefined) {
if (cb.trig.arccosh(theta) !== undefined) {
ctx.fillText("arccosh(θ) = " + cb.trig.arccosh(theta).toFixed(2), 20, 520);
} else {
ctx.fillText("arccosh(θ) = undefined", 20, 520);
}
if(cb.trig.arctanh(theta) !== undefined) {
if (cb.trig.arctanh(theta) !== undefined) {
ctx.fillText("arctanh(θ) = " + cb.trig.arctanh(theta).toFixed(2), 20, 570);
} else {
ctx.fillText("arctanh(θ) = undefined", 20, 570);
}
if(cb.trig.arccsch(theta) !== undefined) {
if (cb.trig.arccsch(theta) !== undefined) {
ctx.fillText("arccsch(θ) = " + cb.trig.arccsch(theta).toFixed(2), 20, 620);
} else {
ctx.fillText("arccsch(θ) = undefined", 20, 620);
}
if(cb.trig.arcsech(theta) !== undefined) {
if (cb.trig.arcsech(theta) !== undefined) {
ctx.fillText("arcsech(θ) = " + cb.trig.arcsech(theta).toFixed(2), 20, 670);
} else {
ctx.fillText("arcsech(θ) = undefined", 20, 670);
}
if(cb.trig.arccoth(theta) !== undefined) {
if (cb.trig.arccoth(theta) !== undefined) {
ctx.fillText("arccoth(θ) = " + cb.trig.arccoth(theta).toFixed(2), 20, 720);
} else {
ctx.fillText("arccoth(θ) = undefined", 20, 720);
}

theta += 0.05;
if(theta > 2.5) {
if (theta > 2.5) {
theta = -2.5;
}
window.requestAnimationFrame(main);
Expand Down
16 changes: 8 additions & 8 deletions 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.7.0 Descartes Example Program: Mandelbrot Set
Version 2.0.0 al-Khwarizmi Example Program: Mandelbrot Set
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand All @@ -16,29 +16,29 @@ var cb = Chalkboard; // Initialize Chalkboard as cb
var imageData = ctx.createImageData(canvas.width, canvas.height);
var pixels = imageData.data;
function main() {
for(var x = 0; x < canvas.width; x++) {
for(var y = 0; y < canvas.height; y++) {
for (var x = 0; x < canvas.width; x++) {
for (var y = 0; y < canvas.height; y++) {
// The complex numbers from the Mandelbrot set's definition (see: lines 33-34), z and c
var z = cb.comp.new(cb.numb.map(x, [0, canvas.width], [-2 * ratio, 2 * ratio]), cb.numb.map(y, [0, canvas.height], [-2, 2]));
var c = cb.comp.new(cb.numb.map(x, [0, canvas.width], [-2 * ratio, 2 * ratio]), cb.numb.map(y, [0, canvas.height], [-2, 2]));
var z = cb.comp.init(cb.numb.map(x, [0, canvas.width], [-2 * ratio, 2 * ratio]), cb.numb.map(y, [0, canvas.height], [-2, 2]));
var c = cb.comp.init(cb.numb.map(x, [0, canvas.width], [-2 * ratio, 2 * ratio]), cb.numb.map(y, [0, canvas.height], [-2, 2]));

var currIteration = 0; // The current iteration of the fractal
var maxIterations = 100; // The maximum iterations intended to be evaluated

while(currIteration < maxIterations) {
while (currIteration < maxIterations) {
// The definition of the Mandelbrot set: f(z) = z^2 + c (see: https://en.wikipedia.org/wiki/Mandelbrot_set)
z = cb.comp.add(cb.comp.sq(z), c);

// Of course we can't keep iterating infinitely, so we'll just round infinity down to 2
if(cb.comp.mag(z) > 2) {
if (cb.comp.magsq(z) > 4) {
break;
}
currIteration++; // Keep iterating
}

// The fractal will be colored based on how many iterations it's gone through at a point
var color = cb.numb.map(cb.real.sqrt(cb.numb.map(currIteration, [0, maxIterations], [0, 1])), [0, 1], [0, 255]);
if(currIteration === maxIterations) {
if (currIteration === maxIterations) {
color = 0;
}
var px = (x + y * canvas.width) * 4;
Expand Down
28 changes: 15 additions & 13 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.7.0 Descartes Example Program: Matrix Donut
Version 2.0.0 al-Khwarizmi Example Program: Matrix Donut
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand All @@ -13,35 +13,37 @@ var cb = Chalkboard; // Initialize Chalkboard as cb

// Generate the donut's points with parametric equations (see: https://en.wikipedia.org/wiki/Torus)
var points = [];
for(var u = 0; u < cb.PI(2); u += cb.PI(1/16)) {
for(var v = 0; v < cb.PI(2); v += cb.PI(1/6)) {
for (var u = 0; u < cb.PI(2); u += cb.PI(1/16)) {
for (var v = 0; v < cb.PI(2); v += cb.PI(1/6)) {
var x = (75 + 30 * cb.trig.cos(v)) * cb.trig.cos(u);
var y = (75 + 30 * cb.trig.cos(v)) * cb.trig.sin(u);
var z = 30 * cb.trig.sin(v);
points.push(cb.vec3.new(x, y, z));
points.push(cb.vect.init(x, y, z));
}
}

// Make the donut rotate with a rotation matrix
var r = cb.matr.rotator(0.01, 0.01, 0.01);

function main() {
ctx.fillStyle = "rgb(255, 255, 255)";
ctx.fillStyle = "white";
ctx.fillRect(0, 0, canvas.width, canvas.height);

ctx.save();
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.strokeStyle = "rgb(0, 0, 0)";
for(var i = 0; i < points.length; i++) {
for(var j = 0; j < points.length; j++) {
if(cb.vec3.dist(points[i], points[j]) < 25) {
ctx.strokeStyle = "black";
for (var i = 0; i < points.length; i++) {
for (var j = 0; j < points.length; j++) {
if (cb.vect.distsq(points[i], points[j]) < 625) {
// Draw lines between the donut's points to draw the donut
cb.geom.line3D(points[i].x, points[i].y, points[i].z, points[j].x, points[j].y, points[j].z);
}
}
}
ctx.restore();

// Make the donut rotate with a rotation matrix
var r = cb.matr.rotator(cb.trig.toRad(1), cb.trig.toRad(1), cb.trig.toRad(1));
for(var i = 0; i < points.length; i++) {
points[i] = cb.matr.mulvec(r, points[i]); // Multiply the rotation matrix with the points' vectors
for (var i = 0; i < points.length; i++) {
points[i] = cb.matr.mulVector(r, points[i]); // Multiply the rotation matrix with the points' vectors
}

window.requestAnimationFrame(main);
Expand Down
22 changes: 9 additions & 13 deletions 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.7.0 Descartes Example Program: Newton's Method
Version 2.0.0 al-Khwarizmi Example Program: Newton's Method
Authored by Zushah ===> https://www.github.com/Zushah
*/

Expand All @@ -12,33 +12,29 @@ canvas.height = window.innerHeight;
var cb = Chalkboard; // Initialize Chalkboard as cb

// Random fourth-degree polynomial function
var c1 = cb.numb.random(-3, 3);
var c2 = cb.numb.random(-3, 3);
var c3 = cb.numb.random(-3, 3);
var c4 = cb.numb.random(-3, 3);
var c5 = cb.numb.random(-3, 3);
var f = cb.real.function(c1 + " * x * x * x * x + " + c2 + " * x * x * x + " + c3 + " * x * x + " + c4 + " * x + " + c5);
var c = cb.stat.random(-3, 3, 5);
var f = cb.real.define(c[0] + " * x * x * x * x + " + c[1] + " * x * x * x + " + c[2] + " * x * x + " + c[3] + " * x + " + c[4]);

// Newton's method's solution and tangent line (see: https://en.wikipedia.org/wiki/Newton's_method)
var root = cb.calc.Newton(f, [-5, 5]);
var y = cb.real.function(cb.calc.dfdx(f, root) + " * (x - " + root + ") + " + cb.real.val(f, root));
var y = cb.real.define(cb.calc.dfdx(f, root) + " * (x - " + root + ") + " + cb.real.val(f, root));

function main() {
ctx.fillStyle = "rgb(255, 255, 255)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
cb.plot.xyplane({lineWidth: 2});

// Draw the polynomial
cb.plot.function(f, {strokeStyle: "rgb(100, 100, 255)", lineWidth: 4});
cb.plot.definition(f, {strokeStyle: "rgb(100, 100, 255)", lineWidth: 4});
ctx.fillStyle = "rgb(0, 0, 0)";
ctx.font = "50px Times New Roman";
ctx.fillText("f(x) = " + c1.toFixed(2) + "x⁴ + " + c2.toFixed(2) + "x³ + " + c3.toFixed(2) + "x² + " + c4.toFixed(2) + "x + " + c5.toFixed(2), 20, 70);
ctx.fillText("f(x) = " + c[0].toFixed(2) + "x⁴ + " + c[1].toFixed(2) + "x³ + " + c[2].toFixed(2) + "x² + " + c[3].toFixed(2) + "x + " + c[4].toFixed(2), 20, 70);

// Only draw the solution and the tangent line if the solution is correct
if(cb.real.val(f, root).toFixed(1) == 0) {
// Draw the solution and the tangent line if the solution is correct
if (cb.real.val(f, root).toFixed(1) == 0) {
ctx.fillText("y = " + cb.calc.dfdx(f, root).toFixed(2) + "x - " + (cb.calc.dfdx(f, root) * root).toFixed(2), 20, 120);
ctx.fillText("A possible root is at x = " + root.toFixed(2), 20, 170);
cb.plot.function(y, {strokeStyle: "rgb(255, 100, 100)", lineWidth: 4});
cb.plot.definition(y, {strokeStyle: "rgb(255, 100, 100)", lineWidth: 4});
ctx.save();
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.beginPath();
Expand Down
Loading

0 comments on commit 5950134

Please sign in to comment.