Color API Reference

Comprehensive color management system with support for multiple color spaces, gradients, and advanced color manipulation.

Color Creation

SetRGB(r, g, b float64)
Sets the current color using RGB values (0.0 to 1.0)
SetRGBA(r, g, b, a float64)
Sets the current color using RGBA values with alpha transparency
SetHSL(h, s, l float64)
Sets the current color using HSL values (Hue, Saturation, Lightness)
SetHex(hex string)
Sets the current color using hex color string (#RRGGBB or #RGB)
// RGB colors
dc.SetRGB(1.0, 0.5, 0.2)  // Orange
dc.SetRGBA(0.2, 0.8, 0.4, 0.7)  // Semi-transparent green

// HSL colors
dc.SetHSL(240, 1.0, 0.5)  // Pure blue

// Hex colors
dc.SetHex("#FF6B35")  // Orange
dc.SetHex("#3498DB")  // Blue

Color Spaces

RGB Color Space

Red, Green, Blue additive color model

RGB(255, 0, 0)
RGB(0, 255, 0)
RGB(0, 0, 255)

HSL Color Space

Hue, Saturation, Lightness intuitive color model

HSL(0°, 100%, 50%)
HSL(120°, 100%, 50%)
HSL(240°, 100%, 50%)

Gradients

NewLinearGradient(x0, y0, x1, y1 float64) *LinearGradient
Creates a linear gradient between two points
NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) *RadialGradient
Creates a radial gradient between two circles
AddColorStop(offset float64, color color.Color)
Adds a color stop to the gradient at the specified offset (0.0 to 1.0)
// Linear gradient
gradient := advancegg.NewLinearGradient(0, 0, 200, 0)
gradient.AddColorStop(0, color.RGBA{255, 0, 0, 255})    // Red
gradient.AddColorStop(0.5, color.RGBA{255, 255, 0, 255}) // Yellow
gradient.AddColorStop(1, color.RGBA{0, 255, 0, 255})    // Green

dc.SetFillStyle(gradient)
dc.DrawRectangle(0, 0, 200, 100)
dc.Fill()

// Radial gradient
radial := advancegg.NewRadialGradient(100, 100, 0, 100, 100, 50)
radial.AddColorStop(0, color.RGBA{255, 255, 255, 255})  // White center
radial.AddColorStop(1, color.RGBA{0, 0, 0, 255})        // Black edge

dc.SetFillStyle(radial)
dc.DrawCircle(100, 100, 50)
dc.Fill()

Color Manipulation

Lighten(color color.Color, amount float64) color.Color
Lightens a color by the specified amount (0.0 to 1.0)
Darken(color color.Color, amount float64) color.Color
Darkens a color by the specified amount (0.0 to 1.0)
Saturate(color color.Color, amount float64) color.Color
Increases color saturation by the specified amount
Desaturate(color color.Color, amount float64) color.Color
Decreases color saturation by the specified amount
// Color manipulation
baseColor := color.RGBA{100, 150, 200, 255}

// Lighten and darken
lighter := advancegg.Lighten(baseColor, 0.3)
darker := advancegg.Darken(baseColor, 0.3)

// Saturate and desaturate
saturated := advancegg.Saturate(baseColor, 0.5)
desaturated := advancegg.Desaturate(baseColor, 0.5)

// Mix colors
mixed := advancegg.MixColors(baseColor, color.RGBA{255, 0, 0, 255}, 0.5)

Color Palettes

Material Design
#F44336
#2196F3
#4CAF50
Flat UI
#E74C3C
#3498DB
#2ECC71
Pastel
#FFB3BA
#BAFFC9
#BAE1FF

Complete Examples

// Rainbow gradient
func createRainbow(dc *advancegg.Context) {
    gradient := advancegg.NewLinearGradient(0, 0, 400, 0)
    gradient.AddColorStop(0.0, color.RGBA{255, 0, 0, 255})    // Red
    gradient.AddColorStop(0.17, color.RGBA{255, 165, 0, 255}) // Orange
    gradient.AddColorStop(0.33, color.RGBA{255, 255, 0, 255}) // Yellow
    gradient.AddColorStop(0.5, color.RGBA{0, 255, 0, 255})    // Green
    gradient.AddColorStop(0.67, color.RGBA{0, 0, 255, 255})   // Blue
    gradient.AddColorStop(0.83, color.RGBA{75, 0, 130, 255})  // Indigo
    gradient.AddColorStop(1.0, color.RGBA{238, 130, 238, 255}) // Violet
    
    dc.SetFillStyle(gradient)
    dc.DrawRectangle(0, 0, 400, 100)
    dc.Fill()
}

// Color wheel
func createColorWheel(dc *advancegg.Context) {
    centerX, centerY := 200.0, 200.0
    radius := 100.0
    
    for angle := 0.0; angle < 360.0; angle += 1.0 {
        hue := angle
        saturation := 1.0
        lightness := 0.5
        
        dc.SetHSL(hue, saturation, lightness)
        
        x1 := centerX + math.Cos(angle*math.Pi/180) * radius * 0.8
        y1 := centerY + math.Sin(angle*math.Pi/180) * radius * 0.8
        x2 := centerX + math.Cos(angle*math.Pi/180) * radius
        y2 := centerY + math.Sin(angle*math.Pi/180) * radius
        
        dc.SetLineWidth(2)
        dc.MoveTo(x1, y1)
        dc.LineTo(x2, y2)
        dc.Stroke()
    }
}