ASCII Halftone Hover
A photo built from characters, bright where the image is bright; around the cursor the real photo shows through sharp. For a portfolio or campaign image that asks for a second look.
How to use it
- Paste the HTML where the backgrounds & webgl should appear.
- Add the CSS to your stylesheet. All classes are prefixed, so nothing clashes with your own styles.
- Add the JavaScript and call init() with the element that contains the HTML.
<!-- ASCII Halftone Hover · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie -->
<div class="jouw-container">
<div class="asc" data-beeld="https://neddev.com/lab-media/carousel-basis-2.webp">
<canvas class="asc__doek" role="img" aria-label="Rijtjeshuizen met dakkapellen, weergegeven als tekens"></canvas>
<p class="asc__hint" aria-hidden="true">Beweeg over het beeld</p>
</div>
</div>/* ASCII Halftone Hover · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie */
.asc{position:relative;width:100%;height:100%;background:#0a0a0a;overflow:hidden;touch-action:pan-y;font-family:Switzer,sans-serif;cursor:crosshair}
.asc__doek{position:absolute;inset:0;width:100%;height:100%;display:block}
.asc__hint{position:absolute;left:14px;bottom:10px;margin:0;padding:4px 8px;background:#0a0a0a;color:rgba(244,243,241,.7);font-size:13px;border-radius:4px;pointer-events:none;transition:opacity .3s ease}
.asc.is-actief .asc__hint{opacity:0}// ASCII Halftone Hover · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie
// root = het element waarin de HTML staat
function init(root){
var el=root.querySelector('.asc'); if(!el) return;
var cv=el.querySelector('.asc__doek'), ctx=cv.getContext('2d'); if(!ctx) return;
var stil=window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var RAMP=' .,:-=+*%#@';
var tekens=document.createElement('canvas'), foto=document.createElement('canvas'), lens=document.createElement('canvas');
var img=new Image(), klaar=false, W=0, H=0, dpr=1;
var muis={x:0,y:0,in:false}, pos={x:0,y:0}, straal=0, t0=performance.now(), zichtbaar=true, vuil=true;
function dek(c,w,h){ var s=Math.max(w/img.naturalWidth,h/img.naturalHeight), iw=img.naturalWidth*s, ih=img.naturalHeight*s; c.drawImage(img,(w-iw)/2,(h-ih)/2,iw,ih); }
function bouw(){
var r=el.getBoundingClientRect(); if(!r.width||!r.height) return;
dpr=Math.min(window.devicePixelRatio||1,2); W=Math.round(r.width*dpr); H=Math.round(r.height*dpr);
[cv,tekens,foto,lens].forEach(function(c){ c.width=W; c.height=H; });
var cel=(r.width<500?7:8)*dpr, hoog=cel*1.45, kol=Math.ceil(W/cel), rij=Math.ceil(H/hoog);
var klein=document.createElement('canvas'); klein.width=kol; klein.height=rij; var kc=klein.getContext('2d');
var lum=null;
if(img.naturalWidth){ dek(kc,kol,rij); try{ lum=kc.getImageData(0,0,kol,rij).data; }catch(e){ lum=null; } dek(foto.getContext('2d'),W,H); }
var tc=tekens.getContext('2d'); tc.fillStyle='#0a0a0a'; tc.fillRect(0,0,W,H);
tc.font='600 '+Math.round(hoog*0.92)+'px Switzer, sans-serif'; tc.textAlign='center'; tc.textBaseline='middle';
for(var y=0;y<rij;y++){ for(var x=0;x<kol;x++){
var v;
if(lum){ var i=(y*kol+x)*4; v=(lum[i]*0.3+lum[i+1]*0.59+lum[i+2]*0.11)/255; }
else { var u=x/kol-0.5, w=y/rij-0.55; v=0.55+0.4*Math.sin(u*9)*Math.cos(w*7)-Math.hypot(u,w)*0.5; }
v=Math.max(0,Math.min(1,(v-0.12)*1.25));
var ch=RAMP[Math.min(RAMP.length-1,Math.floor(v*RAMP.length))]; if(ch===' ') continue;
tc.fillStyle='rgba(244,243,241,'+(0.22+v*0.78).toFixed(2)+')';
tc.fillText(ch,x*cel+cel/2,y*hoog+hoog/2);
}}
if(!pos.x){ pos.x=W*0.5; pos.y=H*0.5; }
klaar=true; vuil=true;
}
function teken(){
ctx.clearRect(0,0,W,H); ctx.drawImage(tekens,0,0);
if(straal>1&&img.naturalWidth){
var lc=lens.getContext('2d'); lc.globalCompositeOperation='source-over'; lc.clearRect(0,0,W,H); lc.drawImage(foto,0,0);
lc.globalCompositeOperation='destination-in';
var g=lc.createRadialGradient(pos.x,pos.y,straal*0.45,pos.x,pos.y,straal);
g.addColorStop(0,'rgba(0,0,0,1)'); g.addColorStop(1,'rgba(0,0,0,0)');
lc.fillStyle=g; lc.fillRect(0,0,W,H); lc.globalCompositeOperation='source-over';
ctx.drawImage(lens,0,0);
}
}
el.addEventListener('pointermove',function(e){ var r=el.getBoundingClientRect(); muis.x=(e.clientX-r.left)*dpr; muis.y=(e.clientY-r.top)*dpr; muis.in=true; el.classList.add('is-actief'); vuil=true; });
el.addEventListener('pointerleave',function(){ muis.in=false; el.classList.remove('is-actief'); vuil=true; });
function stap(nu){
if(klaar&&zichtbaar){
var doelR=(muis.in?110:(stil?0:80))*dpr, tx, ty;
if(muis.in){ tx=muis.x; ty=muis.y; }
else { var s=(nu-t0)/1000; tx=W*(0.5+Math.sin(s*0.35)*0.3); ty=H*(0.5+Math.sin(s*0.55+0.8)*0.25); }
if(stil){ pos.x=tx; pos.y=ty; straal=doelR; }
else { pos.x+=(tx-pos.x)*0.12; pos.y+=(ty-pos.y)*0.12; straal+=(doelR-straal)*0.1; vuil=true; }
if(vuil){ teken(); vuil=false; }
}
requestAnimationFrame(stap);
}
if('IntersectionObserver' in window){ new IntersectionObserver(function(es){ zichtbaar=es[0].isIntersecting; }).observe(el); }
var wacht; if('ResizeObserver' in window){ new ResizeObserver(function(){ clearTimeout(wacht); wacht=setTimeout(bouw,120); }).observe(el); }
img.onload=function(){ (document.fonts&&document.fonts.ready?document.fonts.ready:Promise.resolve()).then(bouw); };
img.onerror=function(){ bouw(); };
img.src=el.getAttribute('data-beeld');
requestAnimationFrame(stap);
}
init(document.querySelector('.jouw-container'));
More backgrounds & webgl
Seen something you like?
Add it to your selection and send it over. We build your site around it, in your brand.
Get in touch →