Skip to content

Commit

Permalink
rebuilt files for new release version
Browse files Browse the repository at this point in the history
  • Loading branch information
Roopesh2 committed Aug 30, 2023
1 parent 9d6d146 commit 4e98b73
Show file tree
Hide file tree
Showing 59 changed files with 336 additions and 200 deletions.
2 changes: 1 addition & 1 deletion Extensions/Animations/constructs.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function Arc(args) {

/**
* animate filling of a given shape
* ! Has some flaws !
* TODO: Has some flaws
* @param {string} name name of animation. Optional
* @param {string} canvasName ID of canvas
* @param {string|Array<number>} FILL color of canvas
Expand Down
9 changes: 4 additions & 5 deletions Extensions/Animations/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loop, noLoop } from "../../src/settings.js";
import { animateFill } from "./constructs.js";

(function () {
if (window["C"] && typeof window["C"].addExtension == "function") {
let C = window["C"];
Expand Down Expand Up @@ -47,7 +47,7 @@ import { animateFill } from "./constructs.js";
syncWithTime = animation.syncWithTime || false,
t = 0,
dt = dTime / dur,
len = points.length - 1;
len = points.length;
if (ctx.lineWidth > 0 && ctx.doStroke) {
if (typeof animation.draw != "function") {
if (smoothen) {
Expand Down Expand Up @@ -153,8 +153,7 @@ import { animateFill } from "./constructs.js";
}
let currentPoint =
points[
Math.round(len * rateFunction(t)) %
len
Math.ceil(len * rateFunction(t)) % len
];
ctx.lineTo(currentPoint[0], currentPoint[1]);
if (ctx.doStroke) ctx.stroke();
Expand All @@ -163,7 +162,7 @@ import { animateFill } from "./constructs.js";
},
ctx.name,
dTime,
50,
1,
{},
dur,
);
Expand Down
9 changes: 8 additions & 1 deletion docs/WebGL.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/WebGL_m4.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/WebGL_settings.js.html

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions docs/WebGL_webgl.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/color_color_converters.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/color_color_reader.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/color_gradients.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/color_interpolation.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/color_random.js.html

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions docs/constants_color_palettes.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/constants_colors.js.html

Large diffs are not rendered by default.

38 changes: 1 addition & 37 deletions docs/global.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/image_image.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/image_processing.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/m4_m4.html

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions docs/main.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/math_aritmetics.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/math_points.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/math_random.js.html

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions docs/misc_point_generator.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Arithmetic-Functions.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/module-Arrows.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/module-Braces.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Color-Converters.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Color-Gradient.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Color-Lerp.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/module-Color-Palettes.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Color-Reader.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Colors.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Coordinate-Systems.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/module-Extra-Shapes.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Geometric-Shapes.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Image-Processing.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Image.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Plottter-Functions.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Point-Utils.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Random-Colors.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Random-Functions.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Settings.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/module-Tex.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-Utils.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/module-text.html

Large diffs are not rendered by default.

29 changes: 9 additions & 20 deletions docs/objects_arrows.js.html

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions docs/objects_braces.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/objects_coordinate_systems.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/objects_functions.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/objects_geometry.js.html

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions docs/objects_more_shapes.js.html

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions docs/objects_tex.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/objects_text.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/settings.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/utils.js.html

Large diffs are not rendered by default.

175 changes: 175 additions & 0 deletions examples/cutting/code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
````js
const W = 400;
const H = 400;
const translateX = W / 1.5 + 50;
const translateY = H / 2;

C(draw, ".display", { width: W, height: H });

async function draw() {
setup();

let data = await read("./data.txt");
let pts = NCtoPoints(data);
drawProfileOutline(pts);
drawProfileHandles(pts);

let profileEdge = generateProfileGeometry(pts);
drawProfileCuts(profileEdge);
}

/**
* Generates boundary points of profile
* @param {Array<{x:number, z: number}>} handles
* @param {number} step
* @returns {Array<{x:number, z: number}>}
*/
function generateProfileGeometry(handles, step = 2) {
let points = [];
for (let i = 1; i < handles.length; i++) {
let p1 = handles[i - 1],
p2 = handles[i];
let xCoords = arange(p1.x, p2.x, step),
interpolator = linear; // function that outlines profile surface
if (xCoords.length < 2 && i > 1) continue;
xCoords.forEach((val, i) => {
points.push({
z: interpolator(p1.z, p2.z, i / (xCoords.length - 1)),
x: xCoords[i],
});
});
}
return points;
}

/**
* Linear interpolation.
* @param {number} a start
* @param {number} b end
* @param {number} t ∈ [0, 1]
* @returns {number} ∈ [a, b]
*/
function linear(a, b, t) {
return a + t * (b - a);
}

/**
* Draws profile cuts based on bounding geometry
*
* @param {Array<{x:number, z: number}>} edgePoints
*/
function drawProfileCuts(edgePoints) {
stroke("#0fa");
console.log(edgePoints);
for (let i = 0; i < edgePoints.length; i++) {
let x = edgePoints[i].z;
let y = edgePoints[i].x;
line(0, y, x, y);
}
}

function setup() {
background(0);
translate(translateX, translateY);
invertXAxis();
invertYAxis();
let a = axes({
xAxis: {
length: W / 1.3,
range: [-10, 100, 10],
includeRightTip: false,
fontSize: 13,
axisFont: 20,
axisLabel: "z",
},
yAxis: {
length: H / 1.3,
range: [-50, 50, 10],
includeRightTip: false,
textDirection: [0, -1.2],
fontSize: 13,
axisFont: 20,
axisLabel: "x",
},
});
scale(...a.unitSpace);
strokeWidth(0.3);
}

function drawProfileOutline(handles) {
stroke("yellow");
startShape();
moveTo(handles[0].z, handles[0].x);
for (let i = 1; i < handles.length; i++) {
let pt = handles[i];
lineTo(pt.z, pt.x);
}
stroke();
endShape();
}

function drawProfileHandles(handles) {
fill("red");
for (let handle of handles) {
point(handle.z, handle.x, 2);
}
}

/**
* Reads a local file and returns output text
* @param {string} file
* @returns {string}
*/
async function read(file) {
let data;
await fetch(file)
.then((res) => {
return res.blob();
})
.then((dat) => {
data = dat.text();
});
return data;
}

/**
* Extracts coodinates from NC statements
* @param {string} txt
* @returns {Array<{x:number, z: number}>[]}
*/
function NCtoPoints(txt) {
let arr = [];
txt = txt.split("\n");
for (let line of txt) {
if (line.length < 4) continue;
arr.push(extractCoords(line));
}
return arr;
}

/**
* Extracts coords from single NC instruction
* @param {string} line
* @returns {{x:number, z: number}}
*/
function extractCoords(line) {
let x = line.match(/(?<=x)(\-+)?\.?\d+\.?(\d+)?/gi);
let z = line.match(/(?<=z)(\-+)?\.?\d+\.?(\d+)?/gi);
return { z: parseFloat(z), x: parseFloat(x) };
}

/**
* Returns array of numbers from ```start``` to ```end``` each with successive difference of ```step```
* @param {number} start
* @param {number} end
* @param {number} step
* @param {boolean} rev
* @returns {number[]}
*/
function arange(start, end, step, rev = false) {
let arr = [];
if (rev) for (let i = end; i >= start; i -= step) arr.push(i);
else for (let i = start; i <= end; i += step) arr.push(i);
return arr;
}
````
6 changes: 2 additions & 4 deletions examples/cutting/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<!doctype html>
<html lang="en">
<head>
<!doctype html><html lang="en"><head>
<meta charset="UTF-8" />
<script src="../../dist/c.min.js"></script>
<script defer src="./index.js" type="module"></script>
<script defer type="module" src="./index.js"></script>
<style>
body,
html {
Expand Down
Loading

0 comments on commit 4e98b73

Please sign in to comment.