Skip to content

Commit

Permalink
Use small gradient at particle edges
Browse files Browse the repository at this point in the history
This reduces the jaggedness of streamlines.
  • Loading branch information
ceesvoesenek committed Apr 16, 2024
1 parent 8042985 commit a1e0fc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/streamlines/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function mapBoundsToEpsg3857BoundingBox(

export class WMSStreamlineLayer implements CustomLayerInterface {
private static readonly MAX_PARTICLE_DISPLACEMENT = 2
private static readonly PARTICLE_TEXTURE_SIZE = 8
private static readonly PARTICLE_TEXTURE_SIZE = 32

public readonly renderingMode = '2d'
public readonly type = 'custom'
Expand Down
11 changes: 9 additions & 2 deletions src/lib/streamlines/visualiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,18 @@ export class StreamlineVisualiser {
throw new Error('Could not initialise 2D offscreen canvas.')
}

context.beginPath()
const x = radius
const y = radius
const gradient = context.createRadialGradient(x, y, 0, x, y, radius)

const particleColor = this.options.particleColor ?? 'black'
gradient.addColorStop(0, particleColor)
gradient.addColorStop(0.8, particleColor)
gradient.addColorStop(1, 'rgba(0, 0, 0, 0)')

context.beginPath()
context.arc(x, y, radius, 0, 2 * Math.PI, false)
context.fillStyle = this.options.particleColor ?? 'black'
context.fillStyle = gradient
context.fill()

const data = context.getImageData(0, 0, width, height).data
Expand Down

0 comments on commit a1e0fc3

Please sign in to comment.