CMYK-drukraster
Een getekende kustscène, opgebouwd uit vier gedraaide puntrasters in cyaan, magenta, geel en zwart, zoals een offsetpers drukt. Met de schuif stel je de rastergrootte in en met de knoppen zet je losse drukgangen aan of uit. Voor drukkerijen, uitgevers en tijdschriften. Canvas 2D in eigen code, geen WebGL nodig; tekent opnieuw bij formaatwijziging.
Zo gebruik je het
- Plak de HTML op de plek waar het onderdeel moet komen.
- Zet de CSS in je stylesheet. Alle klassen hebben een eigen voorvoegsel, dus niets botst met je eigen opmaak.
- Voeg de JavaScript toe en roep init() aan met het element waar de HTML in staat.
<!-- CMYK-drukraster · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie -->
<div class="jouw-container">
<div class="hcm">
<canvas class="hcm__c" role="img" aria-label="Vuurtoren in de duinen bij ondergaande zon, gedrukt als CMYK-raster"></canvas>
<div class="hcm__bal">
<label class="hcm__lab">Raster <input class="hcm__r" type="range" min="4" max="16" step="1" value="7" aria-label="Rastergrootte in pixels"><output class="hcm__o">7 px</output></label>
<div class="hcm__kan" role="group" aria-label="Drukgangen">
<button type="button" class="hcm__k" data-k="0" aria-pressed="true" title="Cyaan, 15 graden">C</button><button type="button" class="hcm__k" data-k="1" aria-pressed="true" title="Magenta, 75 graden">M</button><button type="button" class="hcm__k" data-k="2" aria-pressed="true" title="Geel, 0 graden">Y</button><button type="button" class="hcm__k" data-k="3" aria-pressed="true" title="Zwart, 45 graden">K</button>
</div>
</div>
</div>
</div>/* CMYK-drukraster · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie */
.hcm{position:absolute;inset:0;background:#fbfaf7;font-family:'Switzer',system-ui,sans-serif;color:#0a0a0a}
.hcm__c{position:absolute;inset:0;width:100%;height:100%;display:block}
.hcm__bal{position:absolute;left:8px;right:8px;bottom:8px;display:flex;justify-content:space-between;align-items:center;gap:8px;flex-wrap:wrap}
.hcm__lab{display:flex;align-items:center;gap:8px;padding:6px 9px;background:#fff;border:1px solid #e0ddd6;border-radius:4px;font-size:12.5px;font-weight:600}
.hcm__r{width:96px;height:24px;margin:0;accent-color:#F5480F}
.hcm__o{min-width:34px;font-weight:500;color:#5c5953;font-variant-numeric:tabular-nums}
.hcm__kan{display:flex;gap:4px}
.hcm__k{width:30px;height:30px;border:1px solid #e0ddd6;border-radius:4px;background:#fff;color:#9a968e;font:700 13px 'Switzer',system-ui,sans-serif;cursor:pointer;position:relative}
.hcm__k[aria-pressed="true"]{color:#0a0a0a;border-color:#0a0a0a}
.hcm__k[aria-pressed="true"]::after{content:'';position:absolute;left:5px;right:5px;bottom:4px;height:3px;border-radius:1px;background:var(--hcm-kl)}
.hcm__k[data-k="0"]{--hcm-kl:#00a3e0}.hcm__k[data-k="1"]{--hcm-kl:#e6007e}.hcm__k[data-k="2"]{--hcm-kl:#f7d600}.hcm__k[data-k="3"]{--hcm-kl:#231f20}
.hcm__k:focus-visible,.hcm__r:focus-visible{outline:2px solid #F5480F;outline-offset:2px}
@media (max-width:640px){.hcm__bal{left:6px;right:6px;bottom:6px;flex-wrap:nowrap;gap:4px}.hcm__lab{padding:4px 6px;gap:5px;font-size:12px}.hcm__r{width:64px}.hcm__o{min-width:30px}.hcm__kan{gap:3px}.hcm__k{width:26px;height:28px;font-size:12px}}// CMYK-drukraster · © 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){
const box = root.querySelector('.hcm'); if (!box) return;
const cv = box.querySelector('.hcm__c'), ctx = cv.getContext('2d'); if (!ctx) return;
const rng = box.querySelector('.hcm__r'), out = box.querySelector('.hcm__o');
const KAN = [
{ hoek: 15, kleur: 'rgb(0,163,224)' }, { hoek: 75, kleur: 'rgb(230,0,126)' },
{ hoek: 0, kleur: 'rgb(247,214,0)' }, { hoek: 45, kleur: 'rgb(35,31,32)' }
];
const aan = [true, true, true, true];
let W = 0, H = 0, bron = null;
// De scène zelf: lucht, zon, zee, duinen en een vuurtoren, getekend op een los canvas (dus niets uit een ander domein).
const scene = () => {
const c = document.createElement('canvas'); c.width = W; c.height = H; const g = c.getContext('2d');
const hor = H * 0.6;
let gr = g.createLinearGradient(0, 0, 0, hor); gr.addColorStop(0, '#6f9fc4'); gr.addColorStop(.65, '#e9c9a0'); gr.addColorStop(1, '#f3b07a');
g.fillStyle = gr; g.fillRect(0, 0, W, hor);
gr = g.createRadialGradient(W * .7, hor * .78, 0, W * .7, hor * .78, H * .2); gr.addColorStop(0, '#ffb15a'); gr.addColorStop(1, '#f5480f');
g.fillStyle = gr; g.beginPath(); g.arc(W * .7, hor * .78, H * .19, 0, Math.PI * 2); g.fill();
gr = g.createLinearGradient(0, hor, 0, H); gr.addColorStop(0, '#3d7a96'); gr.addColorStop(1, '#1d4357');
g.fillStyle = gr; g.fillRect(0, hor, W, H - hor);
g.fillStyle = '#c7b07a'; g.beginPath(); g.moveTo(0, H * .74); g.bezierCurveTo(W * .2, H * .64, W * .42, H * .72, W * .62, H * .7); g.bezierCurveTo(W * .8, H * .68, W * .92, H * .76, W, H * .73); g.lineTo(W, H); g.lineTo(0, H); g.fill();
g.fillStyle = '#5d6b3a'; g.beginPath(); g.moveTo(0, H * .84); g.bezierCurveTo(W * .25, H * .76, W * .5, H * .9, W * .75, H * .82); g.bezierCurveTo(W * .88, H * .78, W * .95, H * .84, W, H * .82); g.lineTo(W, H); g.lineTo(0, H); g.fill();
const tx = W * .27, top = H * .2, voet = H * .78, bo = H * .045, on = H * .075;
for (let i = 0; i < 6; i++) {
const y0 = top + (voet - top) * i / 6, y1 = top + (voet - top) * (i + 1) / 6;
const b0 = bo + (on - bo) * i / 6, b1 = bo + (on - bo) * (i + 1) / 6;
g.fillStyle = i % 2 ? '#f4f1ea' : '#c8261c';
g.beginPath(); g.moveTo(tx - b0, y0); g.lineTo(tx + b0, y0); g.lineTo(tx + b1, y1); g.lineTo(tx - b1, y1); g.fill();
}
g.fillStyle = '#1b1b1b'; g.fillRect(tx - bo * 1.25, top - H * .07, bo * 2.5, H * .07);
g.fillStyle = '#ffe9a8'; g.fillRect(tx - bo * .8, top - H * .055, bo * 1.6, H * .04);
return g.getImageData(0, 0, W, H).data;
};
const teken = () => {
const cel = +rng.value; out.textContent = cel + ' px';
const dpr = Math.min(2, window.devicePixelRatio || 1);
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.globalCompositeOperation = 'source-over'; ctx.fillStyle = '#fbfaf7'; ctx.fillRect(0, 0, W, H);
ctx.globalCompositeOperation = 'multiply';
const cx = W / 2, cy = H / 2, R = Math.hypot(W, H) / 2 + cel;
KAN.forEach((k, ki) => {
if (!aan[ki]) return;
const a = k.hoek * Math.PI / 180, co = Math.cos(a), si = Math.sin(a);
ctx.fillStyle = k.kleur; ctx.beginPath();
for (let v = -R; v <= R; v += cel) for (let u = -R; u <= R; u += cel) {
const x = cx + u * co - v * si, y = cy + u * si + v * co;
if (x < -cel || y < -cel || x > W + cel || y > H + cel) continue;
const px = Math.min(W - 1, Math.max(0, x | 0)), py = Math.min(H - 1, Math.max(0, y | 0)), o = (py * W + px) * 4;
const r = bron[o] / 255, gg = bron[o + 1] / 255, b = bron[o + 2] / 255;
const kz = 1 - Math.max(r, gg, b);
const w = ki === 3 ? kz : (kz >= 1 ? 0 : (1 - [r, gg, b][ki] - kz) / (1 - kz));
if (w < 0.03) continue;
const rad = Math.sqrt(w) * cel * 0.62;
ctx.moveTo(x + rad, y); ctx.arc(x, y, rad, 0, Math.PI * 2);
}
ctx.fill();
});
ctx.globalCompositeOperation = 'source-over';
};
const maat = () => {
const r = box.getBoundingClientRect(); const w = Math.round(r.width), h = Math.round(r.height);
if (!w || !h || (w === W && h === H)) return;
W = w; H = h; const dpr = Math.min(2, window.devicePixelRatio || 1);
cv.width = W * dpr; cv.height = H * dpr; bron = scene(); teken();
};
let raf = 0;
rng.addEventListener('input', () => { if (!raf) raf = requestAnimationFrame(() => { raf = 0; teken(); }); });
box.querySelectorAll('.hcm__k').forEach(b => b.addEventListener('click', () => {
const k = +b.dataset.k; aan[k] = !aan[k]; b.setAttribute('aria-pressed', String(aan[k])); teken();
}));
if ('ResizeObserver' in window) new ResizeObserver(maat).observe(box); else addEventListener('resize', maat);
maat();
}
init(document.querySelector('.jouw-container'));
Meer uit achtergronden & webgl
Iets gezien dat je mooi vindt?
Zet het in je selectie en stuur hem op. Dan bouwen we je site eromheen, in jouw huisstijl.
Neem contact op →