plotboilerplate 1.25.0 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.esm.js +171 -43
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +171 -43
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +6 -2
- package/src/cjs/Bounds.d.ts +79 -25
- package/src/cjs/Bounds.js +102 -29
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +3 -0
- package/src/cjs/CircleSector.js +28 -1
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +4 -3
- package/src/cjs/PlotBoilerplate.js +2 -1
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/draw.d.ts +4 -2
- package/src/cjs/draw.js +9 -4
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +3 -2
- package/src/cjs/drawgl.js +2 -1
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +10 -4
- package/src/cjs/drawutilssvg.js +28 -7
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +2 -0
- package/src/cjs/interfaces/DrawLib.js +1 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/utils/LissajousFigure.d.ts +34 -0
- package/src/cjs/utils/LissajousFigure.js +100 -0
- package/src/cjs/utils/LissajousFigure.js.map +1 -0
- package/src/cjs/utils/PerlinNoise.d.ts +19 -0
- package/src/cjs/utils/PerlinNoise.js +352 -0
- package/src/cjs/utils/PerlinNoise.js.map +1 -0
- package/src/cjs/utils/SVGPathUtils.d.ts +22 -0
- package/src/cjs/utils/SVGPathUtils.js +45 -0
- package/src/cjs/utils/SVGPathUtils.js.map +1 -0
- package/src/cjs/utils/WebColors.d.ts +2 -1
- package/src/cjs/utils/WebColors.js +14 -25
- package/src/cjs/utils/WebColors.js.map +1 -1
- package/src/cjs/utils/algorithms/PolygonTesselationOutlines.d.ts +145 -0
- package/src/cjs/utils/algorithms/PolygonTesselationOutlines.js +269 -0
- package/src/cjs/utils/algorithms/PolygonTesselationOutlines.js.map +1 -0
- package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.d.ts +23 -0
- package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.js +270 -0
- package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.js.map +1 -0
- package/src/cjs/utils/datastructures/Color.js +0 -19
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/datastructures/ColorGradient.d.ts +2 -0
- package/src/cjs/utils/datastructures/ColorGradient.js +5 -0
- package/src/cjs/utils/datastructures/ColorGradient.js.map +1 -1
- package/src/cjs/utils/datastructures/DataGrid2d.d.ts +6 -0
- package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.d.ts +88 -0
- package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.js +155 -0
- package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.js.map +1 -0
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +1 -7
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +3 -3
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
- package/src/cjs/utils/datastructures/GeometryMesh.d.ts +49 -0
- package/src/cjs/utils/datastructures/GeometryMesh.js +58 -0
- package/src/cjs/utils/datastructures/GeometryMesh.js.map +1 -0
- package/src/cjs/utils/datastructures/Girih.d.ts +38 -1
- package/src/cjs/utils/datastructures/Girih.js +71 -1
- package/src/cjs/utils/datastructures/Girih.js.map +1 -1
- package/src/cjs/utils/detectDarkMode.js +16 -7
- package/src/cjs/utils/detectDarkMode.js.map +1 -1
- package/src/cjs/utils/dom/components/ColorGradientPicker.d.ts +4 -3
- package/src/cjs/utils/dom/components/ColorGradientPicker.js +8 -8
- package/src/cjs/utils/dom/components/ColorGradientPicker.js.map +1 -1
- package/src/cjs/utils/dom/components/ColorGradientSelector.d.ts +1 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.js +4 -2
- package/src/cjs/utils/dom/components/ColorGradientSelector.js.map +1 -1
- package/src/cjs/utils/io/FileDrop.d.ts +2 -0
- package/src/cjs/utils/io/FileDrop.js +4 -0
- package/src/cjs/utils/io/FileDrop.js.map +1 -1
- package/src/cjs/utils/parsers/svg/types.d.ts +8 -8
- package/src/esm/Bounds.d.ts +79 -25
- package/src/esm/Bounds.js +102 -29
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CircleSector.d.ts +3 -0
- package/src/esm/CircleSector.js +28 -1
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -3
- package/src/esm/PlotBoilerplate.js +2 -1
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/draw.d.ts +4 -2
- package/src/esm/draw.js +9 -4
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +3 -2
- package/src/esm/drawgl.js +2 -1
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +10 -4
- package/src/esm/drawutilssvg.js +28 -7
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +2 -0
- package/src/esm/interfaces/DrawLib.js +1 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/utils/LissajousFigure.d.ts +34 -0
- package/src/esm/utils/LissajousFigure.js +95 -0
- package/src/esm/utils/LissajousFigure.js.map +1 -0
- package/src/esm/utils/PerlinNoise.d.ts +19 -0
- package/src/esm/utils/PerlinNoise.js +346 -0
- package/src/esm/utils/PerlinNoise.js.map +1 -0
- package/src/esm/utils/SVGPathUtils.d.ts +22 -0
- package/src/esm/utils/SVGPathUtils.js +42 -0
- package/src/esm/utils/SVGPathUtils.js.map +1 -0
- package/src/esm/utils/WebColors.d.ts +2 -1
- package/src/esm/utils/WebColors.js +14 -25
- package/src/esm/utils/WebColors.js.map +1 -1
- package/src/esm/utils/algorithms/PolygonTesselationOutlines.d.ts +145 -0
- package/src/esm/utils/algorithms/PolygonTesselationOutlines.js +262 -0
- package/src/esm/utils/algorithms/PolygonTesselationOutlines.js.map +1 -0
- package/src/esm/utils/algorithms/pixelCornersToRoundPaths.d.ts +23 -0
- package/src/esm/utils/algorithms/pixelCornersToRoundPaths.js +266 -0
- package/src/esm/utils/algorithms/pixelCornersToRoundPaths.js.map +1 -0
- package/src/esm/utils/datastructures/Color.js +0 -19
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/datastructures/ColorGradient.d.ts +2 -0
- package/src/esm/utils/datastructures/ColorGradient.js +5 -0
- package/src/esm/utils/datastructures/ColorGradient.js.map +1 -1
- package/src/esm/utils/datastructures/DataGrid2d.d.ts +6 -0
- package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.d.ts +88 -0
- package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.js +150 -0
- package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.js.map +1 -0
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +1 -7
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +3 -3
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
- package/src/esm/utils/datastructures/GeometryMesh.d.ts +49 -0
- package/src/esm/utils/datastructures/GeometryMesh.js +53 -0
- package/src/esm/utils/datastructures/GeometryMesh.js.map +1 -0
- package/src/esm/utils/datastructures/Girih.d.ts +38 -1
- package/src/esm/utils/datastructures/Girih.js +71 -1
- package/src/esm/utils/datastructures/Girih.js.map +1 -1
- package/src/esm/utils/detectDarkMode.js +16 -7
- package/src/esm/utils/detectDarkMode.js.map +1 -1
- package/src/esm/utils/dom/components/ColorGradientPicker.d.ts +4 -3
- package/src/esm/utils/dom/components/ColorGradientPicker.js +18 -7
- package/src/esm/utils/dom/components/ColorGradientPicker.js.map +1 -1
- package/src/esm/utils/dom/components/ColorGradientSelector.d.ts +1 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.js +9 -2
- package/src/esm/utils/dom/components/ColorGradientSelector.js.map +1 -1
- package/src/esm/utils/io/FileDrop.d.ts +2 -0
- package/src/esm/utils/io/FileDrop.js +4 -0
- package/src/esm/utils/io/FileDrop.js.map +1 -1
- package/src/esm/utils/parsers/svg/types.d.ts +8 -8
- package/src/ts/Bounds.ts +107 -22
- package/src/ts/CircleSector.ts +39 -6
- package/src/ts/PlotBoilerplate.ts +4 -3
- package/src/ts/draw.ts +8 -3
- package/src/ts/drawgl.ts +3 -2
- package/src/ts/drawutilssvg.ts +34 -7
- package/src/ts/interfaces/DrawLib.ts +3 -0
- package/src/ts/utils/LissajousFigure.ts +110 -0
- package/src/ts/utils/PerlinNoise.ts +368 -0
- package/src/ts/utils/SVGPathUtils.ts +55 -0
- package/src/ts/utils/WebColors.ts +20 -33
- package/src/ts/utils/algorithms/PolygonTesselationOutlines.ts +296 -0
- package/src/ts/utils/algorithms/pixelCornersToRoundPaths.ts +379 -0
- package/src/ts/utils/datastructures/Color.ts +0 -19
- package/src/ts/utils/datastructures/ColorGradient.ts +6 -0
- package/src/ts/utils/datastructures/DataGrid2d.ts +7 -0
- package/src/ts/utils/datastructures/DataGrid2dArrayMatrix.ts +182 -0
- package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +4 -11
- package/src/ts/utils/datastructures/GeometryMesh.ts +79 -0
- package/src/ts/utils/datastructures/Girih.ts +78 -1
- package/src/ts/utils/datastructures/interfaces.ts +4 -4
- package/src/ts/utils/detectDarkMode.ts +17 -8
- package/src/ts/utils/dom/components/ColorGradientPicker.tsx +18 -6
- package/src/ts/utils/dom/components/ColorGradientSelector.tsx +9 -2
- package/src/ts/utils/io/FileDrop.ts +5 -0
- package/src/ts/utils/parsers/svg/types.ts +8 -8
package/src/ts/draw.ts
CHANGED
|
@@ -57,7 +57,9 @@
|
|
|
57
57
|
* @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
58
58
|
* @modified 2023-10-07 Adding the optional `arrowHeadBasePositionBuffer` param to the arrowHead(...) method.
|
|
59
59
|
* @modified 2024-09-13 Remoed the scaling of `lineWidth` in the `polygon` and `polyline` methods. This makes no sense here and doesn't match up with the behavior of other line functions.
|
|
60
|
-
* @
|
|
60
|
+
* @modified 2026-01-04 Adding `lineJoin` attribute to the `StrokeOptions`.
|
|
61
|
+
* @modified 2026-03-18 Adding `isOpen` parameter to `cubicBezierPath` draw method.
|
|
62
|
+
* @version 1.14.0
|
|
61
63
|
**/
|
|
62
64
|
|
|
63
65
|
import { CubicBezierCurve } from "./CubicBezierCurve";
|
|
@@ -140,6 +142,7 @@ export class drawutils implements DrawLib<void> {
|
|
|
140
142
|
})
|
|
141
143
|
);
|
|
142
144
|
this.ctx.lineDashOffset = (strokeOptions?.dashOffset ?? 0) * this.scale.x;
|
|
145
|
+
this.ctx.lineJoin = strokeOptions?.lineJoin ?? null;
|
|
143
146
|
}
|
|
144
147
|
|
|
145
148
|
// +---------------------------------------------------------------------------------
|
|
@@ -698,7 +701,7 @@ export class drawutils implements DrawLib<void> {
|
|
|
698
701
|
* @instance
|
|
699
702
|
* @memberof drawutils
|
|
700
703
|
*/
|
|
701
|
-
cubicBezierPath(path: Array<XYCoords>, color: string, lineWidth?: number, strokeOptions?: StrokeOptions) {
|
|
704
|
+
cubicBezierPath(path: Array<XYCoords>, color: string, lineWidth?: number, strokeOptions?: StrokeOptions, isOpen?: boolean) {
|
|
702
705
|
if (!path || path.length == 0) {
|
|
703
706
|
return;
|
|
704
707
|
}
|
|
@@ -723,7 +726,9 @@ export class drawutils implements DrawLib<void> {
|
|
|
723
726
|
this.offset.y + endPoint.y * this.scale.y
|
|
724
727
|
);
|
|
725
728
|
}
|
|
726
|
-
|
|
729
|
+
if (!isOpen) {
|
|
730
|
+
this.ctx.closePath();
|
|
731
|
+
}
|
|
727
732
|
this.ctx.lineWidth = lineWidth || 1;
|
|
728
733
|
this._fillOrDraw(color);
|
|
729
734
|
this.ctx.restore();
|
package/src/ts/drawgl.ts
CHANGED
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
* @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
|
|
17
17
|
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
18
18
|
* @modified 2023-09-29 Added the `lineDashes` attribute.
|
|
19
|
+
* @modified 2026-03-18 Adding `isOpen` parameter to `cubicBezierPath` draw method.
|
|
19
20
|
* @version 0.0.10
|
|
20
21
|
**/
|
|
21
22
|
|
|
22
23
|
import { Polygon } from "./Polygon";
|
|
23
24
|
import { Vertex } from "./Vertex";
|
|
24
|
-
import { DrawLib, XYCoords, SVGPathParams, UID, DrawLibConfiguration, FontStyle, FontWeight } from "./interfaces";
|
|
25
|
+
import { DrawLib, XYCoords, SVGPathParams, UID, DrawLibConfiguration, FontStyle, FontWeight, StrokeOptions } from "./interfaces";
|
|
25
26
|
import { Bounds } from "./Bounds";
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -426,7 +427,7 @@ export class drawutilsgl implements DrawLib<void> {
|
|
|
426
427
|
* @instance
|
|
427
428
|
* @memberof drawutils
|
|
428
429
|
*/
|
|
429
|
-
cubicBezierPath(path: Array<XYCoords>, color: string, lineWidth?: number) {
|
|
430
|
+
cubicBezierPath(path: Array<XYCoords>, color: string, lineWidth?: number, strokeOptions?: StrokeOptions, isOpen?: boolean) {
|
|
430
431
|
// NOT YET IMPLEMENTED
|
|
431
432
|
}
|
|
432
433
|
|
package/src/ts/drawutilssvg.ts
CHANGED
|
@@ -47,7 +47,11 @@
|
|
|
47
47
|
* @modified 2024-01-30 Fixing an issue with immutable style sets; changes to the global draw config did not reflect here (do now).
|
|
48
48
|
* @modified 2024-03-10 Fixing some types for Typescript 5 compatibility.
|
|
49
49
|
* @modified 2024-07-24 Caching custom style defs in a private buffer variable.
|
|
50
|
-
* @
|
|
50
|
+
* @modified 2025-11-14 Fixing a bug in the CSS `mix-blend-mode` property handling (caused a runtime error).
|
|
51
|
+
* @modified 2026-01-04 Adding `lineJoin` attribute to the methods' `StrokeOptions` param.
|
|
52
|
+
* @modified 2026-01-04 Fixing missing `strokeOptions` param in the `drawutilssvg.polygon` method.
|
|
53
|
+
* @modified 2026-03-18 Adding `isOpen` parameter to `cubicBezierPath` draw method.
|
|
54
|
+
* @version 1.7.0
|
|
51
55
|
**/
|
|
52
56
|
|
|
53
57
|
import { CircleSector } from "./CircleSector";
|
|
@@ -416,8 +420,12 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
416
420
|
node = this.createSVGNode(nodeName);
|
|
417
421
|
}
|
|
418
422
|
if (this.drawlibConfiguration.blendMode) {
|
|
419
|
-
|
|
420
|
-
|
|
423
|
+
const blendMode = node.style["mix-blend-mode" as keyof Object];
|
|
424
|
+
if (typeof blendMode === "function") {
|
|
425
|
+
blendMode(this.drawlibConfiguration.blendMode);
|
|
426
|
+
} else {
|
|
427
|
+
node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
|
|
428
|
+
}
|
|
421
429
|
}
|
|
422
430
|
// if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
|
|
423
431
|
// node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
|
|
@@ -650,6 +658,7 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
650
658
|
* @param {StrokeOptions=} strokeOptions -
|
|
651
659
|
*/
|
|
652
660
|
private applyStrokeOpts(node: SVGElement, strokeOptions?: StrokeOptions) {
|
|
661
|
+
// Set line dash options?
|
|
653
662
|
if (
|
|
654
663
|
strokeOptions &&
|
|
655
664
|
strokeOptions.dashArray &&
|
|
@@ -668,6 +677,10 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
668
677
|
node.setAttribute("stroke-dashoffset", `${strokeOptions.dashOffset * this.scale.x}`);
|
|
669
678
|
}
|
|
670
679
|
}
|
|
680
|
+
// Set line join option?
|
|
681
|
+
if (strokeOptions && strokeOptions.lineJoin && drawutilssvg.nodeSupportsLineJoin(node.tagName)) {
|
|
682
|
+
node.setAttribute("stroke-linejoin", strokeOptions.lineJoin);
|
|
683
|
+
}
|
|
671
684
|
}
|
|
672
685
|
|
|
673
686
|
private _x(x: number): number {
|
|
@@ -998,12 +1011,18 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
998
1011
|
* @param {string} color - The CSS colot to draw the path with.
|
|
999
1012
|
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
1000
1013
|
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
1001
|
-
*
|
|
1014
|
+
* @param {boolean} isOpen - (optional) Set to tur if the path should not be closed.
|
|
1002
1015
|
* @return {void}
|
|
1003
1016
|
* @instance
|
|
1004
1017
|
* @memberof drawutilssvg
|
|
1005
1018
|
*/
|
|
1006
|
-
cubicBezierPath(
|
|
1019
|
+
cubicBezierPath(
|
|
1020
|
+
path: Array<XYCoords>,
|
|
1021
|
+
color: string,
|
|
1022
|
+
lineWidth?: number,
|
|
1023
|
+
strokeOptions?: StrokeOptions,
|
|
1024
|
+
isOpen?: boolean
|
|
1025
|
+
): SVGElement {
|
|
1007
1026
|
const node: SVGElement = this.makeNode("path");
|
|
1008
1027
|
this.applyStrokeOpts(node, strokeOptions);
|
|
1009
1028
|
if (!path || path.length == 0) {
|
|
@@ -1031,6 +1050,9 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
1031
1050
|
this._y(endPoint.y)
|
|
1032
1051
|
);
|
|
1033
1052
|
}
|
|
1053
|
+
if (!isOpen) {
|
|
1054
|
+
d.push("Z");
|
|
1055
|
+
}
|
|
1034
1056
|
node.setAttribute("d", d.join(" "));
|
|
1035
1057
|
return this._bindFillDraw(node, "cubicBezierPath", color, lineWidth || 1);
|
|
1036
1058
|
}
|
|
@@ -1532,12 +1554,13 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
1532
1554
|
* @param {Polygon} polygon - The polygon to draw.
|
|
1533
1555
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
1534
1556
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
1557
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
1535
1558
|
* @return {void}
|
|
1536
1559
|
* @instance
|
|
1537
1560
|
* @memberof drawutilssvg
|
|
1538
1561
|
*/
|
|
1539
|
-
polygon(polygon: Polygon, color: string, lineWidth?: number): SVGElement {
|
|
1540
|
-
return this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth);
|
|
1562
|
+
polygon(polygon: Polygon, color: string, lineWidth?: number, strokeOptions?: StrokeOptions): SVGElement {
|
|
1563
|
+
return this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth, strokeOptions);
|
|
1541
1564
|
}
|
|
1542
1565
|
|
|
1543
1566
|
/**
|
|
@@ -1956,6 +1979,10 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
1956
1979
|
return ["line", "path", "circle", "ellipse", "rectangle", "rect"].includes(nodeName);
|
|
1957
1980
|
}
|
|
1958
1981
|
|
|
1982
|
+
private static nodeSupportsLineJoin(nodeName: string) {
|
|
1983
|
+
return ["line", "path", "circle", "ellipse", "rectangle", "rect"].includes(nodeName);
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1959
1986
|
/**
|
|
1960
1987
|
* Creates a basic <line> node with start and end coordinates. The created node will not
|
|
1961
1988
|
* be bound to any root node.
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
26
26
|
* @modified 2023-09-29 Added the `lineDashes` attribute.
|
|
27
27
|
* @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
28
|
+
* @modified 2026-01-04 Adding optional `lineJoin` attribute to the `StrokeOptions` interface.
|
|
28
29
|
**/
|
|
29
30
|
|
|
30
31
|
import { Bounds } from "../Bounds";
|
|
@@ -68,6 +69,8 @@ export interface FontOptions {
|
|
|
68
69
|
export interface StrokeOptions {
|
|
69
70
|
dashOffset?: number;
|
|
70
71
|
dashArray?: Array<number>;
|
|
72
|
+
// SVG has more options for this: arcs | bevel | miter | miter-clip | round
|
|
73
|
+
lineJoin?: "round" | "bevel" | "miter";
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
/**
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wrapper for Lissajous figure params.
|
|
3
|
+
*
|
|
4
|
+
* @author Ikaros Kappler
|
|
5
|
+
* @date 2018-11-22
|
|
6
|
+
* @modified 2025-10-29 Ported to typescript from demo 13-lissajous.
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Vertex } from "../Vertex";
|
|
11
|
+
|
|
12
|
+
export class LissajousFigure {
|
|
13
|
+
freqA: number;
|
|
14
|
+
freqB: number;
|
|
15
|
+
phaseA: number;
|
|
16
|
+
phaseB: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new figure with the given settings.
|
|
20
|
+
* @param {number} freqA - The 'horizontal' frequency.
|
|
21
|
+
* @param {number} freqB - The 'vertical' frequency.
|
|
22
|
+
* @param {number} phaseA - The 'horizonal' phase shift.
|
|
23
|
+
* @param {number} phaseB - The 'vertical' phase shift.
|
|
24
|
+
*/
|
|
25
|
+
constructor(freqA: number, freqB: number, phaseA: number, phaseB: number) {
|
|
26
|
+
this.freqA = freqA;
|
|
27
|
+
this.freqB = freqB;
|
|
28
|
+
this.phaseA = phaseA;
|
|
29
|
+
this.phaseB = phaseB;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get the point at the given abstract time.
|
|
34
|
+
*
|
|
35
|
+
* The result is periodic in 0..TWO_PI.
|
|
36
|
+
*
|
|
37
|
+
* @param {number} t - The timing value (for example milliseconds).
|
|
38
|
+
* @returns {Vertex} The x-y-position on the Lissajous figure at the given time.
|
|
39
|
+
*/
|
|
40
|
+
public getPointAt(t: number): Vertex {
|
|
41
|
+
return new Vertex(Math.sin(this.phaseA + this.freqA * t), Math.sin(this.phaseB + this.freqB * t));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public toPolyLine(stepSize: number): Array<Vertex> {
|
|
45
|
+
const polyLine: Array<Vertex> = [];
|
|
46
|
+
|
|
47
|
+
let pA = new Vertex(0, 0);
|
|
48
|
+
|
|
49
|
+
stepSize = Math.abs(stepSize);
|
|
50
|
+
for (var t = 0; t <= 2 * Math.PI; t += stepSize) {
|
|
51
|
+
pA = this.getPointAt(t);
|
|
52
|
+
polyLine.push(pA.clone());
|
|
53
|
+
}
|
|
54
|
+
return polyLine;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public toQuadraticBezierApproximation(
|
|
58
|
+
stepSize: number
|
|
59
|
+
// scale: number
|
|
60
|
+
// alternating: boolean
|
|
61
|
+
): Array<[Vertex, Vertex, Vertex] | [Vertex, Vertex]> {
|
|
62
|
+
const result: Array<[Vertex, Vertex, Vertex] | [Vertex, Vertex]> = [];
|
|
63
|
+
let pA = new Vertex(0, 0);
|
|
64
|
+
let pB = new Vertex(0, 0);
|
|
65
|
+
stepSize = Math.abs(stepSize);
|
|
66
|
+
|
|
67
|
+
let p1 = new Vertex(0, 0);
|
|
68
|
+
let dx1 = this.freqA;
|
|
69
|
+
let dy1 = this.freqB;
|
|
70
|
+
pA = this.getPointAt(stepSize);
|
|
71
|
+
let x2, y2, dx2, dy2, det, x3, y3;
|
|
72
|
+
var i = 0;
|
|
73
|
+
for (var t = stepSize; t <= 2 * Math.PI + 2 * stepSize; t += stepSize) {
|
|
74
|
+
x2 = Math.sin(this.phaseA + this.freqA * t);
|
|
75
|
+
y2 = Math.sin(this.phaseB + this.freqB * t);
|
|
76
|
+
dx2 = this.freqA * Math.cos(this.phaseA + this.freqA * t);
|
|
77
|
+
dy2 = this.freqB * Math.cos(this.phaseB + this.freqB * t);
|
|
78
|
+
det = dx1 * dy2 - dy1 * dx2;
|
|
79
|
+
if (Math.abs(det) > 0.1) {
|
|
80
|
+
x3 = ((x2 * dy2 - y2 * dx2) * dx1 - (p1.x * dy1 - p1.y * dx1) * dx2) / det;
|
|
81
|
+
y3 = ((x2 * dy2 - y2 * dx2) * dy1 - (p1.x * dy1 - p1.y * dx1) * dy2) / det;
|
|
82
|
+
// pB.set(scale * x2, scale * y2 * (alternating ? -1 : 1));
|
|
83
|
+
// pB.set(scale * x2, scale * y2);
|
|
84
|
+
pB.set(x2, y2);
|
|
85
|
+
|
|
86
|
+
// pB.set(x2, y2);
|
|
87
|
+
|
|
88
|
+
if (i > 0) {
|
|
89
|
+
// pb.draw.quadraticBezier(pA, new Vertex(scale * x3, scale * y3), pB, "rgba(0,108,255,1.0)", 2);
|
|
90
|
+
// result.push([pA.clone(), new Vertex(scale * x3, scale * y3), pB.clone()]);
|
|
91
|
+
result.push([pA.clone(), new Vertex(x3, y3), pB.clone()]);
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
// pB.set(scale * x2, scale * y2);
|
|
95
|
+
pB.set(x2, y2);
|
|
96
|
+
|
|
97
|
+
if (i > 0) {
|
|
98
|
+
// pb.draw.line(pA, pB, "rgba(0,192,192,0.8)", 2);
|
|
99
|
+
result.push([pA.clone(), pB.clone()]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
p1.set(x2, y2);
|
|
103
|
+
dx1 = dx2;
|
|
104
|
+
dy1 = dy2;
|
|
105
|
+
pA.set(pB);
|
|
106
|
+
i++;
|
|
107
|
+
} // END for
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A speed-improved perlin and simplex noise algorithms for 2D.
|
|
3
|
+
*
|
|
4
|
+
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
|
|
5
|
+
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
|
|
6
|
+
* Better rank ordering method by Stefan Gustavson in 2012.
|
|
7
|
+
* Converted to Javascript by Joseph Gentle.
|
|
8
|
+
*
|
|
9
|
+
* Version 2012-03-09
|
|
10
|
+
*
|
|
11
|
+
* This code was placed in the public domain by its original author,
|
|
12
|
+
* Stefan Gustavson. You may use it as you see fit, but
|
|
13
|
+
* attribution is appreciated.
|
|
14
|
+
*
|
|
15
|
+
* @modified 2023-03-07 Ikaros Kappler; ported to Typescript & refactored to class.
|
|
16
|
+
* @modified 2025-11-12 Ikaros Kappler; moved from a different project `floatsim` and refactored the class.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
class Grad {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
z: number;
|
|
23
|
+
constructor(x: number, y: number, z: number) {
|
|
24
|
+
this.x = x;
|
|
25
|
+
this.y = y;
|
|
26
|
+
this.z = z;
|
|
27
|
+
}
|
|
28
|
+
dot2(x: number, y: number) {
|
|
29
|
+
return this.x * x + this.y * y;
|
|
30
|
+
}
|
|
31
|
+
dot3(x: number, y: number, z: number) {
|
|
32
|
+
return this.x * x + this.y * y + this.z * z;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const grad3: Array<Grad> = [
|
|
37
|
+
new Grad(1, 1, 0),
|
|
38
|
+
new Grad(-1, 1, 0),
|
|
39
|
+
new Grad(1, -1, 0),
|
|
40
|
+
new Grad(-1, -1, 0),
|
|
41
|
+
new Grad(1, 0, 1),
|
|
42
|
+
new Grad(-1, 0, 1),
|
|
43
|
+
new Grad(1, 0, -1),
|
|
44
|
+
new Grad(-1, 0, -1),
|
|
45
|
+
new Grad(0, 1, 1),
|
|
46
|
+
new Grad(0, -1, 1),
|
|
47
|
+
new Grad(0, 1, -1),
|
|
48
|
+
new Grad(0, -1, -1)
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const p: Array<number> = [
|
|
52
|
+
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
|
|
53
|
+
190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20,
|
|
54
|
+
125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220,
|
|
55
|
+
105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
|
|
56
|
+
135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255,
|
|
57
|
+
82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221,
|
|
58
|
+
153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
|
|
59
|
+
251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106,
|
|
60
|
+
157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78,
|
|
61
|
+
66, 215, 61, 156, 180
|
|
62
|
+
];
|
|
63
|
+
// To remove the need for index wrapping, double the permutation table length
|
|
64
|
+
// const perm = new Array<number>(512);
|
|
65
|
+
// const gradP = new Array<Grad>(512);
|
|
66
|
+
|
|
67
|
+
// Skewing and unskewing factors for 2, 3, and 4 dimensions
|
|
68
|
+
const F2 = 0.5 * (Math.sqrt(3) - 1);
|
|
69
|
+
const G2 = (3 - Math.sqrt(3)) / 6;
|
|
70
|
+
|
|
71
|
+
const F3 = 1 / 3;
|
|
72
|
+
const G3 = 1 / 6;
|
|
73
|
+
|
|
74
|
+
const fade = (t: number) => {
|
|
75
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const lerp = (a: number, b: number, t: number) => {
|
|
79
|
+
return (1 - t) * a + t * b;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// export const noise = {
|
|
83
|
+
export class PerlinNoise {
|
|
84
|
+
// To remove the need for index wrapping, double the permutation table length
|
|
85
|
+
perm = new Array<number>(512);
|
|
86
|
+
gradP = new Array<Grad>(512);
|
|
87
|
+
|
|
88
|
+
constructor() {
|
|
89
|
+
// Use initial seed.
|
|
90
|
+
this.seed(0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// This isn't a very good seeding function, but it works ok. It supports 2^16
|
|
94
|
+
// different seed values. Write something better if you need more seeds.
|
|
95
|
+
// module.seed = function (seed) {
|
|
96
|
+
seed(seed: number): PerlinNoise {
|
|
97
|
+
if (seed > 0 && seed < 1) {
|
|
98
|
+
// Scale the seed out
|
|
99
|
+
seed *= 65536;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
seed = Math.floor(seed);
|
|
103
|
+
if (seed < 256) {
|
|
104
|
+
seed |= seed << 8;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (var i = 0; i < 256; i++) {
|
|
108
|
+
var v: number;
|
|
109
|
+
if (i & 1) {
|
|
110
|
+
v = p[i] ^ (seed & 255);
|
|
111
|
+
} else {
|
|
112
|
+
v = p[i] ^ ((seed >> 8) & 255);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.perm[i] = this.perm[i + 256] = v;
|
|
116
|
+
this.gradP[i] = this.gradP[i + 256] = grad3[v % 12];
|
|
117
|
+
}
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 2D simplex noise
|
|
122
|
+
simplex2(xin: number, yin: number): number {
|
|
123
|
+
var n0: number, n1: number, n2: number; // Noise contributions from the three corners
|
|
124
|
+
// Skew the input space to determine which simplex cell we're in
|
|
125
|
+
const s = (xin + yin) * F2; // Hairy factor for 2D
|
|
126
|
+
var i: number = Math.floor(xin + s);
|
|
127
|
+
var j: number = Math.floor(yin + s);
|
|
128
|
+
const t: number = (i + j) * G2;
|
|
129
|
+
const x0: number = xin - i + t; // The x,y distances from the cell origin, unskewed.
|
|
130
|
+
const y0: number = yin - j + t;
|
|
131
|
+
// For the 2D case, the simplex shape is an equilateral triangle.
|
|
132
|
+
// Determine which simplex we are in.
|
|
133
|
+
var i1: number, j1: number; // Offsets for second (middle) corner of simplex in (i,j) coords
|
|
134
|
+
if (x0 > y0) {
|
|
135
|
+
// lower triangle, XY order: (0,0)->(1,0)->(1,1)
|
|
136
|
+
i1 = 1;
|
|
137
|
+
j1 = 0;
|
|
138
|
+
} else {
|
|
139
|
+
// upper triangle, YX order: (0,0)->(0,1)->(1,1)
|
|
140
|
+
i1 = 0;
|
|
141
|
+
j1 = 1;
|
|
142
|
+
}
|
|
143
|
+
// A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
|
|
144
|
+
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
|
|
145
|
+
// c = (3-sqrt(3))/6
|
|
146
|
+
const x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
|
|
147
|
+
const y1 = y0 - j1 + G2;
|
|
148
|
+
const x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords
|
|
149
|
+
const y2 = y0 - 1 + 2 * G2;
|
|
150
|
+
// Work out the hashed gradient indices of the three simplex corners
|
|
151
|
+
i &= 255;
|
|
152
|
+
j &= 255;
|
|
153
|
+
const gi0 = this.gradP[i + this.perm[j]];
|
|
154
|
+
const gi1 = this.gradP[i + i1 + this.perm[j + j1]];
|
|
155
|
+
const gi2 = this.gradP[i + 1 + this.perm[j + 1]];
|
|
156
|
+
// Calculate the contribution from the three corners
|
|
157
|
+
var t0 = 0.5 - x0 * x0 - y0 * y0;
|
|
158
|
+
if (t0 < 0) {
|
|
159
|
+
n0 = 0;
|
|
160
|
+
} else {
|
|
161
|
+
t0 *= t0;
|
|
162
|
+
n0 = t0 * t0 * gi0.dot2(x0, y0); // (x,y) of grad3 used for 2D gradient
|
|
163
|
+
}
|
|
164
|
+
var t1 = 0.5 - x1 * x1 - y1 * y1;
|
|
165
|
+
if (t1 < 0) {
|
|
166
|
+
n1 = 0;
|
|
167
|
+
} else {
|
|
168
|
+
t1 *= t1;
|
|
169
|
+
n1 = t1 * t1 * gi1.dot2(x1, y1);
|
|
170
|
+
}
|
|
171
|
+
var t2 = 0.5 - x2 * x2 - y2 * y2;
|
|
172
|
+
if (t2 < 0) {
|
|
173
|
+
n2 = 0;
|
|
174
|
+
} else {
|
|
175
|
+
t2 *= t2;
|
|
176
|
+
n2 = t2 * t2 * gi2.dot2(x2, y2);
|
|
177
|
+
}
|
|
178
|
+
// Add contributions from each corner to get the final noise value.
|
|
179
|
+
// The result is scaled to return values in the interval [-1,1].
|
|
180
|
+
return 70 * (n0 + n1 + n2);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 3D simplex noise
|
|
184
|
+
simplex3(xin: number, yin: number, zin: number): number {
|
|
185
|
+
var n0: number, n1: number, n2: number, n3: number; // Noise contributions from the four corners
|
|
186
|
+
|
|
187
|
+
// Skew the input space to determine which simplex cell we're in
|
|
188
|
+
const s: number = (xin + yin + zin) * F3; // Hairy factor for 2D
|
|
189
|
+
var i: number = Math.floor(xin + s);
|
|
190
|
+
var j: number = Math.floor(yin + s);
|
|
191
|
+
var k: number = Math.floor(zin + s);
|
|
192
|
+
|
|
193
|
+
const t: number = (i + j + k) * G3;
|
|
194
|
+
const x0: number = xin - i + t; // The x,y distances from the cell origin, unskewed.
|
|
195
|
+
const y0: number = yin - j + t;
|
|
196
|
+
const z0: number = zin - k + t;
|
|
197
|
+
|
|
198
|
+
// For the 3D case, the simplex shape is a slightly irregular tetrahedron.
|
|
199
|
+
// Determine which simplex we are in.
|
|
200
|
+
var i1: number, j1: number, k1: number; // Offsets for second corner of simplex in (i,j,k) coords
|
|
201
|
+
var i2: number, j2: number, k2: number; // Offsets for third corner of simplex in (i,j,k) coords
|
|
202
|
+
if (x0 >= y0) {
|
|
203
|
+
if (y0 >= z0) {
|
|
204
|
+
i1 = 1;
|
|
205
|
+
j1 = 0;
|
|
206
|
+
k1 = 0;
|
|
207
|
+
i2 = 1;
|
|
208
|
+
j2 = 1;
|
|
209
|
+
k2 = 0;
|
|
210
|
+
} else if (x0 >= z0) {
|
|
211
|
+
i1 = 1;
|
|
212
|
+
j1 = 0;
|
|
213
|
+
k1 = 0;
|
|
214
|
+
i2 = 1;
|
|
215
|
+
j2 = 0;
|
|
216
|
+
k2 = 1;
|
|
217
|
+
} else {
|
|
218
|
+
i1 = 0;
|
|
219
|
+
j1 = 0;
|
|
220
|
+
k1 = 1;
|
|
221
|
+
i2 = 1;
|
|
222
|
+
j2 = 0;
|
|
223
|
+
k2 = 1;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
if (y0 < z0) {
|
|
227
|
+
i1 = 0;
|
|
228
|
+
j1 = 0;
|
|
229
|
+
k1 = 1;
|
|
230
|
+
i2 = 0;
|
|
231
|
+
j2 = 1;
|
|
232
|
+
k2 = 1;
|
|
233
|
+
} else if (x0 < z0) {
|
|
234
|
+
i1 = 0;
|
|
235
|
+
j1 = 1;
|
|
236
|
+
k1 = 0;
|
|
237
|
+
i2 = 0;
|
|
238
|
+
j2 = 1;
|
|
239
|
+
k2 = 1;
|
|
240
|
+
} else {
|
|
241
|
+
i1 = 0;
|
|
242
|
+
j1 = 1;
|
|
243
|
+
k1 = 0;
|
|
244
|
+
i2 = 1;
|
|
245
|
+
j2 = 1;
|
|
246
|
+
k2 = 0;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
|
|
250
|
+
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
|
|
251
|
+
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
|
|
252
|
+
// c = 1/6.
|
|
253
|
+
const x1: number = x0 - i1 + G3; // Offsets for second corner
|
|
254
|
+
const y1: number = y0 - j1 + G3;
|
|
255
|
+
const z1: number = z0 - k1 + G3;
|
|
256
|
+
|
|
257
|
+
const x2: number = x0 - i2 + 2 * G3; // Offsets for third corner
|
|
258
|
+
const y2: number = y0 - j2 + 2 * G3;
|
|
259
|
+
const z2: number = z0 - k2 + 2 * G3;
|
|
260
|
+
|
|
261
|
+
const x3: number = x0 - 1 + 3 * G3; // Offsets for fourth corner
|
|
262
|
+
const y3: number = y0 - 1 + 3 * G3;
|
|
263
|
+
const z3: number = z0 - 1 + 3 * G3;
|
|
264
|
+
|
|
265
|
+
// Work out the hashed gradient indices of the four simplex corners
|
|
266
|
+
i &= 255;
|
|
267
|
+
j &= 255;
|
|
268
|
+
k &= 255;
|
|
269
|
+
const gi0: Grad = this.gradP[i + this.perm[j + this.perm[k]]];
|
|
270
|
+
const gi1: Grad = this.gradP[i + i1 + this.perm[j + j1 + this.perm[k + k1]]];
|
|
271
|
+
const gi2: Grad = this.gradP[i + i2 + this.perm[j + j2 + this.perm[k + k2]]];
|
|
272
|
+
const gi3: Grad = this.gradP[i + 1 + this.perm[j + 1 + this.perm[k + 1]]];
|
|
273
|
+
|
|
274
|
+
// Calculate the contribution from the four corners
|
|
275
|
+
var t0: number = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;
|
|
276
|
+
if (t0 < 0) {
|
|
277
|
+
n0 = 0;
|
|
278
|
+
} else {
|
|
279
|
+
t0 *= t0;
|
|
280
|
+
n0 = t0 * t0 * gi0.dot3(x0, y0, z0); // (x,y) of grad3 used for 2D gradient
|
|
281
|
+
}
|
|
282
|
+
var t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;
|
|
283
|
+
if (t1 < 0) {
|
|
284
|
+
n1 = 0;
|
|
285
|
+
} else {
|
|
286
|
+
t1 *= t1;
|
|
287
|
+
n1 = t1 * t1 * gi1.dot3(x1, y1, z1);
|
|
288
|
+
}
|
|
289
|
+
var t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;
|
|
290
|
+
if (t2 < 0) {
|
|
291
|
+
n2 = 0;
|
|
292
|
+
} else {
|
|
293
|
+
t2 *= t2;
|
|
294
|
+
n2 = t2 * t2 * gi2.dot3(x2, y2, z2);
|
|
295
|
+
}
|
|
296
|
+
var t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;
|
|
297
|
+
if (t3 < 0) {
|
|
298
|
+
n3 = 0;
|
|
299
|
+
} else {
|
|
300
|
+
t3 *= t3;
|
|
301
|
+
n3 = t3 * t3 * gi3.dot3(x3, y3, z3);
|
|
302
|
+
}
|
|
303
|
+
// Add contributions from each corner to get the final noise value.
|
|
304
|
+
// The result is scaled to return values in the interval [-1,1].
|
|
305
|
+
return 32 * (n0 + n1 + n2 + n3);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// 2D Perlin Noise
|
|
309
|
+
perlin2(x_init: number, y_init: number): number {
|
|
310
|
+
// Find unit grid cell containing point
|
|
311
|
+
var X: number = Math.floor(x_init),
|
|
312
|
+
Y: number = Math.floor(y_init);
|
|
313
|
+
// Get relative xy coordinates of point within that cell
|
|
314
|
+
const x: number = x_init - X;
|
|
315
|
+
const y: number = y_init - Y;
|
|
316
|
+
// Wrap the integer cells at 255 (smaller integer period can be introduced here)
|
|
317
|
+
X = X & 255;
|
|
318
|
+
Y = Y & 255;
|
|
319
|
+
|
|
320
|
+
// Calculate noise contributions from each of the four corners
|
|
321
|
+
const n00: number = this.gradP[X + this.perm[Y]].dot2(x, y);
|
|
322
|
+
const n01: number = this.gradP[X + this.perm[Y + 1]].dot2(x, y - 1);
|
|
323
|
+
const n10: number = this.gradP[X + 1 + this.perm[Y]].dot2(x - 1, y);
|
|
324
|
+
const n11: number = this.gradP[X + 1 + this.perm[Y + 1]].dot2(x - 1, y - 1);
|
|
325
|
+
|
|
326
|
+
// Compute the fade curve value for x
|
|
327
|
+
const u: number = fade(x);
|
|
328
|
+
|
|
329
|
+
// Interpolate the four results
|
|
330
|
+
return lerp(lerp(n00, n10, u), lerp(n01, n11, u), fade(y));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// 3D Perlin Noise
|
|
334
|
+
perlin3(x_init: number, y_init: number, z_init: number): number {
|
|
335
|
+
// Find unit grid cell containing point
|
|
336
|
+
var X: number = Math.floor(x_init),
|
|
337
|
+
Y: number = Math.floor(y_init),
|
|
338
|
+
Z: number = Math.floor(z_init);
|
|
339
|
+
// Get relative xyz coordinates of point within that cell
|
|
340
|
+
const x: number = x_init - X;
|
|
341
|
+
const y: number = y_init - Y;
|
|
342
|
+
const z: number = z_init - Z;
|
|
343
|
+
// Wrap the integer cells at 255 (smaller integer period can be introduced here)
|
|
344
|
+
X = X & 255;
|
|
345
|
+
Y = Y & 255;
|
|
346
|
+
Z = Z & 255;
|
|
347
|
+
|
|
348
|
+
// Calculate noise contributions from each of the eight corners
|
|
349
|
+
const n000: number = this.gradP[X + this.perm[Y + this.perm[Z]]].dot3(x, y, z);
|
|
350
|
+
const n001: number = this.gradP[X + this.perm[Y + this.perm[Z + 1]]].dot3(x, y, z - 1);
|
|
351
|
+
const n010: number = this.gradP[X + this.perm[Y + 1 + this.perm[Z]]].dot3(x, y - 1, z);
|
|
352
|
+
const n011: number = this.gradP[X + this.perm[Y + 1 + this.perm[Z + 1]]].dot3(x, y - 1, z - 1);
|
|
353
|
+
const n100: number = this.gradP[X + 1 + this.perm[Y + this.perm[Z]]].dot3(x - 1, y, z);
|
|
354
|
+
const n101: number = this.gradP[X + 1 + this.perm[Y + this.perm[Z + 1]]].dot3(x - 1, y, z - 1);
|
|
355
|
+
const n110: number = this.gradP[X + 1 + this.perm[Y + 1 + this.perm[Z]]].dot3(x - 1, y - 1, z);
|
|
356
|
+
const n111: number = this.gradP[X + 1 + this.perm[Y + 1 + this.perm[Z + 1]]].dot3(x - 1, y - 1, z - 1);
|
|
357
|
+
|
|
358
|
+
// Compute the fade curve value for x, y, z
|
|
359
|
+
const u: number = fade(x);
|
|
360
|
+
const v: number = fade(y);
|
|
361
|
+
const w: number = fade(z);
|
|
362
|
+
|
|
363
|
+
// Interpolate
|
|
364
|
+
return lerp(lerp(lerp(n000, n100, u), lerp(n001, n101, u), w), lerp(lerp(n010, n110, u), lerp(n011, n111, u), w), v);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// noise.seed(0);
|