Advanced example demonstrating pixel-level RGB color manipulation.
- Author
- Sukesh Ashok Kumar
This example creates a beautiful filled circle with dynamic RGB color gradients. Unlike basic shape drawing, this demonstrates pixel-by-pixel color control, combining geometric calculations with color mathematics.
Mathematical Concepts:
- Distance formula: dist² = (x - cx)² + (y - cy)²
- Circle equation: x² + y² ≤ r² (filled circle)
- Normalized coordinates for color mapping
- Linear interpolation for gradients
Programming Concepts:
- Nested loops for 2D iteration
- Integer distance calculation (avoiding sqrt for performance)
- RGB color components (0-255 range)
- Typecasting to unsigned char
- Gradient calculations using position
What you'll learn:
- How to check if a point is inside a circle
- Creating color gradients based on position
- Efficient distance calculation without square root
- RGB color theory and mixing
- Using gfx_putpixel_color() for custom colors
- Bounding box optimization (only checking pixels near circle)
Color Gradient Explanation:
- Red: varies from left to right (horizontal gradient)
- Green: varies from top to bottom (vertical gradient)
- Blue: varies by distance from center (radial gradient)
Compile:
gcc circle-rgb.c gfx/simplegfx.c -o output/circle-rgb -lX11
Run: