-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
9 changed files
with
200 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.