Skip to content

Commit 00b9a7c

Browse files
committed
fix: expose ascii font
1 parent 4297896 commit 00b9a7c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/effects/ASCII.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor)
4747
`
4848

4949
interface IASCIIEffectProps {
50+
font?: string
5051
characters?: string
5152
fontSize?: number
5253
cellSize?: number
@@ -56,6 +57,7 @@ interface IASCIIEffectProps {
5657

5758
class ASCIIEffect extends Effect {
5859
constructor({
60+
font = 'arial',
5961
characters = ` .:,'-^=*+?!|0#X%WM@`,
6062
fontSize = 54,
6163
cellSize = 16,
@@ -75,12 +77,12 @@ class ASCIIEffect extends Effect {
7577
const charactersTextureUniform = this.uniforms.get('uCharacters')
7678

7779
if (charactersTextureUniform) {
78-
charactersTextureUniform.value = this.createCharactersTexture(characters, fontSize)
80+
charactersTextureUniform.value = this.createCharactersTexture(characters, font, fontSize)
7981
}
8082
}
8183

8284
/** Draws the characters on a Canvas and returns a texture */
83-
public createCharactersTexture(characters: string, fontSize: number): THREE.Texture {
85+
public createCharactersTexture(characters: string, font: string, fontSize: number): THREE.Texture {
8486
const canvas = document.createElement('canvas')
8587
const SIZE = 1024
8688
const MAX_PER_ROW = 16
@@ -95,7 +97,7 @@ class ASCIIEffect extends Effect {
9597
}
9698

9799
context.clearRect(0, 0, SIZE, SIZE)
98-
context.font = `${fontSize}px arial`
100+
context.font = `${fontSize}px ${font}`
99101
context.textAlign = 'center'
100102
context.textBaseline = 'middle'
101103
context.fillStyle = '#fff'

0 commit comments

Comments
 (0)