Skip to content

Color-related APIs design #555

@nighca

Description

@nighca

Existed APIs

Type Color (spx v1)

alias for image/color.RGBA

type RGBA struct {
  R, G, B, A uint8
}

func (c RGBA) RGBA() (r, g, b, a uint32)

Utils (spx v1)

  • RGB(r, g, b uint8) Color
  • RGBA(r, g, b, a uint8) Color

Touching (spx v1)

  • TouchingColor(color Color) bool

Pen (Scratch < v3)

Pen (spx v1)

  • SetPenColor(color Color)
  • ChangePenColor(delta float64) (not implemented)
  • SetPenShade(shade float64)
  • ChangePenShade(delta float64)
  • SetPenHue(hue float64)
  • ChangePenHue(delta float64)

Pen (Scratch v3)

Effects (Scratch v3)

  • Set (color|brightness|ghost) effect to ()
  • Change (color|brightness|ghost) effect by ()
    • for color(hue), range [0, 200] is used
    • for brightness, range [-100, 100] is used
    • for ghost(transparency), range [0, 100] is used

Proposal for spx v2

Use HSB instead of RGB as the main color model:

  • When providing color picker in UI, use HSB
  • When providing detailed-color-manipulation APIs, use HSB
  • Provide utility functions to generate color value based on HSB value

Provide APIs as below:

Type Color

type Color struct {
  // no exported fields or methods
}

Utils

func RGB(r, g, b uint8) Color
func RGBA(r, g, b, a uint8) Color

// h, s, b, a in range [0, 100], just like Scratch
func HSB(h, s, b float64) Color
func HSBA(h, s, b, a float64) Color

Touching

func TouchingColor(color Color) bool

Pen

type PenColorParam int

const (
	PenHue PenColorParam = iota
	PenSaturation
	PenBrightness
)

func SetPenColor(color Color)
func SetPenColor(param PenColorParam, value float64)
func ChangePenColor(param PenColorParam, delta float64)

range [0, 100] is used for hue, saturation, and brightness

Effects

type EffectKind int

const (
  ColorEffect EffectKind = iota
  BrightnessEffect
  GhostEffect
  // ...
)

func SetEffect(kind EffectKind, value float64)
func ChangeEffect(kind EffectKind, delta float64)
  • for color(hue), range [0, 200] is used
  • for brightness, range [-100, 100] is used
  • for ghost(transparency), range [0, 100] is used

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions