Ticket #5604 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

average Color objects when adding them together

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)

This would make it easy to create purple, for example, as red+blue.

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 3 years ago by jason

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

This is done now:

sage: sage.plot.colors.red+sage.plot.colors.blue
RGB color (0.5, 0.0, 0.5)

So this ticket should be closed.

comment:3 Changed 3 years ago by mvngu

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

This looks like fixed, but the averaging operator "+" is binary:

[mvngu@sage ~]$ sage
----------------------------------------------------------------------
| Sage Version 4.4.1, Release Date: 2010-05-02                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: r = sage.plot.colors.red
sage: g = sage.plot.colors.green
sage: b = sage.plot.colors.blue
sage: r; g; b
RGB color (1.0, 0.0, 0.0)
RGB color (0.0, 0.50196078431372548, 0.0)
RGB color (0.0, 0.0, 1.0)
sage: r + g; r + b
RGB color (0.5, 0.25098039215686274, 0.0)
RGB color (0.5, 0.0, 0.5)
sage: (r + g) + b; r + g + b
RGB color (0.25, 0.12549019607843137, 0.5)
RGB color (0.25, 0.12549019607843137, 0.5)
sage: (r + b) + g; r + b + g
RGB color (0.25, 0.25098039215686274, 0.25)
RGB color (0.25, 0.25098039215686274, 0.25)
sage: (g + b) + r; g + b + r
RGB color (0.5, 0.12549019607843137, 0.25)
RGB color (0.5, 0.12549019607843137, 0.25)

For more than two operands, I thought that "+" would average over the number of operands. Instead, "+" averages the first two, then average the result with the last operand.

comment:4 follow-up: ↓ 5 Changed 3 years ago by jason

That's because the blending is not associative. We are just providing a simple way to blend colors together. That's a limitation of the method---is there a reason why we should insist on the addition being associative?

Mixing colors and color theory in general is a very involved topic; we are just scratching the surface here with suboptimal, but still useful, methods and shortcuts.

comment:5 in reply to: ↑ 4 Changed 3 years ago by mvngu

Replying to jason:

That's because the blending is not associative. We are just providing a simple way to blend colors together. That's a limitation of the method---is there a reason why we should insist on the addition being associative?

No reason I can think of. My surprise as expressed above has more to do with my lack of understanding.

Note: See TracTickets for help on using tickets.