Ticket #5605 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

Construct Color objects using hsl and hsv values

Reported by: jason Owned by: was
Priority: minor Milestone: sage-4.4.2
Component: graphics Keywords:
Cc: mvngu Work issues:
Report Upstream: N/A Reviewers:
Authors: Merged in:
Dependencies: Stopgaps:

Description (last modified by mpatel) (diff)

See  http://en.wikipedia.org/wiki/HSL_and_HSV

See also this thread, where the idea came up:  http://groups.google.com/group/sage-support/browse_thread/thread/44971aa416574675

Related tickets:

  • #5601 - predefine colors in Sage.
  • #5602 - make .lighter() and .darker() methods for Sage Color objects.
  • #5603 - make a .mix() method for Sage color objects.
  • #5604 - average Color objects when adding them together.
  • #5605 - Construct Color objects using hsl and hsv values.

Change History

comment:1 Changed 4 years ago by mpatel

  • Description modified (diff)

comment:2 Changed 4 years ago by mpatel

On the RGB converters:

sage: from sage.plot.colors import rgbcolor, to_mpl_color
sage: rgbcolor('#ffffff')
(0.99609375, 0.99609375, 0.99609375)
sage: to_mpl_color('#ffffff')
(1.0, 1.0, 1.0)

Both

Color(rgbcolor(hx)).html_color() == hx
Color(to_mpl_color(hx)).html_color() == hx

are True for all hex colors hx, but we should fix rgbcolor and/or unify it with to_mpl_color. I'll do this as part of #5601's patch, which may also cover #5602 and, perhaps, this ticket.

comment:3 Changed 4 years ago by mpatel

See the patch at #5601.

comment:4 Changed 3 years ago by jason

  • Cc mvngu added
  • Report Upstream set to N/A

This works now. From the doctests of sage.plot.colors.Color:

          sage: Color(0.5, 1.0, 1, space='hsv')
          RGB color (0.0, 1.0, 1.0)
          sage: Color(0.25, 0.5, 0.5, space='hls')
          RGB color (0.50000000000000011, 0.75, 0.25)

So this should be closed.

comment:5 Changed 3 years ago by mvngu

  • Status changed from new to closed
  • Resolution set to fixed

Close as fixed:

[mvngu@sage ~]$ sage
----------------------------------------------------------------------
| Sage Version 4.4.1, Release Date: 2010-05-02                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: Color(0.5, 1.0, 1, space='hsv')
RGB color (0.0, 1.0, 1.0)
sage: Color(0.5, 1.0, 1, space='hls')
RGB color (1.0, 1.0, 1.0)
sage: Color(0.25, 0.5, 0.5, space='hls')
RGB color (0.50000000000000011, 0.75, 0.25)
sage: Color(0.25, 0.5, 0.5, space='hsv')
RGB color (0.375, 0.5, 0.25)
Note: See TracTickets for help on using tickets.