Skip to content

Commit

Permalink
Refactor Path.chamfer
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Jul 29, 2024
1 parent 66a4db2 commit 4cfe96e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,8 @@ export namespace Path {
canvas.width = 100
canvas.height = 100
document.body.appendChild(canvas)
canvas.style.width = '400px'
canvas.style.height = '400px'
}

const ctx = canvas.getContext('2d')!
Expand All @@ -2062,21 +2064,21 @@ export namespace Path {
for (let y = 0; y < 100; y++) {
for (let x = 0; x < 100; x++) {
const cost = f([x / 100, y / 100])
costs[y][x] = cost
costs[x][y] = cost
maxCost = Math.max(maxCost, cost)
}
}

console.log('maxCost', maxCost)

for (let y = 0; y < 100; y++) {
for (let x = 0; x < 100; x++) {
const cost = costs[y][x]
const gray = Math.floor(Math.pow(cost / maxCost, 0.44) * 255)
const cost = costs[x][y]
const gray = (cost / maxCost) * 255
ctx.fillStyle = `rgb(${gray}, ${gray}, ${gray})`
ctx.fillRect(x, y, 1, 1)
}
}

ctx.fillStyle = 'red'
ctx.fillText(maxCost.toFixed(2), 2, 12)
}

visualizeGraph(f)
Expand Down

0 comments on commit 4cfe96e

Please sign in to comment.