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K,SAChC,KAAK,QAAQ,EAAI,KAAK,MAAM,EAAI,GAAM,KAAK,SAC3C,KAAK,WAIR,KAAA,UAGD,EAAA,UAAA,OAAR,WACS,KAAA,QACc,IAAA,IAAA,EAAA,EAAA,EAAA,KAAK,MAAL,EAAA,EAAA,OAAA,IAAY,CAAhB,EAAA,GACN,OAAO,KAAK,IAAK,KAAK,SAI3B,EAAA,UAAA,MAAR,WACI,QAAQ,QACH,KAAA,IAAI,UAAU,EAAG,EAAG,KAAK,OAAO,MAAO,KAAK,OAAO,SAGpD,EAAA,UAAA,OAAR,WACU,IAAA,EAAI,SAAS,KAAK,YAClB,EAAI,SAAS,KAAK,aAEe,iBAA5B,OAAO,kBACT,KAAA,OAAO,MAAQ,EAAI,OAAO,iBAC1B,KAAA,OAAO,OAAS,EAAI,OAAO,mBAE3B,KAAA,OAAO,MAAQ,EACf,KAAA,OAAO,OAAS,GAGpB,KAAA,MAAQ,CACT,EAAG,EAAI,EAAI,KAAK,OAAO,MACvB,EAAG,EAAI,EAAI,KAAK,OAAO,QAGtB,KAAA,SAA+E,GAApE,KAAK,MAAM,KAAK,IAAI,KAAK,OAAO,MAAO,KAAK,OAAO,QAAU,MAErF,EA9GA,GAAa,QAAA,IAAA;;ACAb,aAAA,QAAA,YAAA,EAFA,IAAA,EAAA,QAAA,SAEM,EAAM,IAAI,EAAA","file":"generative.9dcd98b5.map","sourceRoot":"..","sourcesContent":["export class Tile {\r\n    constructor (private x: number, private y: number, private size: number) {}\r\n\r\n    public render (ctx: CanvasRenderingContext2D, mouse: {x: number, y: number} = null) {\r\n        const dx = mouse.x - (this.x + this.size / 2);\r\n        const dy = mouse.y - (this.y + this.size / 2);\r\n        const n = 7;\r\n\r\n        for (let i = 0; i < n; i++) {\r\n            const ratio = 1 - 0.9 * i / n;\r\n            this.renderCircle(ctx, i, ratio, dx, dy);\r\n        }\r\n    }\r\n\r\n    private renderCircle (ctx: CanvasRenderingContext2D, i: number, ratio: number, dx: number, dy: number) {\r\n        const m = Math.sqrt(ctx.canvas.width * ctx.canvas.width + ctx.canvas.height * ctx.canvas.height);\r\n        const n = Math.min(Math.sqrt(dx * dx + dy * dy), m) / m;\r\n        const radius = ratio * this.size / 2;\r\n\r\n        const limit = (this.size / 2 - radius) * 1.2    ;\r\n\r\n        const x = this.x + this.size / 2 + Math.max(Math.min(n * (1 - ratio) * dx, limit), -1 * limit);\r\n        const y = this.y + this.size / 2 + Math.max(Math.min(n * (1 - ratio) * dy, limit), -1 * limit);\r\n\r\n        ctx.lineWidth = 0.1 + (1.01 - ratio);\r\n\r\n        if (i % 2 === 0) {\r\n            ctx.fillStyle = '#fff';\r\n        } else {\r\n            ctx.fillStyle = '#000';\r\n        }\r\n\r\n        ctx.beginPath();\r\n        ctx.arc(x, y, radius, 0, 2 * Math.PI);\r\n        ctx.fill();\r\n    }\r\n}\r\n","import { Tile } from './Tile';\r\n\r\nexport class App {\r\n    private canvas: HTMLCanvasElement;\r\n    private ctx: CanvasRenderingContext2D;\r\n\r\n    private padding = { x: 0, y: 0 };\r\n    private tileSize = 50;\r\n\r\n    private tiles: Tile[] = [];\r\n\r\n    private mouse: { x: number, y: number };\r\n\r\n    constructor () {\r\n        const old = document.querySelector('canvas');\r\n        if (old) { old.parentNode.removeChild(old); }\r\n\r\n        this.canvas = document.createElement('canvas');\r\n        this.ctx = this.canvas.getContext('2d');\r\n\r\n        document.body.insertAdjacentElement('afterbegin', this.canvas);\r\n\r\n        window.onresize = () => {\r\n            this.resize();\r\n            this.run();\r\n        };\r\n        this.resize();\r\n\r\n        window.onmousemove = (e: MouseEvent) => {\r\n            if (typeof window.devicePixelRatio === 'number') {\r\n                this.mouse = {\r\n                    x: e.clientX * window.devicePixelRatio,\r\n                    y: e.clientY * window.devicePixelRatio\r\n                };\r\n            } else {\r\n                this.mouse = {\r\n                    x: e.clientX,\r\n                    y: e.clientY\r\n                };\r\n            }\r\n            window.requestAnimationFrame(() => this.render());\r\n        };\r\n\r\n        window.ontouchmove = (e: TouchEvent) => {\r\n            if (typeof window.devicePixelRatio === 'number') {\r\n                this.mouse = {\r\n                    x: e.touches[0].clientX * window.devicePixelRatio,\r\n                    y: e.touches[0].clientY * window.devicePixelRatio\r\n                };\r\n            } else {\r\n                this.mouse = {\r\n                    x: e.touches[0].clientX,\r\n                    y: e.touches[0].clientY\r\n                };\r\n            }\r\n            window.requestAnimationFrame(() => this.render());\r\n        };\r\n\r\n        this.run();\r\n    }\r\n\r\n    private run () {\r\n\r\n        this.padding.x = (this.canvas.width % this.tileSize) / 2;\r\n        this.padding.y = (this.canvas.height % this.tileSize) / 2;\r\n\r\n        const nx = Math.floor(this.canvas.width / this.tileSize);\r\n        const ny = Math.floor(this.canvas.height / this.tileSize);\r\n\r\n        this.tiles = [];\r\n        for (let i = 0; i < nx * ny; i++) {\r\n            this.tiles.push(new Tile(\r\n                this.padding.x + (i % nx * this.tileSize),\r\n                this.padding.y + Math.floor(i / nx) * this.tileSize,\r\n                this.tileSize\r\n            ));\r\n        }\r\n\r\n        this.render();\r\n    }\r\n\r\n    private render () {\r\n        this.clear();\r\n        for (const tile of this.tiles) {\r\n            tile.render(this.ctx, this.mouse);\r\n        }\r\n    }\r\n\r\n    private clear () {\r\n        console.clear();\r\n        this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);\r\n    }\r\n\r\n    private resize () {\r\n        const w = document.body.clientWidth;\r\n        const h = document.body.clientHeight;\r\n\r\n        if (typeof window.devicePixelRatio === 'number') {\r\n            this.canvas.width = w * window.devicePixelRatio;\r\n            this.canvas.height = h * window.devicePixelRatio;\r\n        } else {\r\n            this.canvas.width = w;\r\n            this.canvas.height = h;\r\n        }\r\n\r\n        this.mouse = {\r\n            x: 1 / 3 * this.canvas.width,\r\n            y: 1 / 3 * this.canvas.height\r\n        };\r\n\r\n        this.tileSize = Math.floor(Math.max(this.canvas.width, this.canvas.height) / 250) * 10;\r\n    }\r\n}\r\n","import { App } from './App';\r\n\r\nconst app = new App();\r\n"]}