@tsparticles/path-curl-noise
Version:
tsParticles curl noise path
68 lines (62 loc) • 6.38 kB
JavaScript
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
/* Path v4.1.3 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/plugin-move'), require('@tsparticles/engine'), require('@tsparticles/simplex-noise')) :
typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/plugin-move', '@tsparticles/engine', '@tsparticles/simplex-noise'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.paths = global.__tsParticlesInternals.paths || {}, global.__tsParticlesInternals.paths.curlNoise = global.__tsParticlesInternals.paths.curlNoise || {}), global.__tsParticlesInternals.plugins.move, global.__tsParticlesInternals.engine, global.__tsParticlesInternals.simplex.noise));
})(this, (function (exports, pluginMove, engine, simplexNoise) { 'use strict';
const defaultOptions = {
speed: 0.2,
step: 250,
};
class CurlNoiseGenerator {
options;
#container;
#res;
#simplex;
constructor(container) {
this.#container = container;
this.#res = engine.Vector.origin;
const simplex = new simplexNoise.SimplexNoise();
this.#simplex = simplex.noise2d;
this.options = engine.deepExtend({}, defaultOptions);
}
generate(particle) {
const pos = particle.getPosition(), { speed, step } = this.options, x = pos.x / step, y = pos.y / step, eps = 0.001, n1a = this.#simplex.noise(x, y + eps), n2a = this.#simplex.noise(x, y - eps), a = (n1a - n2a) / (engine.double * eps), n1b = this.#simplex.noise(x + eps, y), n2b = this.#simplex.noise(x - eps, y), b = (n1b - n2b) / (engine.double * eps);
particle.velocity.x = 0;
particle.velocity.y = 0;
this.#res.x = speed * a;
this.#res.y = speed * -b;
return this.#res;
}
init() {
const container = this.#container, sourceOptions = container.actualOptions.particles.move.path.options;
this.options.seed = sourceOptions["seed"];
this.options.speed =
(sourceOptions["speed"] ?? defaultOptions.speed) * container.retina.pixelRatio;
this.options.step = sourceOptions["step"] ?? defaultOptions.step;
this.#simplex.seed(this.options.seed ?? engine.getRandom());
}
reset() {
}
update() {
}
}
const curlNoisePathName = "curlNoise";
async function loadCurlNoisePath(engine) {
engine.checkVersion("4.1.3");
await engine.pluginManager.register((e) => {
pluginMove.ensureBaseMoverLoaded(e);
e.pluginManager.addPathGenerator?.(curlNoisePathName, container => {
return Promise.resolve(new CurlNoiseGenerator(container));
});
});
}
const globalObject = globalThis;
globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
globalObject.loadCurlNoisePath = loadCurlNoisePath;
exports.curlNoisePathName = curlNoisePathName;
exports.loadCurlNoisePath = loadCurlNoisePath;
}));
Object.assign(globalThis.window || globalThis, { loadCurlNoisePath: (globalThis.__tsParticlesInternals.paths.curlNoise || {}).loadCurlNoisePath });
delete (globalThis.window || globalThis).tsparticlesInternalExports;