Creative Visual Effects

Night Garden Interactive Particle Field

Complete an interactive particle field in a night garden scene: includes real content, actionable controls, clear status feedback, and responsive layouts across sizes.

Creative Visual EffectsInteractive Particle FieldHTMLCanvasJavaScript
With JavaScript enabled, you can edit, run, and save this example. The fixed source is as follows:
<!doctype html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Night Garden Interactive Particle Field</title>
  <style>
    :root { --ink:#18332f; --paper:#f4efe4; --accent:#d45f3e; --secondary:#8fc4ad; --line:color-mix(in srgb, var(--ink) 18%, transparent); --shadow:0 24px 60px color-mix(in srgb, var(--ink) 16%, transparent); color-scheme:light; }
    * { box-sizing:border-box; }
    html { min-width:320px; background:var(--paper); }
    body { min-height:100vh; margin:0; overflow-x:hidden; color:var(--ink); font-family:"Kaiti SC",STKaiti,"Songti SC",serif; background:radial-gradient(circle at 12% 18%,color-mix(in srgb,var(--accent) 12%,transparent) 0 1px,transparent 2px),var(--paper);background-size:19px 19px; }
    button,input,select,textarea { color:inherit; font:inherit; }
    button,[role="button"],input,select,textarea { accent-color:var(--accent); }
    button { cursor:pointer; }
    button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible,[tabindex]:focus-visible { outline:3px solid var(--accent); outline-offset:3px; }
    [hidden] { display:none !important; }
    @media (max-width:700px) { .mast h1 { line-height:1.08 !important; letter-spacing:-.035em !important; overflow-wrap:anywhere; } }
    @media (prefers-reduced-motion:reduce) { *,*::before,*::after { scroll-behavior:auto !important; animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; } }
    .page{width:min(980px,calc(100% - 32px));margin:auto;padding:72px 0 92px}.mast{display:grid;grid-template-columns:1fr auto;transform:rotate(-.25deg);gap:32px;align-items:center;margin-bottom:46px}.mast h1{font-family:"Kaiti SC",STKaiti,serif;font-weight:700;font-size:clamp(40px,8vw,84px);letter-spacing:.02em;margin:0;line-height:1.12}.intro{max-width:650px;margin-top:18px;line-height:2}.scenario{padding:12px;border:2px solid var(--accent);color:var(--accent);transform:rotate(3deg)}.eyebrow{display:block;margin-bottom:9px;color:var(--accent);letter-spacing:.18em}.demo{border-radius:2px;transform:rotate(.12deg);box-shadow:0 30px 70px color-mix(in srgb,var(--ink) 18%,transparent);position:relative;min-height:430px;overflow:hidden;padding:clamp(28px,6vw,66px);background:color-mix(in srgb,var(--paper) 92%,#fff)}@media(max-width:700px){.page{width:calc(100% - 20px);padding:28px 0}.mast{grid-template-columns:1fr}.scenario{justify-self:start}.demo{padding:20px}}
    .panel{padding:22px;border:1px solid var(--line);background:color-mix(in srgb,#fff 58%,transparent)}.stack{display:grid;gap:15px}.row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.action{min-height:44px;padding:10px 17px;border:1px solid var(--ink);border-radius:999px;background:transparent}.action.primary,.action.is-active{color:var(--paper);background:var(--accent)}.muted{opacity:.68}.status{min-height:24px;margin-top:15px;color:var(--accent);font-weight:800}.metric{font-size:clamp(30px,6vw,58px);font-weight:900}.meter{height:9px;overflow:hidden;border-radius:999px;background:color-mix(in srgb,var(--ink) 12%,transparent)}.meter>i{display:block;height:100%;background:var(--accent)}.chip{padding:6px 9px;border:1px solid var(--line);border-radius:999px;font-size:12px}
    .composition-gallery{margin:0;padding:clamp(8px,2vw,18px);border:1px solid var(--ink);background:color-mix(in srgb,var(--paper) 78%,transparent)}.gallery-caption{display:grid;grid-template-columns:auto 1fr auto;gap:16px;align-items:center;padding:15px 4px 2px;font-size:12px}.gallery-caption::before,.gallery-caption::after{content:"";height:1px;background:var(--line)}.gallery-caption strong{font:800 11px/1.2 ui-monospace,monospace;letter-spacing:.16em;text-transform:uppercase}.composition-gallery .demo{box-shadow:none}.composition-gallery .demo::before{content:"";position:absolute;inset:10px;border:1px dashed color-mix(in srgb,var(--accent) 36%,transparent);pointer-events:none}
    .particle-field-lab{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(230px,.6fr);gap:16px}.particle-field-lab canvas{width:100%;height:460px;border:1px solid var(--line);border-radius:22px;background:#07131f;touch-action:none}.particle-controls{display:grid;align-content:center;gap:17px}.particle-controls label{display:grid;grid-template-columns:1fr auto;gap:8px;font-weight:800}.particle-controls input{grid-column:1/-1;width:100%}@media(max-width:760px){.particle-field-lab{grid-template-columns:1fr}.particle-field-lab canvas{height:330px}}.workflow-session{display:grid;gap:14px}.session-command{display:grid;grid-template-columns:1fr auto minmax(170px,.45fr) auto;gap:16px;align-items:end;padding:18px;border-block:4px double var(--ink)}.session-command h2{margin:.2em 0}.session-command output{font:900 clamp(28px,5vw,54px)/1 ui-monospace,monospace}.session-command label{display:grid;grid-template-columns:1fr auto;gap:7px;font-size:12px}.session-command input{grid-column:1/-1;width:100%}#workflowSessionProgress{height:12px;overflow:hidden;border-radius:2px;background:var(--line)}#workflowSessionProgress i{display:block;width:0;height:100%;background:var(--accent)}.session-stage{min-width:0;transition:filter .25s,transform .25s}.session-stage[data-session-phase="running"]{transform:translateY(-3px)}.session-stage[data-session-phase="paused"]{filter:grayscale(.65)}.session-stage[data-session-phase="complete"]{filter:contrast(.78);opacity:.72}.session-log{display:grid;grid-template-columns:auto 1fr;gap:18px;align-items:start}.session-log ol{display:flex;flex-wrap:wrap;gap:7px;padding:0;margin:0;list-style:none}.session-log li{padding:5px 8px;border:1px solid var(--line);font-size:12px}@media(max-width:900px){.session-stage{order:-1}.session-command{grid-template-columns:1fr auto}.session-command label{grid-column:1/-1}.session-log{grid-template-columns:1fr}}
  </style>
</head>
<body data-aesthetic="paper" data-composition="gallery-frame">
  <main class="page">
    <header class="mast"><div><span class="eyebrow">paper / interactive particle field / INTERMEDIATE</span><h1>Night Garden Interactive Particle Field</h1><p class="intro">Complete an interactive particle field in a night garden scene: includes real content, actionable controls, clear status feedback, and responsive layouts across sizes.</p></div><span class="scenario">Night Garden</span></header>
    <figure class="composition-gallery"><section class="demo" aria-label="Interactive area for the night garden interactive particle field"><div class="workflow-session"><header class="session-command"><div><span class="eyebrow">Night Garden SESSION</span><h2>Garden Observation Timing Station</h2></div><output id="workflowSessionClock">00:45</output><label>Round Duration<input id="workflowSessionLength" type="range" min="15" max="90" step="15" value="45"><span>sec</span></label><button id="workflowSessionToggle" class="action primary" type="button">Start monitoring</button></header><div id="workflowSessionProgress" role="progressbar" aria-label="Garden Observation Progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><i></i></div><section id="workflowCore" class="workflow-core session-stage" data-session-phase="ready" tabindex="-1"><!-- 11DZ_CORE_START:creative-effects-particle-field --><div class="particle-field-lab"><canvas id="particleCanvas" width="960" height="480" tabindex="0" aria-label="Night Garden interactive particle field; move the pointer or use the arrow keys to attract particles" aria-describedby="particleHelp">Your browser does not support Canvas.</canvas><aside class="particle-controls panel"><span class="eyebrow">PARTICLE FIELD</span><h2>Interactive Particle Field</h2><p id="particleHelp" class="muted">Move the pointer on the canvas, or focus the canvas and use the arrow keys to move the attractor point.</p><label>Particle Count <input id="particleAmount" type="range" min="24" max="110" value="64" data-core-bridge="creative-effects-particle-field"><output id="particleAmountValue">64</output></label><label>Attraction Intensity <input id="particlePull" type="range" min="0" max="100" value="45"><output id="particlePullValue">45%</output></label><div class="row"><button id="particleReset" class="action primary" type="button">Reset particles</button><button id="particlePause" class="action" type="button" aria-pressed="false">Pause</button></div></aside></div><!-- 11DZ_CORE_END --></section><footer class="session-log"><strong id="workflowSessionScore">0 interaction checkpoints</strong><ol id="workflowSessionLaps" aria-label="Round Log"></ol></footer></div><p id="status" class="status" role="status" aria-live="polite"></p></section><figcaption class="gallery-caption"><strong>Night Garden / GALLERY 03</strong></figcaption></figure>
  </main>
  <script>
    'use strict';
    const statusOutput = document.querySelector('#status');
    const announce = message => { statusOutput.textContent = message; };
    /* 11DZ_CORE_SCRIPT_START:creative-effects-particle-field */
const particleCanvas=document.querySelector('#particleCanvas');const particleContext=particleCanvas.getContext('2d');const particleAmount=document.querySelector('#particleAmount');const particlePull=document.querySelector('#particlePull');const particleReduced=matchMedia('(prefers-reduced-motion: reduce)').matches;let particlePaused=particleReduced;let particleList=[];let particleTarget={x:0,y:0,active:false};let particleFrame=0;function sizeParticleCanvas(){const rect=particleCanvas.getBoundingClientRect();const ratio=Math.min(2,devicePixelRatio||1);particleCanvas.width=Math.max(320,Math.round(rect.width*ratio));particleCanvas.height=Math.max(260,Math.round(rect.height*ratio));particleContext.setTransform(ratio,0,0,ratio,0,0);if(!particleTarget.active){particleTarget.x=rect.width/2;particleTarget.y=rect.height/2;}}function resetParticles(){cancelAnimationFrame(particleFrame);const rect=particleCanvas.getBoundingClientRect();particleList=Array.from({length:Number(particleAmount.value)},(_,index)=>({x:(index*83%997)/997*rect.width,y:(index*47%509)/509*rect.height,vx:Math.sin(index*2.17)*.45,vy:Math.cos(index*1.73)*.45,r:1.5+index%4}));document.querySelector('#particleAmountValue').textContent=particleAmount.value;drawParticleField();announce('Particle field reset, total '+particleList.length+' particle');}function drawParticleField(){const rect=particleCanvas.getBoundingClientRect();particleContext.clearRect(0,0,rect.width,rect.height);particleContext.fillStyle='#07131f';particleContext.fillRect(0,0,rect.width,rect.height);const force=Number(particlePull.value)/17000;particleList.forEach((particle,index)=>{if(!particlePaused){if(particleTarget.active){const dx=particleTarget.x-particle.x;const dy=particleTarget.y-particle.y;const distance=Math.max(30,Math.hypot(dx,dy));particle.vx+=dx/distance*force*distance;particle.vy+=dy/distance*force*distance;}particle.vx*=.992;particle.vy*=.992;particle.x+=particle.vx;particle.y+=particle.vy;if(particle.x<0||particle.x>rect.width)particle.vx*=-1;if(particle.y<0||particle.y>rect.height)particle.vy*=-1;particle.x=Math.max(0,Math.min(rect.width,particle.x));particle.y=Math.max(0,Math.min(rect.height,particle.y));}particleContext.beginPath();particleContext.fillStyle=index%3?'#67e8f9':'#ff8a65';particleContext.arc(particle.x,particle.y,particle.r,0,Math.PI*2);particleContext.fill();particleList.slice(index+1,index+7).forEach(other=>{const distance=Math.hypot(other.x-particle.x,other.y-particle.y);if(distance<72){particleContext.beginPath();particleContext.strokeStyle='rgba(103,232,249,'+(1-distance/72)*.22+')';particleContext.moveTo(particle.x,particle.y);particleContext.lineTo(other.x,other.y);particleContext.stroke();}});});if(!particlePaused)particleFrame=requestAnimationFrame(drawParticleField);}function moveParticleTarget(clientX,clientY){const rect=particleCanvas.getBoundingClientRect();particleTarget={x:clientX-rect.left,y:clientY-rect.top,active:true};}particleCanvas.addEventListener('pointermove',event=>moveParticleTarget(event.clientX,event.clientY));particleCanvas.addEventListener('pointerleave',()=>{particleTarget.active=false;});particleCanvas.addEventListener('keydown',event=>{if(!['ArrowLeft','ArrowRight','ArrowUp','ArrowDown'].includes(event.key))return;event.preventDefault();particleTarget.active=true;particleTarget.x+=event.key==='ArrowRight'?18:event.key==='ArrowLeft'?-18:0;particleTarget.y+=event.key==='ArrowDown'?18:event.key==='ArrowUp'?-18:0;particleTarget.x=Math.max(0,Math.min(particleCanvas.clientWidth,particleTarget.x));particleTarget.y=Math.max(0,Math.min(particleCanvas.clientHeight,particleTarget.y));drawParticleField();});particleAmount.addEventListener('input',resetParticles);particlePull.addEventListener('input',()=>{document.querySelector('#particlePullValue').textContent=particlePull.value+'%';announce('Particle attraction intensity '+particlePull.value+'%');});document.querySelector('#particleReset').addEventListener('click',resetParticles);document.querySelector('#particlePause').addEventListener('click',event=>{particlePaused=!particlePaused;event.currentTarget.textContent=particlePaused?'Continue':'Pause';event.currentTarget.setAttribute('aria-pressed',String(particlePaused));cancelAnimationFrame(particleFrame);drawParticleField();announce(particlePaused?'Particle field paused':'Particle field keeps moving');});addEventListener('resize',()=>{sizeParticleCanvas();resetParticles();},{passive:true});sizeParticleCanvas();resetParticles();
/* 11DZ_CORE_SCRIPT_END */
const workflowBridgeSpec={"name":"creative-effects-particle-field","selector":"[data-core-bridge=\"creative-effects-particle-field\"]","mode":"range","key":"ArrowRight"};const workflowBridgeCore=document.querySelector('#workflowCore');const workflowBridgeControl=workflowBridgeCore.querySelector(workflowBridgeSpec.selector);if(!workflowBridgeControl)throw new Error('Missing core bridge: '+workflowBridgeSpec.name);const workflowBridgeControlledId=workflowBridgeControl.getAttribute('aria-controls');const workflowBridgeControlled=workflowBridgeControlledId?document.getElementById(workflowBridgeControlledId):null;workflowBridgeCore.dataset.workflowBridge=workflowBridgeSpec.name;workflowBridgeCore.dataset.workflowVersion='0';function workflowBridgeSerialize(){const visualNode=workflowBridgeCore.firstElementChild||workflowBridgeCore;const visual=getComputedStyle(visualNode);const outputs=[...workflowBridgeCore.querySelectorAll('output,[role="status"],[aria-live],meter,progress')].map(node=>node.textContent.trim()+'|'+node.getAttribute('aria-valuenow')+'|'+node.getAttribute('value'));const canvas=[...workflowBridgeCore.querySelectorAll('canvas')].map(node=>{try{return node.toDataURL().slice(-160);}catch{return 'canvas-unavailable';}});return JSON.stringify({html:workflowBridgeCore.innerHTML,status:statusOutput.textContent,outputs,canvas,visual:[visual.display,visual.visibility,visual.opacity,visual.transform,visual.filter,visual.backgroundColor,visual.width,visual.height],scroll:workflowBridgeSpec.mode==='scroll'?workflowBridgeControl.scrollTop:null});}let workflowBridgeLastEffect=workflowBridgeSerialize();function workflowBridgeSummary(){const label=(workflowBridgeControl.getAttribute('aria-label')||workflowBridgeControl.textContent||workflowBridgeControl.value||workflowBridgeSpec.name).trim().replace(/\s+/g,' ').slice(0,72);return label+' · Core Version '+workflowBridgeCore.dataset.workflowVersion;}function workflowBridgeCommit(){const effect=workflowBridgeSerialize();if(effect===workflowBridgeLastEffect)return {changed:false,summary:workflowBridgeSummary()};workflowBridgeLastEffect=effect;workflowBridgeCore.dataset.workflowVersion=String(Number(workflowBridgeCore.dataset.workflowVersion||0)+1);return {changed:true,summary:workflowBridgeSummary()};}function workflowBridgeScheduleCommit(){queueMicrotask(workflowBridgeCommit);setTimeout(workflowBridgeCommit,0);}workflowBridgeControl.addEventListener("input",workflowBridgeScheduleCommit);workflowBridgeControl.addEventListener('change',workflowBridgeScheduleCommit);const workflowBridgeStateTargets=new Set(workflowBridgeCore.querySelectorAll('dialog'));if(workflowBridgeControlled&&workflowBridgeCore.contains(workflowBridgeControlled))workflowBridgeStateTargets.add(workflowBridgeControlled);workflowBridgeStateTargets.forEach(target=>['close','cancel','toggle'].forEach(eventName=>target.addEventListener(eventName,workflowBridgeScheduleCommit)));function workflowBridgeActivate(){workflowBridgeControl.focus();const step=Number(workflowBridgeControl.step)||1;const min=workflowBridgeControl.min===''?-Infinity:Number(workflowBridgeControl.min);const max=workflowBridgeControl.max===''?Infinity:Number(workflowBridgeControl.max);let next=Math.min(max,Math.max(min,(Number(workflowBridgeControl.value)||0)+step));if(next===Number(workflowBridgeControl.value))next=Math.max(min,Number(workflowBridgeControl.value)-step);workflowBridgeControl.value=String(next);workflowBridgeControl.dispatchEvent(new Event('input',{bubbles:true}));workflowBridgeControl.dispatchEvent(new Event('change',{bubbles:true}));const result=workflowBridgeCommit();setTimeout(workflowBridgeCommit,0);return result;}function workflowBridgeReset(){workflowBridgeCore.dataset.workflowVersion='0';workflowBridgeLastEffect=workflowBridgeSerialize();}
const workflowSessionCore=document.querySelector('#workflowCore');const workflowSessionToggle=document.querySelector('#workflowSessionToggle');const workflowSessionLength=document.querySelector('#workflowSessionLength');const workflowSessionState={phase:'ready',elapsed:0,limit:Number(workflowSessionLength.value),checkpoints:[],timer:null};function workflowSessionFormat(seconds){return String(Math.floor(seconds/60)).padStart(2,'0')+':'+String(seconds%60).padStart(2,'0');}function workflowSessionDrive(){const percent=Math.min(100,Math.round(workflowSessionState.elapsed/workflowSessionState.limit*100));document.querySelector('#workflowSessionClock').textContent=workflowSessionFormat(Math.max(0,workflowSessionState.limit-workflowSessionState.elapsed));const progress=document.querySelector('#workflowSessionProgress');progress.setAttribute('aria-valuenow',String(percent));progress.querySelector('i').style.width=percent+'%';workflowSessionCore.dataset.sessionPhase=workflowSessionState.phase;document.querySelector('#workflowSessionScore').textContent=workflowSessionState.checkpoints.length+' interactive checkpoints';}function workflowSessionLap(label){workflowSessionState.checkpoints.push({label,at:workflowSessionState.elapsed});const item=document.createElement('li');item.textContent=label+' · '+workflowSessionFormat(workflowSessionState.elapsed);document.querySelector('#workflowSessionLaps').append(item);workflowSessionDrive();}function workflowSessionStop(complete=false){clearInterval(workflowSessionState.timer);workflowSessionState.timer=null;workflowSessionState.phase=complete?'complete':'paused';workflowSessionToggle.textContent=complete?'Restart':'Continue round';workflowSessionToggle.setAttribute('aria-pressed','false');workflowSessionDrive();announce(complete?'Garden Observation Round Complete':'Round paused');}function workflowSessionStart(){if(workflowSessionState.phase==='complete'){workflowSessionState.elapsed=0;workflowSessionState.checkpoints=[];document.querySelector('#workflowSessionLaps').replaceChildren();}workflowSessionState.phase='running';workflowSessionToggle.textContent='Pause round';workflowSessionToggle.setAttribute('aria-pressed','true');const bridge=workflowBridgeActivate();workflowSessionLap(bridge.summary);clearInterval(workflowSessionState.timer);workflowSessionState.timer=setInterval(()=>{workflowSessionState.elapsed+=1;if(workflowSessionState.elapsed>=workflowSessionState.limit){workflowSessionStop(true);return;}workflowSessionDrive();},1000);workflowSessionDrive();announce('Garden observation round has started · '+bridge.summary);}workflowSessionToggle.addEventListener('click',()=>workflowSessionState.phase==='running'?workflowSessionStop():workflowSessionStart());workflowSessionLength.addEventListener('input',()=>{workflowSessionState.limit=Number(workflowSessionLength.value);workflowSessionState.elapsed=Math.min(workflowSessionState.elapsed,workflowSessionState.limit);workflowSessionDrive();});workflowSessionCore.addEventListener('keydown',event=>{if(event.key==='Enter'||event.key===' '){workflowSessionLap('Keyboard Interaction');}});workflowSessionCore.addEventListener('click',event=>{if(event.target.closest('[data-core-bridge]'))workflowSessionLap('Core action · '+workflowBridgeSummary());});document.addEventListener('visibilitychange',()=>{if(document.hidden&&workflowSessionState.phase==='running')workflowSessionStop();});workflowSessionDrive();
workflowBridgeReset();
  </script>
</body>
</html>
Page feedbackFound an issue or have suggestions for improvement?
Feedback features need to be used in the online version

Please enable JavaScript in the online version before submitting; local features of the current tool or example are not affected.

Go to the online version for feedback