Introduction to Cartesian coordinate system and point plotting.
- Author
- Sukesh Ashok Kumar
This fundamental example introduces the Cartesian coordinate system (X-Y plane) by plotting a grid of discrete points. It's the foundation for understanding how mathematical coordinates translate to screen pixels.
Mathematical Concepts:
- Cartesian coordinate system: X-Y plane
- Ordered pairs (x, y): each point has a unique position
- Discrete mathematics: plotting individual points vs continuous lines
- Grid structure: evenly spaced points in 2D space
- Domain and range: x ∈ [50, 200], y ∈ [50, 200]
Programming Concepts:
- Nested for loops for 2D iteration
- Loop increment by steps (x += 10)
- Coordinate mapping: math coordinates → screen pixels
- Pattern generation through structured iteration
What you'll learn:
- How Cartesian coordinates work in computer graphics
- Screen coordinates: origin (0,0) is top-left corner
- Creating regular patterns with nested loops
- The relationship between mathematical points and pixels
- Using gfx_putpixel(x, y) for point plotting
- Loop increment shortcuts (x += 10 means x = x + 10)
Grid Explanation:
- Creates a 16×16 grid of points (16 columns × 16 rows)
- Points are spaced 10 pixels apart
- Covers a 150×150 pixel region
- Each point represents an ordered pair (x, y)
Visual Result: A square grid of dots demonstrating how discrete points can represent the coordinate plane in computer graphics.
Compile:
gcc m-plotting-points.c gfx/simplegfx.c -o output/m-plotting-points -lX11
Run:
./output/m-plotting-points