Rasterfoto in drie kleuren
A photo built from a fixed pattern of dots in black, orange and light grey (Bayer 8x8), with a light spot that follows the cursor and a slider for grain size; gives images a print or old-screen feel.
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.
<!-- Rasterfoto in drie kleuren · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie -->
<div class="jouw-container">
<div class="hrdi"><canvas class="hrdi__cv" role="img" aria-label="Woonkamer aan een Amsterdamse gracht, gerasterd in zwart, oranje en lichtgrijs"></canvas><label class="hrdi__ctl"><span class="hrdi__lab">Korrel</span><input class="hrdi__in" type="range" min="2" max="9" step="1" value="3"></label></div>
</div>/* Rasterfoto in drie kleuren · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie */
.hrdi{position:absolute;inset:0;overflow:hidden;background:#0a0a0a;font-family:'Switzer',sans-serif}
.hrdi__cv{position:absolute;inset:0;width:100%;height:100%;display:block;image-rendering:pixelated;cursor:crosshair}
.hrdi__ctl{position:absolute;right:10px;bottom:10px;display:flex;align-items:center;gap:10px;height:36px;padding:0 12px;background:#fff;color:#0a0a0a;border-radius:4px;font-size:13px;font-weight:500}
.hrdi__in{width:96px;height:24px;margin:0;accent-color:#F5480F;cursor:pointer}// Rasterfoto in drie kleuren · © 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 w=root.querySelector('.hrdi');if(!w)return;
var cv=w.querySelector('.hrdi__cv'),ctx=cv.getContext('2d'),inp=w.querySelector('.hrdi__in');
var reduce=matchMedia('(prefers-reduced-motion: reduce)').matches;
var B=[[0,2],[3,1]];while(B.length<8){var m=B.length,nb=[];for(var y=0;y<m*2;y++){nb.push([]);for(var x=0;x<m*2;x++){var q=B[y%m][x%m]*4;nb[y].push(q+[[0,2],[3,1]][(y/m)|0][(x/m)|0]);}}B=nb;}
var KL=[[10,10,10],[245,72,15],[244,243,241]];
var img=new Image(),bron=null,lum=null,gw=0,gh=0,cel=3,small=document.createElement('canvas'),sctx=small.getContext('2d'),id=null;
var px=.6,py=.4,tx=.6,ty=.4,binnen=false,t0=performance.now(),vis=true,run=false;
function nepbron(){var c=document.createElement('canvas');c.width=320;c.height=200;var g=c.getContext('2d');
var lg=g.createLinearGradient(0,0,0,200);lg.addColorStop(0,'#ddd');lg.addColorStop(.6,'#888');lg.addColorStop(1,'#222');g.fillStyle=lg;g.fillRect(0,0,320,200);
g.fillStyle='#fff';g.beginPath();g.arc(220,80,46,0,7);g.fill();g.fillStyle='#111';g.fillRect(0,150,320,50);g.fillRect(60,70,8,90);g.fillRect(40,66,90,6);return c;}
function maak(){var r=w.getBoundingClientRect();if(!r.width||!r.height||!bron)return;cel=+inp.value;
cv.width=Math.round(r.width);cv.height=Math.round(r.height);gw=Math.ceil(r.width/cel);gh=Math.ceil(r.height/cel);small.width=gw;small.height=gh;
var bw=bron.width||bron.naturalWidth,bh=bron.height||bron.naturalHeight,s=Math.max(gw/bw,gh/bh),dw=bw*s,dh=bh*s;
sctx.drawImage(bron,(gw-dw)/2,(gh-dh)/2,dw,dh);var d;
try{d=sctx.getImageData(0,0,gw,gh).data;}catch(e){bron=nepbron();return maak();}
lum=new Float32Array(gw*gh);for(var i=0;i<gw*gh;i++){var v=(d[i*4]*.299+d[i*4+1]*.587+d[i*4+2]*.114)/255;v=Math.pow(v,1.7);v=(v-.45)*1.3+.45;lum[i]=Math.max(0,Math.min(1,v));}
id=sctx.createImageData(gw,gh);teken();}
function teken(){if(!lum)return;var o=id.data,cx=px*gw,cy=py*gh,rr=Math.pow(Math.min(gw,gh)*.32,2);
for(var y=0;y<gh;y++){var by=B[y&7];for(var x=0;x<gw;x++){var i=y*gw+x,dx=x-cx,dy=y-cy;
var v=lum[i]+.38*Math.exp(-(dx*dx+dy*dy)/rr);var s2=Math.min(1.999,Math.max(0,v*2)),lv=s2|0;if(s2-lv>(by[x&7]+.5)/64)lv++;if(lv>2)lv=2;
var k=KL[lv],j=i*4;o[j]=k[0];o[j+1]=k[1];o[j+2]=k[2];o[j+3]=255;}}
sctx.putImageData(id,0,0);ctx.imageSmoothingEnabled=false;ctx.drawImage(small,0,0,gw,gh,0,0,gw*cel,gh*cel);}
function loop(t){if(!vis){run=false;return;}
if(!binnen&&!reduce){var s=(t-t0)/1000;tx=.5+.32*Math.sin(s*.45);ty=.45+.25*Math.sin(s*.7+1);}
var k=reduce?1:.12;px+=(tx-px)*k;py+=(ty-py)*k;teken();
if(reduce&&!binnen){run=false;return;}requestAnimationFrame(loop);}
function wake(){if(!run&&vis){run=true;requestAnimationFrame(loop);}}
cv.addEventListener('pointermove',function(e){var r=cv.getBoundingClientRect();tx=(e.clientX-r.left)/r.width;ty=(e.clientY-r.top)/r.height;binnen=true;wake();});
cv.addEventListener('pointerleave',function(){binnen=false;wake();});
inp.addEventListener('input',function(){maak();});
img.onload=function(){bron=img;maak();wake();};img.onerror=function(){bron=nepbron();maak();wake();};
img.src='https://neddev.com/lab-media/carousel-basis-1.webp';
if('ResizeObserver' in window)new ResizeObserver(function(){maak();}).observe(w);
if('IntersectionObserver' in window)new IntersectionObserver(function(es){vis=es[0].isIntersecting;if(vis)wake();}).observe(w);
}
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 →