Chapter 44: Canvas Radial Gradients

Canvas Radial Gradients in the clearest, most patient, step-by-step way possible.

Imagine I’m sitting right next to you with my laptop open. We’re going to build every single example together — slowly, with tiny complete snippets you can copy-paste and run immediately. No skipping steps, no magic formulas you don’t understand, just plain English explanations, visual thinking, common beginner traps, and repeated patterns until radial gradients feel completely natural and easy to control.

Canvas Radial Gradients – From Zero to Confident

1. The single most important sentence about radial gradients

A radial gradient in Canvas is a special paint recipe that spreads color outward from a central point (or small circle) toward a larger surrounding circle — like a glowing orb, a spotlight, a shiny button highlight, or a soft vignette.

It is not a straight line transition (that’s linear gradient). It is circular / radial — the color changes in rings from the inside out.

2. Mental model – Think of it like a flashlight or spotlight

  • You define an inner circle (the bright/hot center)
  • You define an outer circle (the fade-to-edge)
  • You place color stops along the radius (from center → edge)
  • The gradient fills everything between inner and outer circle
  • Anything outside the outer circle is the last color stop (by default)

3. The command you will use 99% of the time: createRadialGradient

JavaScript

Most common & beginner-friendly pattern (use this 90% of the time):

JavaScript

→ Inner radius = 0 → brightest spot exactly at center → Inner radius > 0 → bright ring instead of sharp dot

4. Minimal complete radial gradient example (copy → run)

HTML

What you should see & remember forever:

  • Bright white/yellow center → fades through orange → red edge
  • Inner radius = 20 → small bright core (not a sharp dot)
  • Outer radius = 140 → matches circle radius → gradient fills exactly to edge
  • addColorStop(offset 0..1, color) → offset 0 = inner circle, offset 1 = outer circle

5. Example 2 – Shiny button / highlight effect (very common pattern)

HTML

Key lessons from this example:

  • Radial gradient as overlay → creates realistic shine/highlight
  • Inner circle offset (not center) → light comes from top-left (very natural look)
  • Fade to transparent at outer edge → smooth blend into button color

6. Quick reference – Radial gradient patterns you’ll reuse often

Effect / Look Inner radius Outer radius Center offset? Typical stops sequence
Sharp glowing orb 0 shape radius No white → color → dark color
Soft spotlight / vignette 0–20 large No white → fade to transparent
Shiny button highlight 5–20 100–200 Yes (top-left) white → semi-transparent white → transparent
Metallic/chrome ring 20–40 shape radius Slight offset white → light gray → dark gray → black
Sunset radial background 0 canvas size Top center orange → purple → navy

7. Your three tiny practice tasks (10–15 min each)

Task 1 – Glowing orb Draw a purple circle Fill with radial gradient: white center → purple → very dark purple edge

Task 2 – Shiny pill button Draw a long rounded rectangle (pill shape) Fill with blue gradient Add white radial gradient overlay for top-left shine

Task 3 – Spotlight effect Fill whole canvas with dark color Draw large radial gradient circle (white center → transparent edge) in the middle → creates spotlight

Paste any of them here when you finish — I’ll review it like we’re pair-programming together.

──────────────────────────────

Which part still feels a little slippery?

  • Difference between linear vs radial gradients?
  • How to choose inner vs outer radius?
  • Why offset inner circle for shine/highlight?
  • Adding multiple color stops smoothly?
  • Radial gradient not filling the whole shape?
  • Something else?

Tell me — we’ll stay on radial gradients until you feel super confident creating any glowing, shiny, or spotlight effect you imagine.

You’re doing really well — radial gradients are one of the things that instantly make Canvas graphics look polished and 3D-like! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *