Chapter 41: Canvas Circles

1. What are “Canvas Circles” actually?

Canvas Circles means using JavaScript on the <canvas> element to draw perfect circular shapes (full circles, half-circles, pie slices, rings, arcs, dotted circles, glowing orbs, clocks, buttons, loaders, eyes in drawings, etc.).

In Canvas, there is no <circle> tag like in SVG. Instead, you use the arc() method to draw circles (and parts of circles).

The arc() method is extremely powerful — it can draw:

  • Full circles (360°)
  • Half-circles / semi-circles
  • Pie slices / sectors
  • Thin rings / donuts
  • Curved arcs (not full circle)
  • Smoothed curves when combined with other path commands

One golden rule everyone must remember from day one:

  • arc() always works inside a path → you must use beginPath(), then arc(), then fill() or stroke() (or both)

2. Syntax of arc() – The Heart of Canvas Circles

JavaScript

Parameters explained (very slowly):

  • centerX → horizontal center of the circle (from left edge of canvas)
  • centerY → vertical center (from top edge — remember Y increases down)
  • radius → distance from center to edge (in pixels)
  • startAngle → starting angle in radians (0 = right side, Math.PI/2 = bottom, Math.PI = left, 3*Math.PI/2 = top)
  • endAngle → ending angle in radians
  • counterclockwise → false = clockwise (default), true = counterclockwise (rarely used)

Important angles everyone must memorize:

  • 0 radians = right side (3 o’clock)
  • Math.PI / 2 = bottom (6 o’clock)
  • Math.PI = left (9 o’clock)
  • 3 * Math.PI / 2 = top (12 o’clock)
  • Math.PI * 2 = full circle (back to start)

3. Your First Canvas Circle – Hello World Style (Copy-Paste & Run)

Create canvas-circle-hello.html:

HTML

What you see:

  • Big yellow filled circle with orange border
  • Red half-circle / pie slice
  • Thick purple ring (donut style)

4. All Important Circle / Arc Commands & Tricks (With Copy-Paste)

A. Full Circle (most common)

JavaScript

B. Pie Slice / Sector (0 to 90° example)

JavaScript

C. Ring / Donut (stroke only – no fill)

JavaScript

D. Dashed Circle Outline

JavaScript

E. Circle with Shadow (very common in UI)

JavaScript

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

  • Always beginPath() before arc — prevents connecting to previous drawing
  • Angles are in radians — full circle = Math.PI * 2, half = Math.PI, quarter = Math.PI / 2
  • To make a perfect circle → endAngle must be Math.PI * 2 (or 0 to close naturally)
  • Common mistake #1: Forget fill() or stroke() after arc → invisible circle!
  • Common mistake #2: Wrong center (cx, cy) → circle appears in wrong place
  • Common mistake #3: No beginPath() → arc connects to previous line/path
  • Pro tip: Use ctx.save() / ctx.restore() when changing shadow / style
JavaScript

Understood Canvas Circles fully now? Circles (via arc()) are one of the most used shapes in Canvas — loaders, buttons, avatars, clocks, eyes, progress rings, glowing effects… almost everything.

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

  • Full animated spinning loader (circle + arc)?
  • Progress circle / circular loading bar?
  • Mouse-following circle trail?
  • Circle collision / bouncing balls?
  • Or 15-question Canvas circles 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 *