Chapter 44: Canvas Radial Gradients

1. What is a Radial Gradient in Canvas? (Clear definition first)

A radial gradient in Canvas means a smooth color transition that spreads outward from a central point — like ripples in water, light from a bulb, a glowing orb, a shiny button highlight, or a sunset sky in a circle.

It is the circular / round version of the linear gradient we studied earlier.

Instead of changing color along a straight line, the color changes from the center outward in all directions — usually brightest / lightest in the middle and darker / different color toward the edges.

Real-life examples you see every day:

  • Shiny metallic buttons (white highlight in center → dark metal edge)
  • Glowing neon orbs / loaders
  • Glass / plastic / bubble effects
  • Spotlight / vignette effect
  • 3D-looking spheres or orbs
  • Radial progress indicators

2. How to Create & Use a Radial Gradient (Core Steps)

You need three main steps (almost same as linear, but different method):

  1. Create the gradient object with createRadialGradient(cx0, cy0, r0, cx1, cy1, r1)
  2. Add color stops with addColorStop(offset, color)
  3. Assign it to fillStyle or strokeStyle and draw your shape

Basic syntax:

JavaScript

Most common pattern (simple glowing orb):

JavaScript

3. Your First Radial Gradient – Shiny Orb / Ball (Copy-Paste & Run)

Create canvas-radial-gradient.html:

HTML

What you see:

  • Left orb: perfect center glow (white → cyan → dark blue)
  • Right orb: light coming from top-left (more realistic 3D look)

4. All Important Parts of Radial Gradients (With Copy-Paste Snippets)

A. Perfect Center Glow (most common)

JavaScript

B. Ring / Donut Effect (inner radius > 0)

JavaScript

→ Hollow center, colorful ring

C. Multiple Stops + Transparency

JavaScript

→ Soft white radial vignette overlay

D. Gradient on Stroke (Glowing Border)

JavaScript

→ Neon glowing ring

5. Teacher’s Quick Tips (Hyderabad Student Style 😄)

  • Inner radius = 0 → sharp bright center (most realistic orbs)
  • Inner radius > 0 → hollow / ring / donut effect
  • Use fx/fy parameters (focal point) to shift highlight (advanced)
JavaScript
  • Common mistake #1: Forget to assign gradient to fillStyle / strokeStyle → solid color instead
  • Common mistake #2: Same inner & outer center + radius → no gradient
  • Pro tip: Combine radial + linear gradient on same shape → metallic shine (linear base + radial highlight)
  • Pro tip 2: Add shadowBlur + shadowColor → extra glow
JavaScript

Understood Canvas Radial Gradients fully now? This is one of the most beautiful and most-used effects in Canvas — almost every shiny button, orb loader, glassmorphism card, glowing icon, progress ring, and modern UI element uses radial gradients.

Tell me what you want next — we can build on this:

  • Full animated pulsing orb (radial gradient + scale)?
  • Metallic button with linear + radial + shadow?
  • Glassmorphism card with radial + blur?
  • Radial progress circle / gauge?
  • Or 15-question radial gradient quiz?

Just say — we keep going step by step together! 🚀

You may also like...

Leave a Reply

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