Lens Distortion Grid
A test grid bent by a distortion slider: wide and fisheye lenses bulge outward, some telephotos pinch inward.
AI prompt
Interior photograph of a narrow modern hallway shot on a 14mm ultra-wide rectilinear lens, strong perspective convergence, slightly stretched corners, floor tiles forming a grid that bows subtly outward, ceiling lights leading to a vanishing point, bright even light, crisp detail, architectural photography. Lens variants: circular fisheye (heavy barrel distortion, curved horizon, 180 degree view, playful), 35mm natural (almost no distortion, straight lines), 135mm telephoto (compressed depth, flat perspective, slight pincushion). Negative: tilted verticals unless intended, warped faces, mismatched distortion between objects, black vignette corners.About this pattern
Definition
Lens distortion is how a lens bends straight lines. Wide-angle and fisheye lenses show barrel distortion (lines bulge outward from the centre); some telephoto lenses show slight pincushion distortion (lines curve inward).
When to use it
- Barrel distortion adds energy and a feeling of space in architecture, action and interiors; use it deliberately.
- Fisheye is an extreme, playful look; rectilinear wide lenses keep straight lines straight but stretch the corners.
- Portraits on very wide lenses distort faces; prefer 50 to 135mm for natural proportions.
What the controls do
- Presets (Normal, Wide, Fisheye, Tele) and a continuous Distortion slider from pincushion to barrel.
Motion & timing
- The grid redraws live with the slider.
- Reduced motion: no difference, nothing animates on its own.
Tips & variations
- Distortion is strongest at the edges, so keep important subjects and straight lines away from the corners.
- In prompts, name the lens type (fisheye, ultra-wide, 85mm) rather than only the effect.
Code of this live preview
<div class="bx"><canvas id="cv" width="300" height="140" role="img" aria-label="Distorted test grid"></canvas><div class="pre" id="pre" role="group" aria-label="Lens preset"><button data-k="0">Normal</button><button data-k="0.18">Wide</button><button data-k="0.55">Fisheye</button><button data-k="-0.1">Tele</button></div><label class="ctl">Distortion <b id="kv">0.00</b><input id="k" type="range" min="-15" max="70" value="0"></label></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.bx{width:min(300px,100%);display:grid;gap:8px}
canvas{display:block;width:100%;height:auto;border-radius:12px;background:#fff;border:1px solid var(--line)}
.pre{display:grid;grid-template-columns:repeat(4,1fr);gap:5px}.pre button{height:28px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11.5px;cursor:pointer;padding:0}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.ctl{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.ctl b{color:var(--text)}
input[type=range]{width:100%;accent-color:#171717}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){*{transition:none}}const cv=document.getElementById('cv'),cx=cv.getContext('2d'),k=document.getElementById('k'),kv=document.getElementById('kv'),bs=[...document.querySelectorAll('#pre button')],W=300,H=140;
function P(x,y,K){const r2=x*x+y*y,s=1/(1+K*.7*r2);return[W/2+x*s*(W/2)*.86,H/2+y*s*(H/2)*.95];}
function line(a,K,vert){cx.beginPath();for(let i=0;i<=40;i++){const t=-1+2*i/40,p=vert?P(a*1.15,t*.85,K):P(t*1.15,a*.85,K);i?cx.lineTo(p[0],p[1]):cx.moveTo(p[0],p[1]);}cx.stroke();}
function draw(){const K=+k.value/100;cx.clearRect(0,0,W,H);cx.fillStyle='#fff';cx.fillRect(0,0,W,H);cx.save();cx.beginPath();cx.rect(0,0,W,H);cx.clip();
cx.lineWidth=1.3;cx.strokeStyle='#bdbdb8';for(let a=-1;a<=1.01;a+=.25)line(a,K,true);for(let a=-1;a<=1.01;a+=.33)line(a,K,false);
cx.strokeStyle='#171717';cx.lineWidth=2;line(0,K,true);line(0,K,false);
cx.strokeStyle='#ff5a36';cx.lineWidth=2.2;cx.beginPath();[[-.55,-.45],[.55,-.45],[.55,.45],[-.55,.45],[-.55,-.45]].forEach((q,i)=>{const p=P(q[0],q[1],K);i?cx.lineTo(p[0],p[1]):cx.moveTo(p[0],p[1]);});cx.stroke();cx.restore();
kv.textContent=K.toFixed(2);bs.forEach(b=>b.setAttribute('aria-pressed',String(Math.abs(+b.dataset.k-K)<.005)));}
k.addEventListener('input',draw);bs.forEach(b=>b.addEventListener('click',()=>{k.value=Math.round(+b.dataset.k*100);draw();}));draw();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Lens Distortion Grid — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.bx{width:min(300px,100%);display:grid;gap:8px}
canvas{display:block;width:100%;height:auto;border-radius:12px;background:#fff;border:1px solid var(--line)}
.pre{display:grid;grid-template-columns:repeat(4,1fr);gap:5px}.pre button{height:28px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11.5px;cursor:pointer;padding:0}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.ctl{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.ctl b{color:var(--text)}
input[type=range]{width:100%;accent-color:#171717}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){*{transition:none}}
</style></head>
<body><div class="stage">
<div class="bx"><canvas id="cv" width="300" height="140" role="img" aria-label="Distorted test grid"></canvas><div class="pre" id="pre" role="group" aria-label="Lens preset"><button data-k="0">Normal</button><button data-k="0.18">Wide</button><button data-k="0.55">Fisheye</button><button data-k="-0.1">Tele</button></div><label class="ctl">Distortion <b id="kv">0.00</b><input id="k" type="range" min="-15" max="70" value="0"></label></div>
</div>
<script>
const cv=document.getElementById('cv'),cx=cv.getContext('2d'),k=document.getElementById('k'),kv=document.getElementById('kv'),bs=[...document.querySelectorAll('#pre button')],W=300,H=140;
function P(x,y,K){const r2=x*x+y*y,s=1/(1+K*.7*r2);return[W/2+x*s*(W/2)*.86,H/2+y*s*(H/2)*.95];}
function line(a,K,vert){cx.beginPath();for(let i=0;i<=40;i++){const t=-1+2*i/40,p=vert?P(a*1.15,t*.85,K):P(t*1.15,a*.85,K);i?cx.lineTo(p[0],p[1]):cx.moveTo(p[0],p[1]);}cx.stroke();}
function draw(){const K=+k.value/100;cx.clearRect(0,0,W,H);cx.fillStyle='#fff';cx.fillRect(0,0,W,H);cx.save();cx.beginPath();cx.rect(0,0,W,H);cx.clip();
cx.lineWidth=1.3;cx.strokeStyle='#bdbdb8';for(let a=-1;a<=1.01;a+=.25)line(a,K,true);for(let a=-1;a<=1.01;a+=.33)line(a,K,false);
cx.strokeStyle='#171717';cx.lineWidth=2;line(0,K,true);line(0,K,false);
cx.strokeStyle='#ff5a36';cx.lineWidth=2.2;cx.beginPath();[[-.55,-.45],[.55,-.45],[.55,.45],[-.55,.45],[-.55,-.45]].forEach((q,i)=>{const p=P(q[0],q[1],K);i?cx.lineTo(p[0],p[1]):cx.moveTo(p[0],p[1]);});cx.stroke();cx.restore();
kv.textContent=K.toFixed(2);bs.forEach(b=>b.setAttribute('aria-pressed',String(Math.abs(+b.dataset.k-K)<.005)));}
k.addEventListener('input',draw);bs.forEach(b=>b.addEventListener('click',()=>{k.value=Math.round(+b.dataset.k*100);draw();}));draw();
</script>
</body></html>