figureone 0.15.10 → 1.0.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/figureone.min.js +1 -1
- package/index.js +79167 -0
- package/package.json +15 -1
- package/types/index.d.ts +132 -0
- package/types/js/figure/Animation/Animation.d.ts +36 -0
- package/types/js/figure/Animation/AnimationBuilder.d.ts +173 -0
- package/types/js/figure/Animation/AnimationManager.d.ts +392 -0
- package/types/js/figure/Animation/AnimationStep/CustomStep.d.ts +99 -0
- package/types/js/figure/Animation/AnimationStep/DelayStep.d.ts +24 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ColorAnimationStep.d.ts +203 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/OpacityAnimationStep.d.ts +220 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PositionAnimationStep.d.ts +124 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseAnimationStep.d.ts +137 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseTransformAnimationStep.d.ts +52 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/RotationAnimationStep.d.ts +119 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScaleAnimationStep.d.ts +93 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScenarioAnimationStep.d.ts +204 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/TransformAnimationStep.d.ts +163 -0
- package/types/js/figure/Animation/AnimationStep/ElementAnimationStep.d.ts +56 -0
- package/types/js/figure/Animation/AnimationStep/ParallelAnimationStep.d.ts +70 -0
- package/types/js/figure/Animation/AnimationStep/SerialAnimationStep.d.ts +84 -0
- package/types/js/figure/Animation/AnimationStep/TriggerStep.d.ts +106 -0
- package/types/js/figure/Animation/AnimationStep.d.ts +110 -0
- package/types/js/figure/DrawContext2D.d.ts +9 -0
- package/types/js/figure/DrawingObjects/DrawingObject.d.ts +45 -0
- package/types/js/figure/DrawingObjects/GLObject/GLObject.d.ts +146 -0
- package/types/js/figure/DrawingObjects/HTMLObject/HTMLObject.d.ts +29 -0
- package/types/js/figure/DrawingObjects/TextObject/TextObject.d.ts +94 -0
- package/types/js/figure/DrawingObjects/TextObject/glyphMeasures.d.ts +7 -0
- package/types/js/figure/DrawingObjects/VertexObject/VertexGeneric.d.ts +21 -0
- package/types/js/figure/DrawingObjects/VertexObject/VertexObject.d.ts +0 -0
- package/types/js/figure/DrawingObjects/VertexObject/VertexText.d.ts +34 -0
- package/types/js/figure/Element.d.ts +1212 -0
- package/types/js/figure/Equation/Elements/BaseAnnotationFunction.d.ts +118 -0
- package/types/js/figure/Equation/Elements/BaseEquationFunction.d.ts +20 -0
- package/types/js/figure/Equation/Elements/Bounds.d.ts +49 -0
- package/types/js/figure/Equation/Elements/Color.d.ts +7 -0
- package/types/js/figure/Equation/Elements/Container.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Element.d.ts +95 -0
- package/types/js/figure/Equation/Elements/Fraction.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Lines.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Matrix.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Offset.d.ts +5 -0
- package/types/js/figure/Equation/Elements/Scale.d.ts +5 -0
- package/types/js/figure/Equation/Equation.d.ts +984 -0
- package/types/js/figure/Equation/EquationForm.d.ts +139 -0
- package/types/js/figure/Equation/EquationFunctions.d.ts +3367 -0
- package/types/js/figure/Equation/EquationSymbols.d.ts +1646 -0
- package/types/js/figure/Equation/HTMLEquation.d.ts +56 -0
- package/types/js/figure/Equation/Symbols/AngleBracket.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Arrow.d.ts +17 -0
- package/types/js/figure/Equation/Symbols/Bar.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Box.d.ts +11 -0
- package/types/js/figure/Equation/Symbols/Brace.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Bracket.d.ts +8 -0
- package/types/js/figure/Equation/Symbols/Division.d.ts +8 -0
- package/types/js/figure/Equation/Symbols/Integral.d.ts +7 -0
- package/types/js/figure/Equation/Symbols/Line.d.ts +5 -0
- package/types/js/figure/Equation/Symbols/Product.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Radical.d.ts +9 -0
- package/types/js/figure/Equation/Symbols/SquareBracket.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/Strike.d.ts +8 -0
- package/types/js/figure/Equation/Symbols/Sum.d.ts +6 -0
- package/types/js/figure/Equation/Symbols/SymbolNew.d.ts +15 -0
- package/types/js/figure/Equation/Symbols/Vinculum.d.ts +6 -0
- package/types/js/figure/Figure.d.ts +711 -0
- package/types/js/figure/FigureCollections/Angle.d.ts +766 -0
- package/types/js/figure/FigureCollections/Axis.d.ts +517 -0
- package/types/js/figure/FigureCollections/Axis3.d.ts +118 -0
- package/types/js/figure/FigureCollections/Button.d.ts +195 -0
- package/types/js/figure/FigureCollections/EquationLabel.d.ts +77 -0
- package/types/js/figure/FigureCollections/FigureCollections.d.ts +122 -0
- package/types/js/figure/FigureCollections/Legend.d.ts +270 -0
- package/types/js/figure/FigureCollections/Line.d.ts +587 -0
- package/types/js/figure/FigureCollections/Plot.d.ts +558 -0
- package/types/js/figure/FigureCollections/PolyLine.d.ts +487 -0
- package/types/js/figure/FigureCollections/Rectangle.d.ts +235 -0
- package/types/js/figure/FigureCollections/SlideNavigator.d.ts +255 -0
- package/types/js/figure/FigureCollections/Slider.d.ts +155 -0
- package/types/js/figure/FigureCollections/Text.d.ts +307 -0
- package/types/js/figure/FigureCollections/Toggle.d.ts +185 -0
- package/types/js/figure/FigureCollections/Trace.d.ts +237 -0
- package/types/js/figure/FigurePrimitives/FigureElementPrimitive2DText.d.ts +119 -0
- package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGLText.d.ts +94 -0
- package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGesture.d.ts +536 -0
- package/types/js/figure/FigurePrimitives/FigureElementPrimitiveMorph.d.ts +175 -0
- package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes.d.ts +788 -0
- package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes2D.d.ts +1324 -0
- package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes3D.d.ts +1105 -0
- package/types/js/figure/FigurePrimitives/FigurePrimitives.d.ts +173 -0
- package/types/js/figure/FigurePrimitives/Generic.d.ts +5 -0
- package/types/js/figure/FigurePrimitives/Text.d.ts +17 -0
- package/types/js/figure/FontManager.d.ts +113 -0
- package/types/js/figure/Gesture.d.ts +39 -0
- package/types/js/figure/Recorder/Recorder.d.ts +291 -0
- package/types/js/figure/Recorder/parseState.d.ts +3 -0
- package/types/js/figure/Recorder/recorder.worker.d.ts +1 -0
- package/types/js/figure/Recorder/state.d.ts +7 -0
- package/types/js/figure/SlideNavigator.d.ts +606 -0
- package/types/js/figure/TimeKeeper.d.ts +174 -0
- package/types/js/figure/geometries/arc.d.ts +18 -0
- package/types/js/figure/geometries/arrow.d.ts +215 -0
- package/types/js/figure/geometries/buffer.d.ts +4 -0
- package/types/js/figure/geometries/copy/copy.d.ts +178 -0
- package/types/js/figure/geometries/ellipse.d.ts +17 -0
- package/types/js/figure/geometries/line.d.ts +13 -0
- package/types/js/figure/geometries/lines/corners.d.ts +7 -0
- package/types/js/figure/geometries/lines/dashes.d.ts +23 -0
- package/types/js/figure/geometries/lines/lines.d.ts +31 -0
- package/types/js/figure/geometries/polygon/polygon.d.ts +12 -0
- package/types/js/figure/geometries/rectangle.d.ts +19 -0
- package/types/js/figure/geometries/triangle.d.ts +27 -0
- package/types/js/figure/webgl/Atlas.d.ts +42 -0
- package/types/js/figure/webgl/shaders.d.ts +143 -0
- package/types/js/figure/webgl/target.d.ts +9 -0
- package/types/js/figure/webgl/webgl.d.ts +54 -0
- package/types/js/tools/FunctionMap.d.ts +69 -0
- package/types/js/tools/color.d.ts +11 -0
- package/types/js/tools/colorNames.d.ts +2 -0
- package/types/js/tools/d2/polygon.d.ts +60 -0
- package/types/js/tools/d2/triangles.d.ts +0 -0
- package/types/js/tools/d3/cone.d.ts +57 -0
- package/types/js/tools/d3/cube.d.ts +26 -0
- package/types/js/tools/d3/cylinder.d.ts +45 -0
- package/types/js/tools/d3/line3.d.ts +55 -0
- package/types/js/tools/d3/prism.d.ts +49 -0
- package/types/js/tools/d3/revolve.d.ts +87 -0
- package/types/js/tools/d3/sphere.d.ts +33 -0
- package/types/js/tools/d3/surface.d.ts +47 -0
- package/types/js/tools/g2.d.ts +242 -0
- package/types/js/tools/geometry/Bounds.d.ts +446 -0
- package/types/js/tools/geometry/Line.d.ts +314 -0
- package/types/js/tools/geometry/Path.d.ts +67 -0
- package/types/js/tools/geometry/Plane.d.ts +201 -0
- package/types/js/tools/geometry/Point.d.ts +359 -0
- package/types/js/tools/geometry/Rect.d.ts +115 -0
- package/types/js/tools/geometry/Transform.d.ts +623 -0
- package/types/js/tools/geometry/angle.d.ts +105 -0
- package/types/js/tools/geometry/common.d.ts +9 -0
- package/types/js/tools/geometry/coordinates.d.ts +30 -0
- package/types/js/tools/geometry/deceleration.d.ts +13 -0
- package/types/js/tools/geometry/polygon.d.ts +4 -0
- package/types/js/tools/geometry/quaternion.d.ts +15 -0
- package/types/js/tools/geometry/scene.d.ts +282 -0
- package/types/js/tools/geometry/tools.d.ts +8 -0
- package/types/js/tools/geometry/types.d.ts +2 -0
- package/types/js/tools/getCssColors.d.ts +1 -0
- package/types/js/tools/getCssVariables.d.ts +4 -0
- package/types/js/tools/getImageData.d.ts +1 -0
- package/types/js/tools/getScssColors.d.ts +2 -0
- package/types/js/tools/htmlGenerator.d.ts +85 -0
- package/types/js/tools/m2.d.ts +24 -0
- package/types/js/tools/m3.d.ts +71 -0
- package/types/js/tools/math.d.ts +112 -0
- package/types/js/tools/morph.d.ts +651 -0
- package/types/js/tools/styleSheets.d.ts +3 -0
- package/types/js/tools/tools.d.ts +281 -0
- package/types/js/tools/types.d.ts +305 -0
- package/figureone.worker.js +0 -1
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
import type { TypeColor } from './types';
|
|
2
|
+
import { Point } from './g2';
|
|
3
|
+
import type { TypeParsablePoint } from './g2';
|
|
4
|
+
import type { TypeHAlign, TypeVAlign } from '../figure/Equation/EquationForm';
|
|
5
|
+
declare function getPixels(data: Uint8ClampedArray, imageWidth: number, imageHeight: number, filter: (color: TypeColor, position: [number, number]) => boolean): {
|
|
6
|
+
max: number[];
|
|
7
|
+
min: number[];
|
|
8
|
+
pixels: number[][];
|
|
9
|
+
pixelColors: number[][];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @property {Image} [image]
|
|
13
|
+
* @property {number | null} [num] maximum number of shapes to return -
|
|
14
|
+
* `null` defaults to the number of pixels (or filtered pixels if a filter is
|
|
15
|
+
* used) (`null`)
|
|
16
|
+
* @property {'repeatOpaqueOnly' | 'lastOpaque' | 'repeat'} [excess] if
|
|
17
|
+
* num is greater than the number of pixels, then either `'repeat'` the
|
|
18
|
+
* shapes from all the pixels again, repeat the shapes from only the opaque
|
|
19
|
+
* pixels `'repeatOpaqueOnly'` or put all execess shapes on the `'lastOpaque'`
|
|
20
|
+
* pixel. Note, repeating pixels that are semitransparent will effectively put
|
|
21
|
+
* multiple pixels on top of each other, reducing the transparency of the pixel
|
|
22
|
+
* (`'repeatOpaqueOnly'`).
|
|
23
|
+
* @property {function(TypeColor, [number, number]) => boolean} [filter]
|
|
24
|
+
* filter function with pixel color and pixel position input parameters. Return
|
|
25
|
+
* `true` to keep pixel. Pixel position is (0, 0) in top left corner and
|
|
26
|
+
* (pixelsWidth, pixelsHeight) in the bottom right (`() => true`)
|
|
27
|
+
* @property {'raster' | 'random'} [distribution] Returned shapes are randomly
|
|
28
|
+
* distributed throughout shape (`'random'`) or rasterized in order from top
|
|
29
|
+
* left to bottom right of image (or filtered image) (`random`)
|
|
30
|
+
* @property {number | null} [width] width to map image pixels to. Width is
|
|
31
|
+
* between center of most left to most right pixels
|
|
32
|
+
* @property {number | null} [height] height to map image pixels to. Height is
|
|
33
|
+
* between center of most bottom to most top pixels
|
|
34
|
+
* @property {number} [size] shape size to map pixel to. Final points will
|
|
35
|
+
* have a width of `width + size` center of points are used to determine
|
|
36
|
+
* `width` and `height`. Default shape is a square, and default size
|
|
37
|
+
* (if left undefined) is the size needed to make adjacent square shapes
|
|
38
|
+
* touch
|
|
39
|
+
* @property {TypeParsablePoint} [position] position to place shapes at
|
|
40
|
+
* @property {TypeHAlign} [xAlign] align shapes horizontally around `position`
|
|
41
|
+
* @property {TypeVAlign} [yAlign] align shapes vertically around `position`
|
|
42
|
+
* @property {'image' | 'filteredImage'} [align] `image` will align the shapes
|
|
43
|
+
* as if there were no pixels filtered out. `filteredImage` will align to only
|
|
44
|
+
* the shapes that exist.
|
|
45
|
+
* @property {number} [dither] Add a random offset to each shape to create a
|
|
46
|
+
* dither effect
|
|
47
|
+
* @property {function(Point, number): Array<number> | number} [shape]
|
|
48
|
+
* By default a square of two triangles is created (six vertices). Use a
|
|
49
|
+
* `number` to create a regular polygon with `number` sides. Use a custom
|
|
50
|
+
* function to make a custom shape. The function takes as input the [x, y]
|
|
51
|
+
* position of the point to build the shape around, and `size`. It outputs an
|
|
52
|
+
* array of interlaced x and y coordinates of triangle vertices - i.e.:
|
|
53
|
+
* [x1, y1, x2, y2, x3, y3, ....]
|
|
54
|
+
* @property {function(TypeColor, number): Array<number>} [makeColors]
|
|
55
|
+
* use this function to customze color mapping. The function takes as input the
|
|
56
|
+
* pixel's color, and the number of vertices that need to be colored. It
|
|
57
|
+
* outputs an array of colors for each vertex - i.e.:
|
|
58
|
+
* [r1, b1, g1, a1, r2, g2, b, a2, ...]
|
|
59
|
+
* @interface
|
|
60
|
+
* @group Morphing
|
|
61
|
+
*/
|
|
62
|
+
export type OBJ_ImageToShapes = {
|
|
63
|
+
image: HTMLImageElement;
|
|
64
|
+
maxPoints?: number | null;
|
|
65
|
+
xAlign?: TypeHAlign;
|
|
66
|
+
yAlign?: TypeVAlign;
|
|
67
|
+
align?: 'image' | 'filteredImage';
|
|
68
|
+
distribution?: 'raster' | 'random';
|
|
69
|
+
filter?: 'none' | Array<number>;
|
|
70
|
+
position?: TypeParsablePoint;
|
|
71
|
+
dither?: number;
|
|
72
|
+
width?: number | null;
|
|
73
|
+
height?: number | null;
|
|
74
|
+
size?: number;
|
|
75
|
+
excess?: 'repeatOpaqueOnly' | 'lastOpaque' | 'repeat';
|
|
76
|
+
makeColors?: (color: TypeColor, num: number) => Array<number>;
|
|
77
|
+
shape?: number | ((center: Point, size: number) => Array<number>);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* `imageToShapes` maps the pixels of an image to shapes that will be
|
|
81
|
+
* used to draw those pixels.
|
|
82
|
+
*
|
|
83
|
+
* 
|
|
84
|
+
*
|
|
85
|
+
* 
|
|
86
|
+
*
|
|
87
|
+
* All pixels in an image can be made shapes, or a `filter` function can be used
|
|
88
|
+
* to only use desired pixels.
|
|
89
|
+
*
|
|
90
|
+
* The shapes can be rasterized in order (raster from top left to bottom
|
|
91
|
+
* right) or be in a random order.
|
|
92
|
+
*
|
|
93
|
+
* The image pixel centers are mapped to some `width` and `height` and aligned
|
|
94
|
+
* to a position relative to either all pixels in the original image, or just
|
|
95
|
+
* the filtered pixels. The shapes are centered on the pixel centers.
|
|
96
|
+
*
|
|
97
|
+
* This method is useful for including images in morphing effects. It should
|
|
98
|
+
* not be used to simply show an image (use a texture with some
|
|
99
|
+
* FigureElementPrimitive for this).
|
|
100
|
+
*
|
|
101
|
+
* @param {OBJ_ImageToShapes} options
|
|
102
|
+
* @return {[Array<number>, Array<number>]} [vertices, colors]
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const { imageToShapes, rectangleCloudShapes } = Fig.morph;
|
|
106
|
+
*
|
|
107
|
+
* const image = new Image();
|
|
108
|
+
* image.src = './logo.png';
|
|
109
|
+
* image.onload = () => {
|
|
110
|
+
* const [logo, logoColors] = imageToShapes({
|
|
111
|
+
* image,
|
|
112
|
+
* width: 0.7,
|
|
113
|
+
* height: 0.7,
|
|
114
|
+
* filter: c => c[3] > 0,
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* const cloud = rectangleCloudShapes({
|
|
118
|
+
* width: 2,
|
|
119
|
+
* height: 2,
|
|
120
|
+
* num: logo.length / 2 / 6,
|
|
121
|
+
* });
|
|
122
|
+
*
|
|
123
|
+
* const m = figure.add({
|
|
124
|
+
* make: 'morph',
|
|
125
|
+
* points: [cloud, logo],
|
|
126
|
+
* color: [logoColors, logoColors],
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* m.animations.new()
|
|
130
|
+
* .delay(1)
|
|
131
|
+
* .morph({ start: 0, target: 1, duration: 2 })
|
|
132
|
+
* .start();
|
|
133
|
+
* };
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const { imageToShapes } = Fig.morph;
|
|
137
|
+
*
|
|
138
|
+
* const micImage = new Image();
|
|
139
|
+
* micImage.src = './mic.png';
|
|
140
|
+
* const headphonesImage = new Image();
|
|
141
|
+
* headphonesImage.src = './headphones.png';
|
|
142
|
+
*
|
|
143
|
+
* let index = 0;
|
|
144
|
+
* const loaded = () => {
|
|
145
|
+
* index += 1;
|
|
146
|
+
* if (index < 2) {
|
|
147
|
+
* return;
|
|
148
|
+
* }
|
|
149
|
+
*
|
|
150
|
+
* const [mic, micColors] = imageToShapes({
|
|
151
|
+
* image: micImage,
|
|
152
|
+
* width: 0.7,
|
|
153
|
+
* filter: c => c[3] > 0,
|
|
154
|
+
* });
|
|
155
|
+
*
|
|
156
|
+
* const [headphones, headphoneColors] = imageToShapes({
|
|
157
|
+
* image: headphonesImage,
|
|
158
|
+
* width: 0.7,
|
|
159
|
+
* filter: c => c[3] > 0,
|
|
160
|
+
* num: mic.length / 6 / 2,
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* const m = figure.add({
|
|
164
|
+
* make: 'morph',
|
|
165
|
+
* points: [mic, headphones],
|
|
166
|
+
* color: [micColors, headphoneColors],
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* m.animations.new()
|
|
170
|
+
* .delay(1)
|
|
171
|
+
* .morph({ start: 0, target: 1, duration: 2 })
|
|
172
|
+
* .start();
|
|
173
|
+
* };
|
|
174
|
+
*
|
|
175
|
+
* micImage.onload = loaded.bind(this);
|
|
176
|
+
* headphonesImage.onload = loaded.bind(this);
|
|
177
|
+
* @group Morphing
|
|
178
|
+
*/
|
|
179
|
+
declare function imageToShapes(options: OBJ_ImageToShapes): number[][];
|
|
180
|
+
/**
|
|
181
|
+
* Options obect for {@link polylineToShapes} that evenly distributes shapes
|
|
182
|
+
* along a line
|
|
183
|
+
*
|
|
184
|
+
* @property {Array<TypeParsablePoint>} points array of points representing a
|
|
185
|
+
* polyline where each point is a corner in the line
|
|
186
|
+
* @property {number} num number of shapes to distribute along line
|
|
187
|
+
* @property {boolean} close `true` closes the polyline
|
|
188
|
+
* @property {number} size size of shape
|
|
189
|
+
* @property {function(Point, number): Array<number> | number} [shape]
|
|
190
|
+
* By default a square of two triangles is created (six vertices). Use a
|
|
191
|
+
* `number` to create a regular polygon with `number` sides. Use a custom
|
|
192
|
+
* function to make a custom shape. The function takes as input the [x, y]
|
|
193
|
+
* position of the point to build the shape around, and `size`. It outputs an
|
|
194
|
+
* array of interlaced x and y coordinates of triangle vertices - i.e.:
|
|
195
|
+
* [x1, y1, x2, y2, x3, y3, ....]
|
|
196
|
+
* @property {function(number, Point, number, number, number): Array<number>} makeColors
|
|
197
|
+
* function that creates colors for each vertex of the shape.
|
|
198
|
+
* Function input parameters are the number of shape vertices to be colored,
|
|
199
|
+
* the center point coordinate, the previous polyline point index, the
|
|
200
|
+
* cumulative length from the start of the polyline, and the percentLength from
|
|
201
|
+
* the start of the polyline. The function must return a single array
|
|
202
|
+
* containing all vertex colors.
|
|
203
|
+
* @interface
|
|
204
|
+
* @group Morphing
|
|
205
|
+
*/
|
|
206
|
+
export type OBJ_PolylineToShapes = {
|
|
207
|
+
points: Array<TypeParsablePoint>;
|
|
208
|
+
num?: number;
|
|
209
|
+
close?: boolean;
|
|
210
|
+
size?: number;
|
|
211
|
+
shape?: number | ((center: Point, size: number) => Array<number>);
|
|
212
|
+
makeColors?: (num: number, center: Point, cumDist: number, percentDist: number, index: number) => Array<number>;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* `polylineToShapes` distributes a number of shapes equally along a polyline.
|
|
216
|
+
*
|
|
217
|
+
* 
|
|
218
|
+
*
|
|
219
|
+
* 
|
|
220
|
+
*
|
|
221
|
+
* 
|
|
222
|
+
*
|
|
223
|
+
* The polyline is defined by an array of points, where each point is a corner
|
|
224
|
+
* in the polyline
|
|
225
|
+
*
|
|
226
|
+
* The start and ends of the polyline each have a centered shape
|
|
227
|
+
*
|
|
228
|
+
* The polyline can be closed or open.
|
|
229
|
+
*
|
|
230
|
+
* This method is useful for morphing between shapes.
|
|
231
|
+
*
|
|
232
|
+
* @param {OBJ_PolylineToShapes} options
|
|
233
|
+
* @return {[Array<number>, Array<number>]} [vertices, colors]
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* const { polylineToShapes, getPolygonCorners } = Fig.morph;
|
|
237
|
+
*
|
|
238
|
+
* const [square] = polylineToShapes({
|
|
239
|
+
* points: [[0.5, 0], [0, 0.5], [-0.5, 0], [0, -0.5]],
|
|
240
|
+
* num: 50,
|
|
241
|
+
* size: 0.03,
|
|
242
|
+
* close: true,
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
*
|
|
246
|
+
* const [circle] = polylineToShapes({
|
|
247
|
+
* points: getPolygonCorners({ radius: 0.5, sides: 30 }),
|
|
248
|
+
* num: 50,
|
|
249
|
+
* size: 0.03,
|
|
250
|
+
* close: true,
|
|
251
|
+
* });
|
|
252
|
+
*
|
|
253
|
+
* const m = figure.add({
|
|
254
|
+
* make: 'morph',
|
|
255
|
+
* points: [square, circle],
|
|
256
|
+
* color: [1, 0, 0, 1],
|
|
257
|
+
* });
|
|
258
|
+
*
|
|
259
|
+
* m.animations.new()
|
|
260
|
+
* .morph({ start:0, target: 1, duration: 2 })
|
|
261
|
+
* .start();
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* const { polylineToShapes, getPolygonCorners } = Fig.morph;
|
|
265
|
+
*
|
|
266
|
+
* const [square] = polylineToShapes({
|
|
267
|
+
* points: [[-0.5, 0], [0.5, 0]],
|
|
268
|
+
* num: 500,
|
|
269
|
+
* size: 0.02,
|
|
270
|
+
* shape: 'hex',
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* const [circle] = polylineToShapes({
|
|
274
|
+
* points: getPolygonCorners({ radius: 0.5, sides: 6, rotation: Math.PI / 2 }),
|
|
275
|
+
* num: 500,
|
|
276
|
+
* size: 0.02,
|
|
277
|
+
* close: true,
|
|
278
|
+
* shape: 'hex',
|
|
279
|
+
* });
|
|
280
|
+
*
|
|
281
|
+
* const m = figure.add({
|
|
282
|
+
* make: 'morph',
|
|
283
|
+
* points: [square, circle],
|
|
284
|
+
* color: [1, 0, 0, 1],
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
* m.animations.new()
|
|
288
|
+
* .morph({ start:0, target: 1, duration: 2 })
|
|
289
|
+
* .start();
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* const { polylineToShapes, getPolygonCorners } = Fig.morph;
|
|
293
|
+
*
|
|
294
|
+
* const [square] = polylineToShapes({
|
|
295
|
+
* points: getPolygonCorners({ radius: 0.5, sides: 4, rotation: Math.PI / 4 }),
|
|
296
|
+
* num: 500,
|
|
297
|
+
* close: true,
|
|
298
|
+
* });
|
|
299
|
+
*
|
|
300
|
+
* const [circle] = polylineToShapes({
|
|
301
|
+
* points: getPolygonCorners({ radius: 0.25, sides: 100, rotation: Math.PI / 4 }),
|
|
302
|
+
* num: 500,
|
|
303
|
+
* close: true,
|
|
304
|
+
* });
|
|
305
|
+
*
|
|
306
|
+
* for (let i = 0; i < 10; i += 1) {
|
|
307
|
+
* const m = figure.add({
|
|
308
|
+
* make: 'morph',
|
|
309
|
+
* points: [square, circle],
|
|
310
|
+
* position: [0.2 - i / 30, 0.2 - i / 30],
|
|
311
|
+
* color: [1 - i / 10, 0, i / 10, 1],
|
|
312
|
+
* });
|
|
313
|
+
*
|
|
314
|
+
* m.animations.new()
|
|
315
|
+
* .delay(2 - i / 10)
|
|
316
|
+
* .morph({ start: 0, target: 1, duration: 2 })
|
|
317
|
+
* .delay(2)
|
|
318
|
+
* .morph({ start: 1, target: 0, duration: 2 })
|
|
319
|
+
* .start();
|
|
320
|
+
* }
|
|
321
|
+
* @group Morphing
|
|
322
|
+
*/
|
|
323
|
+
declare function polylineToShapes(options: OBJ_PolylineToShapes): number[][];
|
|
324
|
+
/**
|
|
325
|
+
* Options obect for {@link pointsToShapes} that creates a shape at each point
|
|
326
|
+
*
|
|
327
|
+
* @property {Array<TypeParsablePoint>} points array of points to create shapes
|
|
328
|
+
* at
|
|
329
|
+
* @property {number} size size of shape
|
|
330
|
+
* @property {function(Point, number): Array<number> | number} [shape]
|
|
331
|
+
* By default a square of two triangles is created (six vertices). Use a
|
|
332
|
+
* `number` to create a regular polygon with `number` sides. Use a custom
|
|
333
|
+
* function to make a custom shape. The function takes as input the [x, y]
|
|
334
|
+
* position of the point to build the shape around, and `size`. It outputs an
|
|
335
|
+
* array of interlaced x and y coordinates of triangle vertices - i.e.:
|
|
336
|
+
* [x1, y1, x2, y2, x3, y3, ....]
|
|
337
|
+
* @property {function(number, Point): Array<number>} makeColors
|
|
338
|
+
* function that creates colors for each vertex of the shape.
|
|
339
|
+
* Function input parameters are the number of shape vertices to be colored,
|
|
340
|
+
* and the position of the shape. The function must return a single array
|
|
341
|
+
* containing all vertex colors.
|
|
342
|
+
* @interface
|
|
343
|
+
* @group Morphing
|
|
344
|
+
*/
|
|
345
|
+
export type OBJ_PointsToShapes = {
|
|
346
|
+
points: Array<TypeParsablePoint>;
|
|
347
|
+
size?: number;
|
|
348
|
+
shape?: number | ((center: Point, size: number) => Array<number>);
|
|
349
|
+
makeColors?: (num: number, center: Point, cumDist: number, percentDist: number, index: number) => Array<number>;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* `pointsToShapes` creates shapes at each point input.
|
|
353
|
+
*
|
|
354
|
+
* 
|
|
355
|
+
*
|
|
356
|
+
* This method is useful for morphing between shapes.
|
|
357
|
+
*
|
|
358
|
+
* @param {OBJ_PointsToShapes} options
|
|
359
|
+
* @return {[Array<number>, Array<number>]} [vertices, colors]
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* const { pointsToShapes } = Fig.morph;
|
|
363
|
+
*
|
|
364
|
+
* const xValues = Fig.range(-0.8, 0.8, 0.001);
|
|
365
|
+
* const sinc = (xIn, a, b, c) => {
|
|
366
|
+
* const x = (xIn + c) === 0 ? 0.00001 : xIn + c;
|
|
367
|
+
* return a * Math.sin(b * x) / (b * x);
|
|
368
|
+
* };
|
|
369
|
+
*
|
|
370
|
+
* const [trace1] = pointsToShapes({
|
|
371
|
+
* points: xValues.map(x => [x, sinc(x, 0.5, 20, 0)]),
|
|
372
|
+
* shape: 'hex',
|
|
373
|
+
* });
|
|
374
|
+
*
|
|
375
|
+
* const [trace2] = pointsToShapes({
|
|
376
|
+
* points: xValues.map(x => [x, 0.4 * Math.sin(x * 2 * Math.PI / 0.5)]),
|
|
377
|
+
* shape: 'hex',
|
|
378
|
+
* });
|
|
379
|
+
*
|
|
380
|
+
* const m = figure.add({
|
|
381
|
+
* make: 'morph',
|
|
382
|
+
* points: [trace1, trace2],
|
|
383
|
+
* color: [1, 0, 0, 1],
|
|
384
|
+
* });
|
|
385
|
+
*
|
|
386
|
+
* m.animations.new()
|
|
387
|
+
* .morph({ start: 0, target: 1, duration: 2 })
|
|
388
|
+
* .start();
|
|
389
|
+
* @group Morphing
|
|
390
|
+
*/
|
|
391
|
+
declare function pointsToShapes(options: OBJ_PointsToShapes): number[][];
|
|
392
|
+
/**
|
|
393
|
+
* Options object for `polyline` in morph tools.
|
|
394
|
+
*
|
|
395
|
+
* @property {Array<TypeParsablePoint>} points points that define the polyline
|
|
396
|
+
* @property {number | null} [num] split the polyline into `num` equal
|
|
397
|
+
* segments. Use `null` or leave undefined to not split the polyline
|
|
398
|
+
* @property {boolean} [close] `true` to close the polyline
|
|
399
|
+
* @property {number} [width] width of the polyline
|
|
400
|
+
* @property {boolean} [simple] `false` fills corners.
|
|
401
|
+
* @interface
|
|
402
|
+
* @group Misc Morphing
|
|
403
|
+
*/
|
|
404
|
+
export type OBJ_MorphPolyline = {
|
|
405
|
+
points: Array<TypeParsablePoint>;
|
|
406
|
+
num?: number;
|
|
407
|
+
close?: boolean;
|
|
408
|
+
width?: number;
|
|
409
|
+
simple?: boolean;
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
412
|
+
* Creates triangles to the width of a polyline.
|
|
413
|
+
*
|
|
414
|
+
* A polyline is defined by a series of points.
|
|
415
|
+
*
|
|
416
|
+
* The polyline can either be converted directly to triangles that create
|
|
417
|
+
* its width (`num` undefined), or split into `num` equal segments first.
|
|
418
|
+
*
|
|
419
|
+
* `simple` polylines are rectangles formed between two points in a polyline
|
|
420
|
+
* or segmented polyline. When there are bends in the line, gaps will form on
|
|
421
|
+
* the outside border. These gaps will become more visible as the line gets
|
|
422
|
+
* thicker.
|
|
423
|
+
*
|
|
424
|
+
* When `simple = false`, each corner has an additional two triangles to fill
|
|
425
|
+
* in the gaps.
|
|
426
|
+
*
|
|
427
|
+
* The final number of vertices depends on `simple`, `num` and `close`. Each
|
|
428
|
+
* line segment as 6 vertices. Each corner fill has 6 vertices. If `num` is
|
|
429
|
+
* `undefined` or `null` then the total number of line segments will be
|
|
430
|
+
* `points.length` + 1.
|
|
431
|
+
*
|
|
432
|
+
* This method is useful for morphing between lines, but is of limited use. If
|
|
433
|
+
* the line segments gradient change quadrants, then the line thicknesses will
|
|
434
|
+
* change during morphing. Especially for thick lines, it will often be better
|
|
435
|
+
* to use `polylineToShapes`.
|
|
436
|
+
*
|
|
437
|
+
* @group Misc Morphing
|
|
438
|
+
*/
|
|
439
|
+
declare function polyline(options: OBJ_MorphPolyline): number[];
|
|
440
|
+
/**
|
|
441
|
+
* Options object to calculate vertices of a polygon
|
|
442
|
+
*
|
|
443
|
+
* @property {number} [radius] radius of polygon (`1`)
|
|
444
|
+
* @property {number} [sides] number of polygon sides (`4`)
|
|
445
|
+
* @property {TypeParsablePoint} [position] center position of polygon (`[0, 0]`)
|
|
446
|
+
* @property {number} [rotation] polygon rotation (first vertex will be along
|
|
447
|
+
* the positive x axis) (`0`)
|
|
448
|
+
* @property {1 | -1} [direction] 1 is CCW, -1 is CW (`1`)
|
|
449
|
+
* @interface
|
|
450
|
+
* @group Misc Morphing
|
|
451
|
+
*/
|
|
452
|
+
export type OBJ_GetPolygonCorners = {
|
|
453
|
+
radius?: number;
|
|
454
|
+
sides?: number;
|
|
455
|
+
position?: TypeParsablePoint;
|
|
456
|
+
rotation?: number;
|
|
457
|
+
direction?: 1 | -1;
|
|
458
|
+
};
|
|
459
|
+
/**
|
|
460
|
+
* Calculate vertices of a polygon
|
|
461
|
+
*
|
|
462
|
+
* @param {OBJ_GetPolygonCorners} options
|
|
463
|
+
* @return {Array<Point>} Array of vertices
|
|
464
|
+
* tuples
|
|
465
|
+
* @group Misc Morphing
|
|
466
|
+
*/
|
|
467
|
+
declare function getPolygonCorners(options: OBJ_GetPolygonCorners): Point[];
|
|
468
|
+
/**
|
|
469
|
+
* Options object to generate shapes at random positions within a polygon.
|
|
470
|
+
*
|
|
471
|
+
* @property {number} [num] number of shapes to generate (`10`)
|
|
472
|
+
* @property {number} [size] size of each shape (`0.01`)
|
|
473
|
+
* @property {number} [radius] radius of polygon (`1`)
|
|
474
|
+
* @property {number} [sides] number of polygon sides (`4`)
|
|
475
|
+
* @property {TypeParsablePoint} [position] center position of polygon (`[0, 0]`)
|
|
476
|
+
* @property {number} [rotation] polygon rotation (first vertex will be along
|
|
477
|
+
* the positive x axis) (`0`)
|
|
478
|
+
* @property {function(Point, number): Array<number> | number} [shape]
|
|
479
|
+
* By default a square of two triangles is created (six vertices). Use a
|
|
480
|
+
* `number` to create a regular polygon with `number` sides. Use a custom
|
|
481
|
+
* function to make a custom shape. The function takes as input the [x, y]
|
|
482
|
+
* position of the point to build the shape around, and `size`. It outputs an
|
|
483
|
+
* array of interlaced x and y coordinates of triangle vertices - i.e.:
|
|
484
|
+
* [x1, y1, x2, y2, x3, y3, ....]
|
|
485
|
+
* @interface
|
|
486
|
+
* @group Morphing
|
|
487
|
+
*/
|
|
488
|
+
export type OBJ_PolygonCloudShapes = {
|
|
489
|
+
radius?: number;
|
|
490
|
+
sides?: number;
|
|
491
|
+
position?: TypeParsablePoint;
|
|
492
|
+
rotation?: number;
|
|
493
|
+
num?: number;
|
|
494
|
+
size?: number;
|
|
495
|
+
shape?: number | ((center: Point, size: number) => Array<number>);
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Generate random points within a polygon.
|
|
499
|
+
*
|
|
500
|
+
* 
|
|
501
|
+
*
|
|
502
|
+
* @param {OBJ_PolygonCloudShapes} polygonCloudPoints
|
|
503
|
+
* @return {Array<number>} array of interlaced x and y coordinates of vertices
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* const { polygonCloudShapes } = Fig.morph;
|
|
507
|
+
*
|
|
508
|
+
* const cloud1 = polygonCloudShapes({
|
|
509
|
+
* num: 2000,
|
|
510
|
+
* radius: 0.5,
|
|
511
|
+
* sides: 5,
|
|
512
|
+
* });
|
|
513
|
+
*
|
|
514
|
+
* const cloud2 = polygonCloudShapes({
|
|
515
|
+
* num: 2000,
|
|
516
|
+
* radius: 0.5,
|
|
517
|
+
* sides: 100,
|
|
518
|
+
* });
|
|
519
|
+
*
|
|
520
|
+
* const m = figure.add({
|
|
521
|
+
* make: 'morph',
|
|
522
|
+
* points: [cloud1, cloud2],
|
|
523
|
+
* color: [1, 0, 0, 1],
|
|
524
|
+
* });
|
|
525
|
+
*
|
|
526
|
+
* m.animations.new()
|
|
527
|
+
* .morph({ start: 0, target: 1, duration: 2 })
|
|
528
|
+
* .start();
|
|
529
|
+
* @group Morphing
|
|
530
|
+
*/
|
|
531
|
+
declare function polygonCloudShapes(options: OBJ_PolygonCloudShapes): number[];
|
|
532
|
+
/**
|
|
533
|
+
* Options object to generate shapes at random positions within a circle.
|
|
534
|
+
*
|
|
535
|
+
* @property {number} [num] number of shapes to generate (`10`)
|
|
536
|
+
* @property {number} [pointSize] size of each shape (`0.01`)
|
|
537
|
+
* @property {number} [radius] radius of circle (`1`)
|
|
538
|
+
* @property {TypeParsablePoint} [position] center position of circle (`[0, 0]`)
|
|
539
|
+
* @property {function(Point, number): Array<number> | number} [shape]
|
|
540
|
+
* By default a square of two triangles is created (six vertices). Use a
|
|
541
|
+
* `number` to create a regular polygon with `number` sides. Use a custom
|
|
542
|
+
* function to make a custom shape. The function takes as input the [x, y]
|
|
543
|
+
* position of the point to build the shape around, and `size`. It outputs an
|
|
544
|
+
* array of interlaced x and y coordinates of triangle vertices - i.e.:
|
|
545
|
+
* [x1, y1, x2, y2, x3, y3, ....]
|
|
546
|
+
* @interface
|
|
547
|
+
* @group Morphing
|
|
548
|
+
*/
|
|
549
|
+
export type OBJ_CircleCloudShapes = {
|
|
550
|
+
radius?: number;
|
|
551
|
+
position?: TypeParsablePoint;
|
|
552
|
+
num?: number;
|
|
553
|
+
shape?: ((position: [number, number], size: number) => Array<number>);
|
|
554
|
+
size?: number;
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Generate random points within a circle.
|
|
558
|
+
*
|
|
559
|
+
* 
|
|
560
|
+
*
|
|
561
|
+
* @param {OBJ_CircleCloudShapes} options
|
|
562
|
+
* @return {Array<number>} array of interlaced x and y coordinates of vertices
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* const { circleCloudShapes } = Fig.morph;
|
|
566
|
+
*
|
|
567
|
+
* const cloud1 = circleCloudShapes({
|
|
568
|
+
* num: 2000,
|
|
569
|
+
* radius: 2,
|
|
570
|
+
* });
|
|
571
|
+
*
|
|
572
|
+
* const cloud2 = circleCloudShapes({
|
|
573
|
+
* num: 2000,
|
|
574
|
+
* radius: 0.5,
|
|
575
|
+
* });
|
|
576
|
+
*
|
|
577
|
+
* const m = figure.add({
|
|
578
|
+
* make: 'morph',
|
|
579
|
+
* points: [cloud1, cloud2],
|
|
580
|
+
* color: [1, 0, 0, 1],
|
|
581
|
+
* });
|
|
582
|
+
*
|
|
583
|
+
* m.animations.new()
|
|
584
|
+
* .morph({ start: 0, target: 1, duration: 2 })
|
|
585
|
+
* .start();
|
|
586
|
+
* @group Morphing
|
|
587
|
+
*/
|
|
588
|
+
declare function circleCloudShapes(options: OBJ_CircleCloudShapes): number[];
|
|
589
|
+
/**
|
|
590
|
+
* Options object to generate shapes at random positions within a rectangle.
|
|
591
|
+
*
|
|
592
|
+
* @property {number} [maxPoints] number of shapes to generate (`10`)
|
|
593
|
+
* @property {number} [pointSize] size of each shape (`0.01`)
|
|
594
|
+
* @property {number} [width] width of rectangle (`1`)
|
|
595
|
+
* @property {number} [height] height of rectangle (`1`)
|
|
596
|
+
* @property {TypeParsablePoint} [position] center position of rectangle (`[0, 0]`)
|
|
597
|
+
* @property {function(Point, number): Array<number> | number} [shape]
|
|
598
|
+
* By default a square of two triangles is created (six vertices). Use a
|
|
599
|
+
* `number` to create a regular polygon with `number` sides. Use a custom
|
|
600
|
+
* function to make a custom shape. The function takes as input the [x, y]
|
|
601
|
+
* position of the point to build the shape around, and `size`. It outputs an
|
|
602
|
+
* array of interlaced x and y coordinates of triangle vertices - i.e.:
|
|
603
|
+
* [x1, y1, x2, y2, x3, y3, ....]
|
|
604
|
+
* @interface
|
|
605
|
+
* @group Morphing
|
|
606
|
+
*/
|
|
607
|
+
export type OBJ_RectangleCloudShapes = {
|
|
608
|
+
width?: number;
|
|
609
|
+
height?: number;
|
|
610
|
+
position?: TypeParsablePoint;
|
|
611
|
+
num?: number;
|
|
612
|
+
shape?: ((position: [number, number], size: number) => Array<number>);
|
|
613
|
+
size?: number;
|
|
614
|
+
};
|
|
615
|
+
/**
|
|
616
|
+
* Generate random points within a rectangle.
|
|
617
|
+
*
|
|
618
|
+
* 
|
|
619
|
+
*
|
|
620
|
+
* @param {OBJ_RectangleCloudShapes} options
|
|
621
|
+
* @return {Array<number>} array of interlaced x and y coordinates of vertices
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* const { rectangleCloudShapes } = Fig.morph;
|
|
625
|
+
*
|
|
626
|
+
* const cloud1 = rectangleCloudShapes({
|
|
627
|
+
* num: 1000,
|
|
628
|
+
* width: 0.5,
|
|
629
|
+
* height: 0.5,
|
|
630
|
+
* position: [-0.5, 0],
|
|
631
|
+
* });
|
|
632
|
+
*
|
|
633
|
+
* const cloud2 = rectangleCloudShapes({
|
|
634
|
+
* num: 1000,
|
|
635
|
+
* width: 0.7,
|
|
636
|
+
* height: 0.7,
|
|
637
|
+
* });
|
|
638
|
+
*
|
|
639
|
+
* const m = figure.add({
|
|
640
|
+
* make: 'morph',
|
|
641
|
+
* points: [cloud1, cloud2],
|
|
642
|
+
* color: [1, 0, 0, 1],
|
|
643
|
+
* });
|
|
644
|
+
*
|
|
645
|
+
* m.animations.new()
|
|
646
|
+
* .morph({ start: 0, target: 1, duration: 2 })
|
|
647
|
+
* .start();
|
|
648
|
+
* @group Morphing
|
|
649
|
+
*/
|
|
650
|
+
declare function rectangleCloudShapes(options: OBJ_RectangleCloudShapes): number[];
|
|
651
|
+
export { polyline, pointsToShapes, polylineToShapes, imageToShapes, getPixels, getPolygonCorners, polygonCloudShapes, circleCloudShapes, rectangleCloudShapes, };
|