UNPKG

@tsparticles/path-polygon

Version:
88 lines (82 loc) 6.88 kB
(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.0 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/plugin-move'), require('@tsparticles/engine')) : typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/plugin-move', '@tsparticles/engine'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.paths = global.__tsParticlesInternals.paths || {}, global.__tsParticlesInternals.paths.polygon = global.__tsParticlesInternals.paths.polygon || {}), global.__tsParticlesInternals.plugins.move, global.__tsParticlesInternals.engine)); })(this, (function (exports, pluginMove, engine) { 'use strict'; const defaultOptions = { sides: 6, turnSteps: 20, angle: 30, }; class PolygonPathGenerator { dirsList; options; #container; #res; constructor(container) { this.#container = container; this.#res = engine.Vector.origin; this.dirsList = []; this.options = engine.deepExtend({}, defaultOptions); } generate(p) { const { sides, turnSteps } = this.options; p.hexStep ??= 0; p.hexDirection ??= sides === 6 ? ((engine.getRandom() * 3) | 0) * 2 : (engine.getRandom() * sides) | 0; p.hexSpeed ??= p.velocity.length; if (p.hexStep % turnSteps === 0) { p.hexDirection = engine.getRandom() > 0.5 ? (p.hexDirection + 1) % sides : (p.hexDirection + sides - 1) % sides; } p.velocity.x = 0; p.velocity.y = 0; p.hexStep++; const direction = this.dirsList[p.hexDirection]; this.#res.x = direction.x * p.hexSpeed; this.#res.y = direction.y * p.hexSpeed; return this.#res; } init() { const container = this.#container, sourceOptions = container.actualOptions.particles.move.path.options; this.options.sides = sourceOptions["sides"] > 0 ? sourceOptions["sides"] : this.options.sides; this.options.angle = sourceOptions["angle"] ?? this.options.angle; this.options.turnSteps = sourceOptions["turnSteps"] >= 0 ? sourceOptions["turnSteps"] : this.options.turnSteps; this.#createDirs(); } reset(particle) { delete particle.hexStep; delete particle.hexDirection; delete particle.hexSpeed; } update() { } #createDirs = () => { const options = this.options; this.dirsList = []; for (let i = 0; i < 360; i += 360 / options.sides) { const angle = options.angle + i; this.dirsList.push(engine.Vector.create(Math.cos((angle * Math.PI) / 180), Math.sin((angle * Math.PI) / 180))); } }; } const polygonPathName = "polygonPathGenerator"; async function loadPolygonPath(engine) { engine.checkVersion("4.1.0"); await engine.pluginManager.register((e) => { pluginMove.ensureBaseMoverLoaded(e); e.pluginManager.addPathGenerator?.(polygonPathName, container => { return Promise.resolve(new PolygonPathGenerator(container)); }); }); } const globalObject = globalThis; globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {}; globalObject.loadPolygonPath = loadPolygonPath; exports.loadPolygonPath = loadPolygonPath; exports.polygonPathName = polygonPathName; })); Object.assign(globalThis.window || globalThis, { loadPolygonPath: (globalThis.__tsParticlesInternals.paths.polygon || {}).loadPolygonPath }); delete (globalThis.window || globalThis).tsparticlesInternalExports;