{"version":3,"file":"zebraUtils-BAnW12rS.js","sources":["../../src/vectorUtils.ts","../../src/zebraUtils.ts"],"sourcesContent":["export class Vector2d {\n x: number\n y: number\n\n constructor(x: number, y: number) {\n this.x = x\n this.y = y\n }\n\n static fromCoordList(coords: number[]): Vector2d {\n return new Vector2d(coords[0], coords[1])\n }\n\n add(b: Vector2d): Vector2d {\n return new Vector2d(this.x + b.x, this.y + b.y)\n }\n\n mtpl(n: number): Vector2d {\n return new Vector2d(this.x * n, this.y * n)\n }\n\n subtract(b: Vector2d): Vector2d {\n return new Vector2d(this.x + b.x, this.y + b.y)\n }\n\n rotate(angle: number): Vector2d {\n return new Vector2d(\n this.x * Math.cos(angle) + this.y * Math.sin(angle),\n -this.x * Math.sin(angle) + this.y * Math.cos(angle)\n )\n }\n\n rotate90deg(): Vector2d {\n return new Vector2d(this.y, -this.x)\n }\n\n length(): number {\n return Math.sqrt(this.x ** 2 + this.y ** 2)\n }\n\n\n toLength(length: number): Vector2d {\n const fact = length / this.length()\n return new Vector2d(this.x * fact, this.y * fact)\n\n }\n\n}\n\nexport function draw(ctx: CanvasRenderingContext2D, start: Vector2d, end: Vector2d): void {\n ctx.moveTo(start.x, start.y)\n ctx.lineTo(end.x, end.y)\n}\n\n\nexport class Line {\n start: Vector2d\n end: Vector2d\n vec: Vector2d\n\n constructor(start: Vector2d, end: Vector2d) {\n this.start = start\n this.end = end\n this.vec = new Vector2d(end.x - start.x, end.y - start.y)\n }\n\n static fromStartandVector(start: Vector2d, vec: Vector2d): Line {\n const end = start.add(vec)\n return new Line(start, end)\n }\n\n\n drawInCoord(ctx: CanvasRenderingContext2D, ex: Vector2d, ey: Vector2d, eoff: Vector2d): void {\n const newStart = ex.mtpl(this.start.x).add(ey.mtpl(this.start.y)).add(eoff)\n const newEnd = ex.mtpl(this.end.x).add(ey.mtpl(this.end.y)).add(eoff)\n draw(ctx, newStart, newEnd)\n }\n\n draw(ctx: CanvasRenderingContext2D): void {\n ctx.beginPath()\n ctx.lineWidth = 10\n draw(ctx, this.start, this.end)\n ctx.stroke()\n\n }\n\n\n}\n","import {Line, Vector2d} from \"./vectorUtils\";\nimport {FlagType} from \"../interfaces\";\n\nexport const prideFlagColors = [\"#e40303\", \"#ff8c00\", \"#ffed00\", \"#008026\", \"#004dff\", \"#750787\"]\nexport const transFlagColors = [\"#5BCEFA\", \"#F5A9B8\"]\nexport const nonbinaryFlagColors = [\"#FFF433\", \"#9B59D0\", \"#2D2D2D\"] // I assume they will skip the white stripe\nexport const portschachRainbowColors = [\"#e40303\", \"#004dff\", \"#008026\", \"#ff8c00\",\n]\nexport type PatternFunction = (i: number) => string\n\nexport function zebraPattern(i: number): string {\n return i % 2 == 0 ? \"white\" : \"black\";\n}\n\nexport function generateFlagZebraPattern(colors: string[]): PatternFunction {\n return (i: number): string => {\n if (i % 2) {\n return \"white\"\n } else {\n const j = Math.floor(i / 2) % colors.length\n return colors[j]\n }\n };\n}\n\nexport const prideZebraPattern = generateFlagZebraPattern(prideFlagColors)\nexport const transZebraPattern = generateFlagZebraPattern(transFlagColors)\nexport const nonbinaryZebraPattern = generateFlagZebraPattern(nonbinaryFlagColors)\nexport const portschachZebraPattern = generateFlagZebraPattern(portschachRainbowColors)\n\nexport const zebraPatterns: { [d in FlagType]: PatternFunction } = {\n \"prideFlag\": prideZebraPattern,\n \"transFlag\": transZebraPattern,\n \"nonbinaryFlag\": nonbinaryZebraPattern,\n \"portschachRainbow\": portschachZebraPattern\n}\n\n\nexport function drawZebraCrossing(\n ctx: CanvasRenderingContext2D,\n line: Line,\n zebraWidth: number,\n pattern: (i: number) => string, numStripes: number\n): void {\n const ex = line.vec\n const ey = line.vec.rotate90deg().toLength(zebraWidth)\n const eoff = line.start\n\n const stripeLength = 1\n const stripeWidth = stripeLength / numStripes\n for (let i = 0; i < numStripes; i++) {\n const x = i * stripeWidth\n ctx.beginPath()\n ctx.lineWidth = stripeWidth * ex.length()\n ctx.strokeStyle = pattern(i)\n const stripe = new Line(new Vector2d(x, -0.5), new Vector2d(x, 0.5))\n stripe.drawInCoord(ctx, ex, ey, eoff)\n ctx.stroke()\n }\n\n}\n"],"names":["Vector2d","x","y","__publicField","coords","b","n","angle","length","fact","draw","ctx","start","end","Line","vec","ex","ey","eoff","newStart","newEnd","prideFlagColors","transFlagColors","nonbinaryFlagColors","portschachRainbowColors","zebraPattern","i","generateFlagZebraPattern","colors","j","prideZebraPattern","transZebraPattern","nonbinaryZebraPattern","portschachZebraPattern","zebraPatterns","drawZebraCrossing","line","zebraWidth","pattern","numStripes","stripeWidth"],"mappings":"02BAAO,MAAMA,CAAS,CAIlB,YAAYC,EAAWC,EAAW,CAHlCC,EAAA,UACAA,EAAA,UAGI,KAAK,EAAIF,EACT,KAAK,EAAIC,CAAA,CAGb,OAAO,cAAcE,EAA4B,CAC7C,OAAO,IAAIJ,EAASI,EAAO,CAAC,EAAGA,EAAO,CAAC,CAAC,CAAA,CAG5C,IAAIC,EAAuB,CAChB,OAAA,IAAIL,EAAS,KAAK,EAAIK,EAAE,EAAG,KAAK,EAAIA,EAAE,CAAC,CAAA,CAGlD,KAAKC,EAAqB,CACtB,OAAO,IAAIN,EAAS,KAAK,EAAIM,EAAG,KAAK,EAAIA,CAAC,CAAA,CAG9C,SAASD,EAAuB,CACrB,OAAA,IAAIL,EAAS,KAAK,EAAIK,EAAE,EAAG,KAAK,EAAIA,EAAE,CAAC,CAAA,CAGlD,OAAOE,EAAyB,CAC5B,OAAO,IAAIP,EACP,KAAK,EAAI,KAAK,IAAIO,CAAK,EAAI,KAAK,EAAI,KAAK,IAAIA,CAAK,EAClD,CAAC,KAAK,EAAI,KAAK,IAAIA,CAAK,EAAI,KAAK,EAAI,KAAK,IAAIA,CAAK,CACvD,CAAA,CAGJ,aAAwB,CACpB,OAAO,IAAIP,EAAS,KAAK,EAAG,CAAC,KAAK,CAAC,CAAA,CAGvC,QAAiB,CACb,OAAO,KAAK,KAAK,KAAK,GAAK,EAAI,KAAK,GAAK,CAAC,CAAA,CAI9C,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