Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | // Runs in the CSS Paint Worklet global scope, not as an application module. |
| 2 | class PixelatedCirclePainter { |
| 3 | static get inputProperties() { |
| 4 | return [ |
| 5 | '--docs-reveal-x', |
| 6 | '--docs-reveal-y', |
| 7 | '--docs-reveal-radius', |
| 8 | '--docs-pixel-size', |
| 9 | '--docs-dissolve-amount', |
| 10 | ]; |
| 11 | } |
| 12 | |
| 13 | hash(x, y) { |
| 14 | const value = Math.sin(x * 12.9898 + y * 78.233) * 43758.5453; |
| 15 | return value - Math.floor(value); |
| 16 | } |
| 17 | |
| 18 | paint(context, size, properties) { |
| 19 | const readNumber = (name, fallback) => { |
| 20 | const value = Number.parseFloat(properties.get(name)); |
| 21 | return Number.isNaN(value) ? fallback : value; |
| 22 | }; |
| 23 | const centerX = readNumber('--docs-reveal-x', 32); |
| 24 | const centerY = readNumber('--docs-reveal-y', 32); |
| 25 | const radiusPercent = readNumber('--docs-reveal-radius', 0); |
| 26 | const pixelSize = readNumber('--docs-pixel-size', 20); |
| 27 | const dissolveAmount = Math.min( |
| 28 | 1, |
| 29 | Math.max(0, readNumber('--docs-dissolve-amount', 0.65)), |
| 30 | ); |
| 31 | const diagonal = Math.sqrt(size.width ** 2 + size.height ** 2); |
| 32 | const baseRadius = (radiusPercent / 100) * diagonal; |
| 33 | const radiusScale = dissolveAmount < 0.95 ? 1 / (1 - dissolveAmount) : 20; |
| 34 | const radius = baseRadius * radiusScale; |
| 35 | const innerEdge = radius * (1 - dissolveAmount); |
| 36 | const fuzzyWidth = radius - innerEdge; |
| 37 | |
| 38 | for (let x = 0; x < size.width; x += pixelSize) { |
| 39 | for (let y = 0; y < size.height; y += pixelSize) { |
| 40 | const distance = Math.sqrt( |
| 41 | (x + pixelSize / 2 - centerX) ** 2 + |
| 42 | (y + pixelSize / 2 - centerY) ** 2, |
| 43 | ); |
| 44 | let opacity = 0; |
| 45 | |
| 46 | if (distance <= innerEdge) { |
| 47 | opacity = 1; |
| 48 | } else if (distance <= radius && fuzzyWidth > 0) { |
| 49 | const distanceOpacity = 1 - (distance - innerEdge) / fuzzyWidth; |
| 50 | if (this.hash(x / pixelSize, y / pixelSize) < distanceOpacity) { |
| 51 | opacity = |
| 52 | distanceOpacity * |
| 53 | (0.5 + 0.5 * this.hash(y / pixelSize, x / pixelSize)); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (opacity > 0) { |
| 58 | context.fillStyle = `rgba(0, 0, 0, ${opacity})`; |
| 59 | context.fillRect(x, y, pixelSize, pixelSize); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | registerPaint('docs-pixelated-circle', PixelatedCirclePainter); |