UNPKG

tsparticles

Version:

Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.

33 lines (32 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CircleShape = void 0; class CircleShape { randomPosition(position, size, fill) { const generateTheta = (x, y) => { const u = Math.random() / 4.0; const theta = Math.atan((y / x) * Math.tan(2 * Math.PI * u)); const v = Math.random(); if (v < 0.25) { return theta; } else if (v < 0.5) { return Math.PI - theta; } else if (v < 0.75) { return Math.PI + theta; } else { return -theta; } }; const radius = (x, y, theta) => (x * y) / Math.sqrt((y * Math.cos(theta)) ** 2 + (x * Math.sin(theta)) ** 2); const [a, b] = [size.width / 2, size.height / 2]; const randomTheta = generateTheta(a, b), maxRadius = radius(a, b, randomTheta), randomRadius = fill ? maxRadius * Math.sqrt(Math.random()) : maxRadius; return { x: position.x + randomRadius * Math.cos(randomTheta), y: position.y + randomRadius * Math.sin(randomTheta), }; } } exports.CircleShape = CircleShape;