Chapter 35: Canvas Coordinates

Canvas Coordinates in the clearest, most patient way possible.

Imagine I’m sitting right next to you with my screen open, and we’re going to build understanding together step by step — no rushing, no skipping, lots of tiny visual examples, and repeated explanations until it feels natural.

1. The single most important sentence about Canvas coordinates

In HTML5 Canvas, the coordinate (0,0) is always at the top-left corner of the canvas element.

  • x increases → to the right
  • y increases → downward

This is the opposite of the math graphs you learned in school (where y usually goes up).

Quick mental picture (imagine this grid):

text

Every point on the canvas is described by a pair:

  • (x, y) → x = horizontal distance from left edge → y = vertical distance from top edge

2. Visual proof – where do these four points go?

Copy-paste and run this tiny example — it will make everything click instantly.

HTML

Run this code.

You will see:

  • Red dot at top-left → (0,0)
  • Blue dot at top-right → (600,0)
  • Green dot at bottom-left → (0,400)
  • Orange dot at bottom-right → (600,400)

This is the only coordinate system Canvas uses — always.

3. Common beginner confusion & how to fix it

Confusion 1 “I want the circle in the middle — why is it in the corner?”

JavaScript

Fix Use half the canvas size for center:

JavaScript

Confusion 2 “Why does y increase downward? I want it to go up like math class.”

Answer You cannot change it — that is how every screen coordinate system works (HTML, Canvas, most game engines, CSS, etc.). If you really want math-style y-up coordinates, you can flip the canvas once at the beginning:

JavaScript

Now (0,0) is bottom-left and y grows upward — but most people don’t do this because it flips text and images upside-down too.

Best advice: Just get used to y-down. After 2–3 days it feels completely normal.

4. Quick coordinate examples you should try

Example A – Four corners

JavaScript

Example B – Center circle

JavaScript

Example C – Diagonal line from top-left to bottom-right

JavaScript

5. Summary – One-page Canvas Coordinate Cheat Sheet

  • (0,0) = top-left corner
  • x → right
  • y → down
  • Center of canvas ≈ (canvas.width/2, canvas.height/2)
  • Bottom-right corner = (canvas.width, canvas.height)
  • All drawing commands (fillRect, arc, lineTo, fillText, etc.) use this system
  • No way to change it globally — learn to love y-down

Your tiny homework (5–10 minutes)

  1. Draw four colored squares — one in each corner of the canvas
  2. Draw a thick purple diagonal line from top-left to bottom-right
  3. Draw a big circle exactly in the center (use canvas.width/2 and canvas.height/2)

Paste your code here when you’re done — I’ll look at it like we’re sitting together debugging.

Which sentence or concept still feels a bit slippery?

  • The y-axis going down?
  • How to find the center every time?
  • Why coordinates are pixels and not percentages?
  • Something else?

Tell me — we’ll stay on coordinates until it feels 100% comfortable. You’re doing really well — this is the foundation everything else sits on! 🚀

You may also like...

Leave a Reply

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