Skip to content

Conversation

@paul-hammant
Copy link
Contributor

No description provided.

claude and others added 4 commits November 18, 2025 11:39
This commit introduces a full-featured color manipulation and selection
library for ChrysaLisp, including:

Library Components (lib/colors/):
- colors.inc: Core color library with 140+ web colors, HSV<->RGB conversion,
  ARGB utilities, hex parsing/formatting, color name lookup, and color
  manipulation functions (lighten, darken, saturate, desaturate, hue rotation,
  blending)
- picker.inc: ColorPicker GUI widget class with HSV sliders, RGB sliders,
  live preview, hex input/output, and web color palette (36 common colors)
- test.lisp: Comprehensive test suite for all color functions
- README.md: Complete documentation with examples and usage guide

Demo Application (apps/colorpicker/):
- Full-featured demo showcasing all color picker features
- Color information display (Hex, RGB, HSV values)
- Clipboard integration for copying color values
- Interactive color manipulation (lighten/darken/saturate/desaturate)
- Color name lookup and sample text/background previews

Features:
- HSV/RGB color space conversion with proper floating-point precision
- 140+ named web colors (HTML/CSS standard)
- Hex color parsing (#RGB and #RRGGBB formats)
- Color manipulation (lighten, darken, saturation, hue rotation, blending)
- Closest color name matching with configurable tolerance
- Interactive GUI widget with multiple input methods

Technical Details:
- Follows ChrysaLisp coding conventions (proper naming, no forward refs)
- Uses efficient O(1) web color lookups via Fmap
- Proper use of defq/setq, bind patterns, and iteration over recursion
- Widget inherits from Flow with proper action event handling
- Prevents feedback loops in UI updates with :updating flag
The hex input field and V slider were using the same event ID (base+2),
causing the hex input to never receive events.

Changes:
- Moved hex input to event ID base+6
- Moved palette buttons to event ID base+7+
- Updated action method to handle new event IDs correctly

This ensures all widget controls have unique event IDs and function properly.
Edge Case Tests (lib/colors/test_edges.lisp):
- Black and white boundary testing
- Grayscale values (S=0) across all hues
- Hue boundary tests (0° and 360° wrapping)
- Saturation extremes (0-100%)
- Value extremes (0-100%)
- Hex parsing edge cases (short form, case, invalid input)
- Color blending ratios (0.0, 0.5, 1.0)
- Color name lookup with tolerance
- ARGB packing with overflow values
- Round-trip precision testing with random colors
- 50+ individual test cases covering all edge conditions

Integration Examples (examples/colors/):

Example 1 - Basic Usage:
- Working with web colors
- RGB/HSV conversion
- Hex parsing and formatting
- Color manipulation functions
- Color blending
- Name lookup

Example 2 - Color Theming:
- Monochromatic theme generation
- Complementary color schemes
- Triadic color harmony
- Analogous colors
- Split-complementary themes
- Complete application theme creation
- Demonstrates color theory in practice

Example 3 - Widget Integration:
- Full GUI app with ColorPicker
- Real-time color preview
- Apply colors to UI elements
- Event handling patterns
- Integration best practices

Documentation:
- Comprehensive examples README
- Use case patterns
- Integration patterns
- Advanced topics (gradients, palettes)
- Tips and best practices

All examples are fully functional and demonstrate real-world usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants