The Life Starter
0 of 6 complete0%
Course Library · Lesson 4 of 6
Create · Guided lesson

Add pointer and keyboard controls

About 36 minutes · 6 reading + 30 practice and checks
Time includes reading, practice, and questions. Extra videos or further study are optional.
See this course’s project requirements

An original interactive geometric artwork with palette and spacing controls, optional motion, a text description, inspected PNG and runnable source.

Keep your working files in your own notebook or software. Save a private description, checklist, and work link in My Proof.

What to include

  • Coordinate, grid-count and edge-fit calculations.
  • Two intentional original composition choices.
  • Equivalent pointer/button/keyboard controls with boundary tests.
  • Optional motion, pause and useful text support.
  • Inspected PNG plus complete source and dependency notes.

Review and revise

Use these criteria to check your work and choose what to improve.

  • The layout matches its calculations and fits the canvas.
  • Controls update bounded state consistently.
  • Motion and text support are usable and explained.
  • Image and source handoff are complete.
Open the full course project
Want more background?
Before you begin

The idea in everyday life

Create Tile Garden, an original geometric artwork with optional motion and multiple control routes.

The idea

An input handler changes state; the next draw uses that state to render the result.

Follow along

Add pointer and keyboard controls — guided practice

Trace input events to bounded state changes with equivalent visible controls.

Save index.html and sketch.js from the practice files in the same new folder. Open index.html in a modern browser while online; the page loads the free p5.js 2.3.3 library from the CDN URL listed by the official download page. No account is needed. If you need offline use, download that library as p5.min.js from the official page and change only the library script src to p5.min.js. Edit sketch.js with a plain-text code editor, save, and reload the page after code changes. Use browser developer tools Console to inspect errors. Restore the original constants after each changed case unless instructed otherwise.

  1. 1. Test pointer and button

    Click the canvas once, note the palette change, then click Next palette.

    You should see: Both advance the same palette state through nextPalette.

    Equivalent inputs can share one function instead of duplicating logic.

  2. 2. Test keyboard spacing

    Tab to the canvas so its focus outline is visible. Press Right once from spacing 70, then Left once.

    You should see: The status shows 75, then 70 pixels.

    The key handler is scoped to the focused canvas and prevents arrow scrolling for those handled keys.

  3. 3. Test equivalent buttons

    Use More spacing until the value stops, then Less spacing until it stops.

    You should see: The allowed range is 40–80 pixels.

    Visible buttons provide the same adjustment without requiring a canvas-specific keyboard gesture.

  4. 4. Inspect the guard

    Read Math.max(40,Math.min(80,spacing+amount)). From 75, predict three +5 requests.

    You should see: The results are 80,80,80.

    Clamping constrains state before drawing uses it.

Now change one thing

Spacing is 75 with an upper limit 80. Two +5 requests occur. Enter the final spacing.

Your work

What to finish

A pointer/button/keyboard test log including both spacing boundaries.

Common mistake

Watch for this

Implementing a pointer-only control with no equivalent keyboard-operable option.

How can I tell I understand it?

Complete the changed case, explain your result, and pass the three application checks.

Try 3 questions

Quick knowledge check

Answer all 3 questions. Get at least 2 right and the lesson completes automatically.

Not yet passed

You’ll get an explanation for each answer. Signed in? Your results save to your account.

1The canvas and a button should do the same palette action. What is maintainable?
2Spacing is 42 and a request adds-5 with lower bound 40. Result?
3Why keep spacing controls as visible buttons as well as canvas keys?
0 of 3 answeredApply the lesson to a short question, then review the explanation.
4
Finish this lesson

Pass the check. We’ll save the progress.

Answer all 3 questions above and get at least 2 right. You can review the explanations and try again.

Go to the knowledge check
Optional course overview video · same video as Lesson 1
The Coding TrainCreative Coding for Beginners with p5.js (1.1)YouTube
Optional course overview

Creative Coding for Beginners with p5.js (1.1)

From The Coding Train. Watch here or open it on YouTube .

Optional course overview. Follow the written steps below at your own pace.
Tools, templates, and lesson sources

Tools and templates

Tools open in a new tab so you can keep your place here.

Sources and further reading

Explore the references behind this lesson.

p5.js: Get started
Source & access notes · checked 2026-09-12

Opened and inspected on 2026-09-12: Setup/draw, canvas and beginner editor workflow.

Access: Free public web page; no paid enrollment required.

Reuse: Public reference; link only. LifeStarter prose, exercises and files are independently authored.

p5.js: Variables and Change
Source & access notes · checked 2026-09-12

Opened and inspected on 2026-09-12: Using variables to change visual output.

Access: Free public web page; no paid enrollment required.

Reuse: Public reference; link only. LifeStarter prose, exercises and files are independently authored.

Report a problem with this lesson

Tell us what went wrong. Please leave out personal information and private project contents.

No sign-in needed.