Introduction to RGB color gradients using pixel drawing.
- Author
- Sukesh Ashok Kumar
This simple yet powerful example demonstrates the fundamentals of RGB color theory by creating a smooth color gradient along a horizontal line. Each pixel transitions from pure magenta (full red + blue) to pure blue, showing how colors blend.
Mathematical Concepts:
- Linear interpolation: smoothly transitioning between values
- Inverse relationships: as one value increases, another decreases
- Color space mapping: discrete values (0-255) for continuous colors
Programming Concepts:
- RGB color model (Red, Green, Blue channels)
- Each channel ranges from 0 (none) to 255 (maximum)
- Coordinate offset for positioning
- Single loop for sequential pixel drawing
What you'll learn:
- Understanding RGB color components
- How to create color gradients programmatically
- Using gfx_putpixel_color(x, y, r, g, b)
- Color mixing principles (red + blue = magenta/purple)
- Inverse relationships in color transitions
Color Gradient Breakdown:
- At x=0: RGB(0, 0, 255) = Pure Blue with Red increasing
- At x=128: RGB(128, 0, 127) = Purple (middle blend)
- At x=255: RGB(255, 0, 0) = Pure Red
- Green channel stays at 0 throughout, creating red-to-blue transition
Compile:
gcc line-rgb.c gfx/simplegfx.c -o output/line-rgb -lX11
Run: