The Drawing Grid
Understand the coordinate system: where is (0,0)? Which way do x and y go? Why does y go DOWN? Learn to place things exactly where you want.
Every canvas has an origin — the point (0, 0). In Glitchlab (and most computer graphics), the origin is at the top-left corner. That's where x = 0 and y = 0. Let's prove it by drawing a circle right at (0, 0) — notice it's tucked into the corner!
Try it!Try moving the circle to (200, 150) — where does it end up? That's the center of the canvas!
Here's the big gotcha: y goes DOWN, not up! In math class, y goes up. But on a screen, y = 0 is at the top and gets bigger as you go down. Think of it like reading a page — you start at the top and move down. Meanwhile, x works like you'd expect: it starts at 0 on the left and gets bigger to the right.
Now let's practice! Every shape function takes x and y as its first two arguments. For circle(x, y, radius), x and y are the center. For rect(x, y, w, h), x and y are the top-left corner. Let's place some shapes and label their positions.
Try it!Try drawing a circle at (0, 300) — that's the bottom-left corner. Can you place one at each corner?
Hard-coding numbers like 400 and 300 works, but what if you change the canvas size? The built-in variables width and height always know the canvas dimensions. Use width / 2 and height / 2 to find the center, no matter what size your canvas is!
Try it!Change size(400, 300) to size(300, 200) — do all the shapes still land in the right spots?
Let's build something useful: a coordinate explorer! It draws a subtle grid and shows you the exact (x, y) position of your mouse as you move it around. This is a great tool for figuring out where to place things in your own sketches.
Try it!Use this tool! Move your mouse to the center — is it near (200, 150)? Find all four corners.
What to try next
- Draw a face using circles and lines — use the coordinate explorer to find the right positions first
- Place 5 circles in a diagonal line from top-left to bottom-right (hint: both x and y increase together)
- Draw a shape at the exact center of the canvas, then change the canvas size — does it stay centered if you used width/2 and height/2?
- Create a "map" with labeled landmarks at specific coordinates, like a treasure map