ASCIIText
react-bits/ASCIIText-JS-TWFreeComponent
Renders text with an animated ASCII background for a retro feel.
Live preview
live · rendered by the registry
Rendered by @react-bits on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.reactbits.dev/r/ASCIIText-JS-TW.jsonSource
1// Component ported and enhanced from https://codepen.io/JuanFuentes/pen/eYEeoyE23import { useEffect, useRef } from 'react';4import * as THREE from 'three';56const vertexShader = `7varying vec2 vUv;8uniform float uTime;9uniform float mouse;10uniform float uEnableWaves;1112void main() {13 vUv = uv;14 float time = uTime * 5.;1516 float waveFactor = uEnableWaves;1718 vec3 transformed = position;1920 transformed.x += sin(time + position.y) * 0.5 * waveFactor;21 transformed.y += cos(time + position.z) * 0.15 * waveFactor;22 transformed.z += sin(time + position.x) * waveFactor;2324 gl_Position = projectionMatrix * modelViewMatrix * vec4(transformed, 1.0);25}26`;2728const fragmentShader = `29varying vec2 vUv;30uniform float mouse;31uniform float uTime;32uniform sampler2D uTexture;3334void main() {35 float time = uTime;36 vec2 pos = vUv;3738 float move = sin(time + mouse) * 0.01;39 float r = texture2D(uTexture, pos + cos(time * 2. - time + pos.x) * .01).r;40 float g = texture2D(uTexture, pos + tan(time * .5 + pos.x - time) * .01).g;41 float b = texture2D(uTexture, pos - cos(time * 2. + time + pos.y) * .01).b;42 float a = texture2D(uTexture, pos).a;43 gl_FragColor = vec4(r, g, b, a);44}45`;4647Math.map = function (n, start, stop, start2, stop2) {48 return ((n - start) / (stop - start)) * (stop2 - start2) + start2;49};5051const PX_RATIO = typeof window !== 'undefined' ? window.devicePixelRatio : 1;5253class AsciiFilter {54 constructor(renderer, { fontSize, fontFamily, charset, invert } = {}) {55 this.renderer = renderer;56 this.domElement = document.createElement('div');57 this.domElement.style.position = 'absolute';58 this.domElement.style.top = '0';59 this.domElement.style.left = '0';60 this.domElement.style.width = '100%';61 this.domElement.style.height = '100%';6263 this.pre = document.createElement('pre');64 this.domElement.appendChild(this.pre);6566 this.canvas = document.createElement('canvas');67 this.context = this.canvas.getContext('2d');68 this.domElement.appendChild(this.canvas);6970 this.deg = 0;71 this.invert = invert ?? true;72 this.fontSize = fontSize ?? 12;73 this.fontFamily = fontFamily ?? "'Courier New', monospace";74 this.charset = charset ?? ' .\'`^",:;Il!i~+_-?][}{1)(|/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$';7576 this.context.webkitImageSmoothingEnabled = false;77 this.context.mozImageSmoothingEnabled = false;78 this.context.msImageSmoothingEnabled = false;79// … truncated
What it pulls in
npm packages
Files it writes
More from @react-bits
All 556 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AnimatedContentAnimatedContent-JS-CSS | @react-bits | Components | Free | 1 dep | |
| AnimatedContentAnimatedContent-JS-TW | @react-bits | Components | Free | 1 dep | |
| AnimatedContentAnimatedContent-TS-CSS | @react-bits | Components | Free | 1 dep | |
| AnimatedContentAnimatedContent-TS-TW | @react-bits | Components | Free | 1 dep | |
| AnimatedListAnimatedList-JS-CSS | @react-bits | Components | Free | 1 dep · 2 files | |
| AnimatedListAnimatedList-JS-TW | @react-bits | Components | Free | 1 dep | |
| AnimatedListAnimatedList-TS-CSS | @react-bits | Components | Free | 1 dep · 2 files | |
| AnimatedListAnimatedList-TS-TW | @react-bits | Components | Free | 1 dep |
