1
0
Fork 0
mirror of https://github.com/Findus23/RainbowRoad.git synced 2024-09-19 16:03:52 +02:00

simplify code

This commit is contained in:
Lukas Winkler 2023-09-30 22:19:19 +02:00
parent 703667e3fa
commit 107cbae49d
Signed by: lukas
GPG key ID: 54DE4D798D244853
2 changed files with 6 additions and 11 deletions

View file

@ -17,10 +17,11 @@ function main() {
const start = new Vector2d(10, 110) const start = new Vector2d(10, 110)
const end = new Vector2d(110, 60) const end = new Vector2d(110, 60)
const line = new Line(start, end) const line = new Line(start, end)
drawZebraCrossing(ctx, new Line(start, new Vector2d(50, 50)),30, zebraPattern) const numLines = 10;
drawZebraCrossing(ctx, line,30, prideZebraPattern) drawZebraCrossing(ctx, new Line(start, new Vector2d(50, 50)), 30, zebraPattern, numLines)
drawZebraCrossing(ctx, new Line(end, new Vector2d(160, 80)),30, transZebraPattern) drawZebraCrossing(ctx, line, 30, prideZebraPattern, numLines)
drawZebraCrossing(ctx, new Line(new Vector2d(160, 80), new Vector2d(120, 150)),30, nonbinaryZebraPattern) drawZebraCrossing(ctx, new Line(end, new Vector2d(160, 80)), 30, transZebraPattern, numLines)
drawZebraCrossing(ctx, new Line(new Vector2d(160, 80), new Vector2d(120, 150)), 30, nonbinaryZebraPattern, numLines)
// line.draw(ctx) // line.draw(ctx)
// const line = new Line(start, end) // const line = new Line(start, end)
// //

View file

@ -36,17 +36,11 @@ export function drawZebraCrossing(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
line: Line, line: Line,
zebraWidth: number, zebraWidth: number,
pattern: (i: number) => string, numStripes?: number pattern: (i: number) => string, numStripes: number
): void { ): void {
const ex = line.vec const ex = line.vec
const ey = line.vec.rotate90deg().toLength(zebraWidth) const ey = line.vec.rotate90deg().toLength(zebraWidth)
const eoff = line.start const eoff = line.start
// console.log(line.length())
// console.log(line.vec)
if (typeof numStripes === "undefined") {
numStripes = Math.floor(line.vec.length() / 6)
}
// console.log(numStripes)
const stripeLength = 1 const stripeLength = 1
const stripeWidth = stripeLength / numStripes const stripeWidth = stripeLength / numStripes