You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- All built-in shapes support dot stretching - they rotate towards their direction of travel and stretch along it, just like circles do.
204
+
- Images keep their aspect ratio and are scaled so their larger side matches the dot diameter. Since the default dot sizes (1-3) are quite small, you will usually want to increase `dotMinSize`/`dotMaxSize` for image dots.
205
+
- While the image is loading (or if it fails to load), dots are drawn as regular circles, so the canvas never appears empty.
206
+
- Dot colors do not apply to images - the image keeps its own colors. Per-dot opacity still applies.
207
+
208
+
### Custom shape functions (JavaScript only)
209
+
210
+
For full control, `dotShape` also accepts a function that traces a path centered at `(0, 0)`. DotWave handles position, rotation, stretching and filling for you:
211
+
212
+
```JavaScript
213
+
constdotwave=newDotWave({
214
+
// A simple diamond shape
215
+
dotShape:function(ctx, radius) {
216
+
ctx.moveTo(0, -radius);
217
+
ctx.lineTo(radius, 0);
218
+
ctx.lineTo(0, radius);
219
+
ctx.lineTo(-radius, 0);
220
+
ctx.closePath();
221
+
},
222
+
});
223
+
```
224
+
225
+
# Color palettes
226
+
227
+
Instead of a single `dotColor`, you can pass an array of colors with `dotColors`. Each dot picks one color from the palette at random when it is created:
When `dotColors` is set (and not empty), it takes precedence over `dotColor`. Updating `dotColor` or `dotColors` via `updateOptions()` re-rolls the colors of all existing dots without resetting their positions. All CSS color formats supported by `dotColor` (named, hex, RGB/RGBA) work in the palette too.
242
+
243
+
# Motion presets
244
+
245
+
By default, dots just wander randomly (and react to your cursor). The `motion` option gives them a direction of their own:
- Motion presets combine with everything else: cursor reactivity, random movement, friction and `maxSpeed` all still apply. For a perfectly uniform stream, set `randomFactor: 0`.
278
+
-`motionStrength` is a continuous force, so its visible speed is balanced against `friction` and capped by `maxSpeed`.
279
+
- For `vortex`, a negative `motionStrength` reverses the spin direction.
280
+
- The vortex center is relative to the canvas size, so `0.5`/`0.5` always stays in the middle, even after resizing. Values outside `0-1` place the center off-canvas, which works too.
281
+
164
282
# Methods
165
283
166
284
```JavaScript
@@ -209,6 +327,14 @@ dotwave.destroy();
209
327
| dot-max-stretch | dotMaxStretch | number | 20 | Maximum stretch amount |
| motion-angle | motionAngle | number | 0 | Stream direction in degrees (0 = right, 90 = down) |
335
+
| motion-strength | motionStrength | number | 0.05 | Strength of the motion preset force |
336
+
| motion-center-x | motionCenterX | number | 0.5 | Vortex center X as a fraction of canvas width (0-1) |
337
+
| motion-center-y | motionCenterY | number | 0.5 | Vortex center Y as a fraction of canvas height (0-1) |
212
338
213
339
## For HTML
214
340
@@ -234,7 +360,15 @@ dotwave.destroy();
234
360
dot-stretch-mult="10"
235
361
dot-max-stretch="20"
236
362
rot-smoothing="false"
237
-
rot-smoothing-intensity="150">
363
+
rot-smoothing-intensity="150"
364
+
dot-shape="circle"
365
+
dot-image=""
366
+
dot-colors=""
367
+
motion="none"
368
+
motion-angle="0"
369
+
motion-strength="0.05"
370
+
motion-center-x="0.5"
371
+
motion-center-y="0.5">
238
372
</dot-wave>
239
373
```
240
374
@@ -263,7 +397,15 @@ const dotwave = new DotWave({
263
397
dotStretchMult:10, // How much to stretch the dots
264
398
dotMaxStretch:20, // Maximum stretch amount
265
399
rotSmoothing:false, // Toggle for rotation smoothing of dots
266
-
rotSmoothingIntensity:150// Rotation smoothing duration in milliseconds
400
+
rotSmoothingIntensity:150, // Rotation smoothing duration in milliseconds
401
+
dotShape:'circle', // Dot shape: 'circle', 'square', 'triangle', 'star', 'image' or a custom draw function
402
+
dotImage:null, // Image URL used when dotShape is 'image'
403
+
dotColors:null, // Array of colors; each dot picks one at random (overrides dotColor)
404
+
motion:'none', // Autonomous motion preset: 'none', 'stream' or 'vortex'
405
+
motionAngle:0, // Stream direction in degrees (0 = right, 90 = down)
406
+
motionStrength:0.05, // Strength of the motion preset force
407
+
motionCenterX:0.5, // Vortex center X as a fraction of canvas width (0-1)
408
+
motionCenterY:0.5// Vortex center Y as a fraction of canvas height (0-1)
267
409
});
268
410
```
269
411
> *Note, that `rotSmoothing: false` skips the rotation lerping calculations and is therefore more performant than using `rotSmoothingIntensity: 0`, same logic applies to `dotStretch`.*
0 commit comments