Git Product home page Git Product logo

colorutils's People

Contributors

ajmansfield avatar edaniszewski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

colorutils's Issues

Color blending for light addition gives unexpected RGB values

Hi,

provided the code below, I get a rgb tuple with some values higher than 255.
Is this expected?

The version of colorutils I am using is 0.2.1.

Thanks,
Jose Manuel

Snippet

import colorutils
from colorutils import Color
from colorutils import ArithmeticModel

define colors to blend

c1 = Color(rgb=[255, 153, 153]) # red
c2 = Color(rgb=[102, 153, 255]) # blue

simple addition

c3 = c1 + c2

c1 + c2

c4 = Color(rgb=c1.rgb, arithmetic=ArithmeticModel.BLEND) + c2

c2 + c1

c5 = Color(rgb=c2.rgb, arithmetic=ArithmeticModel.BLEND) + c1

display results

for i, c in enumerate([c1, c2, c3, c4, c5):
display(f"c{str(i+1)}: {c.rgb} : {c.hex}")

results: c4 and c5 have unexpectedly high values

c1: [255, 153, 153] : #ff9999'
c2: [102, 153, 255] : #6699ff'
c3: (255, 255, 255) : #ffffff'
c4: (306, 229, 280) : #132e5118'
c5: (229, 229, 331) : #e5e514b'

define color palattes

Have predefined color palattes available to users. e.g. perhaps something like:

> from colorutils.palattes import grayscale
> grayscale.__dict__
[Color(0,0,0), Color(10,10,10), Color(20,20,20), ......]
> from colorutils.palattes import primary
> primary.__dict__
[Color(255,0,0), Color(255,255,0), Color(0,0,255), ......]

potential palattes:
cymk
rgb
primary
secondary
roygbv
grayscale

Add color swatches for interactive notebooks?

I actually just made a fork with a very basic implementation of this for my own use, although I don't think the code I have is exactly ready for prime time or anything.

But basically, by adding a function like _repr_html_ to the Color object, interactive notebook environments like Jupyter or IPython can provide a richer display representation for these objects; in this case it would be quite useful to use this to provide a color swatch of some sort.

The code I added currently just displays a colored box with the hex code above it, like this:
blue color swatch

I'm sure someone else could figure out an even neater layout for this (perhaps put the hex code, rgb triple, hsv, etc to the right of the swatch?), though.

For reference, to get this I added this function to the definition of Color:

def _repr_html_(self):
    return '''
        <div style="
            width:80px;
            text-align:center;
        ">
            <code>{0}</code>
        </div>
        <div style="
            background-color:{0};
            width:80px;
            height:80px;
            border-style:solid;
            border-width:2px
        "></div>'''.format(self.hex)

text color algorithm

create algorithm that decides on best text color (takes two color, either default black, white, or can be some dark-light overridden color) based on some background color. e.g. if given a dark background, return the light text color. light background would yield dark text color

Not able to instantiate Color using BLEND model

192.168.0.165> ./ColorMix red blue

Traceback (most recent call last):
File "./ColorMix", line 11, in
Col1 = Color(web=sys.argv[1], arithmetic = ArithmeticModel.BLEND)
NameError: name 'ArithmeticModel' is not defined

192.168.0.165> cat ColorMix
#!/usr/bin/python3

import sys

from colorutils import Color

print ("\n")

Col1 = Color(web=sys.argv[1], arithmetic = ArithmeticModel.BLEND)
Col2 = Color(web=sys.argv[2], arithmetic = ArithmeticModel.BLEND)

Col3 = Col1 + Col2
print(Col1.web, " + ", Col2.web, " = ", Col3.web)

print ("\n")
quit()

Cannot sum list of colors

This may be an internal code syntax error, but how can I sum the list of Color objects?
Separate index summation works, but function doesn't.

>>> from colorutils import Color, ArithmeticModel
>>>
>>> # An example of LIGHT addition:
>>> # >>> Color((0, 100, 200)) + Color((100, 100, 100))
>>> # <Color (100, 200, 255)>
>>>
>>> List = [(63, 49, 39), (73, 97, 138), (56, 68, 91)]
>>> List = [Color(x) for x in List]
>>> List = sum(List)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'Color'
>>>
>>> List[0] + List[1] + List[2]
<Color (192, 214, 255)>

add support for HSV color format

supposedly HSV is a better color model than RGB.. maybe worth implementing and changing the underlying Color class model to HSV. Adding support includes adding conversions between all existing color formats

add 'color runs' feature

add a color run feature, which takes a start color, end color, and iteration number to produce a sequence of colors between the provided colors, with the sequence size being determined by the iteration number.

support of rgba

it should be great that rgb model be improved and support for the alpha channel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.