Command Palette

Search for a command to run...

Hectal
Phase 3: three.js Foundations
3D Web · Exercise 2 of 5 PreviousNext
Beginner

Make the canvas follow its box

The canvas is sized once, to a fixed 200 × 100 pixels. Make it fill the <div id="app">, keep the camera's aspect in step with the box, and cap the pixel ratio at 2.

Use a ResizeObserver on #app, so it also works when only the box changes size.

What Check tests

  1. The canvas fills the box
  2. The camera aspect equals width / height
  3. It uses a ResizeObserver
  4. The pixel ratio is at most 2
  5. It follows when only the box changes

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.