I often want to test some code using canvas a lot recently, so I made this template to jump into writing code for canvas of 1080x1080.
The canvas is also always centered and resized to fit the screen which is also very helpful when coding in this editor. It also runs in 60FPS and has S, C, T, R dwitter declarations.
Boilerplate Code: 251b
Bookmarklet Code: 1,284b
data:text/html,<meta charset=utf8><title>canvas</title><link rel=icon href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 99 99"><text y="1em" font-size="72">🖼️</text></svg>'><textarea id=d spellcheck=false onkeypress=e=event;k=e.keyCode;(e.ctrlKey&&k==13)||k==10?f.srcdoc=d.value:0 style=resize:none;filter:invert(><canvas id=c><script>x=c.getContext`2d`,F=M=0,onload=U=e=>{requestAnimationFrame(U);if(F&&e<M-2)return;M=Math.max(M+1e3/60,e);T=F/60;if(T*60|0!=F++)T+=1e-6;E(T)};Z=onresize=_=>{W=c.width=innerWidth-19,H=c.height=innerHeight-19};Z()%0d%0du=r=d=l=0;X=Y=200%0donkeydown=onkeyup=e=>this[`lurd${"*".repeat(24)}l**r************l*d***u**u`[e.which-37]]=e.type[5]%0d%0dE=t=>{%0dx.fillStyle="blue";x.fillRect(0,0,W,H);x.font="1in'"%0dx.fillText('⚽',X+=l?-9:r?9:0,Y+=u?-9:d?9:0)%0d}</script></textarea><iframe id=f></iframe><p id=p style=position:fixed;bottom:1;color:white;background:black></p><script>D=null,d.onkeyup=d.onclick=n=>{clearTimeout(D),D=setTimeout(n=>{A=d.selectionStart,B=d.selectionEnd,V=d.value,E=V.substr(0,B).split`\n`,p.innerHTML=`Ln:${E.length}, Col:${E.pop().length+1}, ${A==B?"Pos:"+B:"Sel:"+(B-A)}, Len:${V.length}`},99)}</script><style>*{box-sizing:border-box;margin:0}textarea,iframe{width:50%;height:100%;vertical-align:top}Boilerplate Code: 360b (108b more than above)
- 1080x1080 fit-to-screen with gray background
- WASD/ZQSD/Arrow Key controls
- Moving Soccer ball
Bookmarklet Code: 1,379b
data:text/html,<meta charset=utf8><title>canvas</title><link rel=icon href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 99 99"><text y="1em" font-size="72">🖼️</text></svg>'><textarea id=d spellcheck=false onkeypress=e=event;k=e.keyCode;(e.ctrlKey&&k==13)||k==10?f.srcdoc=d.value:0 style=resize:none;filter:invert(><canvas id=c><script>c.width=c.height=1080;x=c.getContext`2d`,F=M=0,onload=U=e=>{requestAnimationFrame(U);if(F&&e<M-2)return;M=Math.max(M+1e3/60,e);T=F/60;if(T*60|0!=F++)T+=1e-6;E(T)}%0d%0du=r=d=l=0;X=Y=200%0donkeydown=onkeyup=e=>this[`lurd${"*".repeat(24)}l**r************l*d***u**u`[e.which-37]]=e.type[5]%0d%0dE=t=>{%0d%0dc.width|=0;x.font="1in'"%0dx.fillText('⚽',X+=l?-9:r?9:0,Y+=u?-9:d?9:0)%0d%0d}</script><style>html,body{background:%23222;display:flex;justify-content:center;align-items:center;height:100%;margin:0}%23c{background:white;max-height:100%;max-width:100%}</textarea><iframe id=f></iframe><p id=p style=position:fixed;bottom:1;color:white;background:black></p><script>D=null,d.onkeyup=d.onclick=n=>{clearTimeout(D),D=setTimeout(n=>{A=d.selectionStart,B=d.selectionEnd,V=d.value,E=V.substr(0,B).split`\n`,p.innerHTML=`Ln:${E.length}, Col:${E.pop().length+1}, ${A==B?"Pos:"+B:"Sel:"+(B-A)}, Len:${V.length}`},99)}</script><style>*{box-sizing:border-box;margin:0}textarea,iframe{width:50%;height:100%;vertical-align:top}<canvas id=c><script>x=c.getContext`2d`,F=M=0,onload=U=e=>{requestAnimationFrame(U);if(F&&e<M-2)return;M=Math.max(M+1e3/60,e);T=F/60;if(T*60|0!=F++)T+=1e-6;E(T)};Z=onresize=_=>{W=c.width=innerWidth-19,H=c.height=innerHeight-19};Z()
u=r=d=l=0;X=Y=200
onkeydown=onkeyup=e=>this[`lurd${"*".repeat(24)}l**r************l*d***u**u`[e.which-37]]=e.type[5]
E=t=>{
x.fillStyle="blue";x.fillRect(0,0,W,H);x.font="1in'"
x.fillText('⚽',X+=l?-9:r?9:0,Y+=u?-9:d?9:0)
}</script><canvas id=c><script>c.width=c.height=1e3;x=c.getContext`2d`,F=M=0,onload=U=e=>{requestAnimationFrame(U);if(F&&e<M-2)return;M=Math.max(M+1e3/60,e);T=F/60;if(T*60|0!=F++)T+=1e-6;E(T)}
u=r=d=l=0;X=Y=200
onkeydown=onkeyup=e=>this[`lurd${"*".repeat(24)}l**r************l*d***u**u`[e.which-37]]=e.type[5]
E=t=>{
c.width|=0;x.font="1in'"
x.fillText('⚽',X+=l?-9:r?9:0,Y+=u?-9:d?9:0)
}</script><style>html,body{background:#222;display:flex;justify-content:center;align-items:center;height:100%;margin:0}#c{background:white;max-height:100%;max-width:100%}