GithubHelp home page GithubHelp logo

color's Introduction

Color

home

github.com/halostatue/color

code

github.com/halostatue/color

bugs

github.com/halostatue/color/issues

rdoc

rubydoc.info/github/halostatue/color

continuous integration

<img src=“https://travis-ci.org/halostatue/color.png” />

test coverage

<img src=“https://coveralls.io/repos/halostatue/color/badge.png” alt=“Coverage Status” />

Description

Color is a Ruby library to provide basic RGB, CMYK, HSL, and other colourspace manipulation support to applications that require it. It also provides 152 named RGB colours (184 with spelling variations) that are commonly supported in HTML, SVG, and X11 applications. A technique for generating monochromatic contrasting palettes is also included.

The Color library performs purely mathematical manipulation of the colours based on colour theory without reference to colour profiles (such as sRGB or Adobe RGB). For most purposes, when working with RGB and HSL colour spaces, this won’t matter. Absolute colour spaces (like CIE L*a*b* and XYZ) and cannot be reliably converted to relative colour spaces (like RGB) without colour profiles.

Color 1.8 adds an alpha parameter to all #css_rgba calls, fixes a bug exposed by new constant lookup semantics in Ruby 2, and ensures that Color.equivalent? can only be called on Color instances.

Barring bugs introduced in this release, this (really) is the last version of color that supports Ruby 1.8, so make sure that your gem specification is set properly (to ~> 1.8) if that matters for your application. This version will no longer be supported one year after the release of color 2.0.

History

Color is the result of a project merge between color.rb 0.1.0 by Matt Lyon and color-tools 1.3 by Austin Ziegler. Please see History.txt for details on the changes this merge brings.

Color::Palette::MonoContrast was developed based on techniques described by Andy “Malarkey” Clarke, implemented in JavaScript by Steve G. Chipman at SlayerOffice and by Patrick Fitzgerald of BarelyFitz in PHP.

1

www.stuffandnonsense.co.uk/archives/creating_colour_palettes.html

2

slayeroffice.com/tools/color_palette/

3

www.barelyfitz.com/projects/csscolor/

:include: Code-of-Conduct.rdoc

:include: Contributing.rdoc

:include: Licence.rdoc

color's People

Contributors

armahillo avatar bguest avatar halostatue avatar matthewd avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

color's Issues

Using Contrast Methods

Firstly, thanks for this Gem, it has helped a lot with a current project!

I may not have a full grasp of how Gems are packaged or something, so I have a few questions.

Is there a reason that the methods in lib/color/rgb/contrast.rb aren't available in the current Gem? Is it because it is in a subdirectory to where the class Color::RGB is defined? Or that the file doesn't have the include Color line?

When I try to use the method like follows, I get an undefined method error for contrast.

irb(main):006:0> Color::RGB.by_css('ffffff').contrast(Color::RGB.by_css('000000'))
NoMethodError: undefined method `contrast' for RGB [#ffffff]:Color::RGB
    from (irb):6
    from /home/jacob/.rvm/rubies/ruby-2.1.0/bin/irb:11:in `<main>'

I forked the repo and just copied the methods from contrast.rb into rgb.rb, added my git repo to my Gemfile in a rails project and the methods seem to work excellently. See this commit in my fork. I use the contrast method and it works great.

Just wondering if maybe I'm missing something on how it is supposed to be used, or if it isn't ready for production due to a lack of tests or something. For now, I'll use my fork, and again, thank you to everybody who has helped with this Gem!

lab module

i'd like to put the lab stuff into its own namespace and separate .rb file. The to_lab and other related methods would also be added to rgb, hsl and other color type libraries.

Additionally, I have completed a working implementation of the e2000 contrast algorithm and would like to release that for use, wherever it might be useful, into this project.

This would largely consist of putting the existing LAB-related code that currently lives in rgb.rb into its own file and module, LAB.

Fixed alpha channel may make the gem useless for some purposes

At this moment all the colors have fixed alpha channel. This makes the gem useless for some purposes (i.e. CSS). What is a reason to have css_rgba if it anyway substitutes 1 for alpha?

I started to add alpha channels to RGB and other classes, but there is one problem, so I want to ask first.
Is it OK if initialize functions will change its parameters? For example, for RGB:

  def initialize(r = 0, g = 0, b = 0, a = nil, radix = 255.0, &block) # :yields self:

Code depending on radix parameter will have to be updated then. Considering that color-2 is in development, I think that it's OK.

Another approach is to create separate classes RGBA and so on. Since alpha channel can be applied to each color model, it is questionable way.

What do you think or plan?

Averaging a list of colors

I noticed there is a mix_with method for rgb, hsl, etc, but I was wondering how I would go about averaging a list of hsl or rgb colors to find the average color?

Thanks!

difference between color X and Y is reported as not equal to difference between colors Y and X

I would expect

require 'color'

lab_a = Color::RGB::DarkSalmon.to_lab
lab_b = Color::RGB::Blue.to_lab
rgb = Color::RGB::Blue
puts rgb.delta_e94(lab_a, lab_b)
puts rgb.delta_e94(lab_b, lab_a)

to print the same value twice (as distance between colour is the same in both cases as colours are the same). Bur result is

85.6075926403573
54.11289673323268

I found one suspicious fragment of code -

s_C = 1 + k_1 * c_1
s_H = 1 + k_2 * c_1

in https://github.com/halostatue/color/blob/master/lib/color/rgb.rb#L432 that seems to break symmetry between the first and the second color.

But changing second c_1 to c_2 is not fixing lack of symmetry (though in general difference is reduced) - result is

62.44677425056029
79.73246450623749

test/minitest_helper.rb missing from the gem

Hi!

I noticed that the file test/minitest_helper.rb was missing from the gem (version 1.5.1). As a consequence, the tests cannot be run from the gem. It is in particular not possible at the moment to run the tests when building the package for the Debian distribution.

Could you please include it in the next release?

Thanks a lot in advance!

Cédric

Fix the homepage

SInce rubyforge was shut down, it would be nice to update the information about homepage.

Add color profiles or types for the CMYK conversion

The current RGB to CMYK conversion is using an undercolor removal to obtain a good ink representation. I need a different profile to match the values of this tool: https://kuler.adobe.com/create/color-wheel/ (the current values are far from this tool)

The following formula gives good results (not 100% accurate since no profile is specified, but an API or something is need to really match a profile): http://www.codeproject.com/Articles/4488/XCmyk-CMYK-to-RGB-Calculator-with-source-code

I can send a pull request if you tell me how do you want your code to handle this issue.

Here's a short snippet to represent the formula:

def to_cmyk
  c = 1.0 - @r.to_f
  m = 1.0 - @g.to_f
  y = 1.0 - @b.to_f

  k = [c, m, y].min
  reverse_k = 1.0 - k

  if reverse_k
    c = (c - 1.0) / reverse_k
    m = (m - 1.0) / reverse_k
    k = (k - 1.0) / reverse_k
  else
    c = m = y = 0.0
  end

  Color::CMYK.from_fraction(c, m, y, k)
end

What about Ruby 2.1.0 support?

Trying example from documentation

Color::RGB.new(0x20, 0x40, 0x80)
(pry) output error: #<NoMethodError: undefined method `to_rgb' for #<Object:0x0000010186d588>>

I also noticed that builds on travis failing for Ruby 2.0.

Is there are any plans or anything i can help with on this one?

Add Spectrum's functionality

Came across this project today: https://github.com/twoism-dev/Spectrum. It's a rather small set of functions for extracting color references from strings.

Seems like that could be a good addition to color gem, and can do it better since it can return actual Color objects.

So maybe something like:

Color.extract_names('I love the color red, blue is awful') => { "red"=>RGB [#ff0000], "blue"=>RGB [#ff00ff] }
Color.extract_css('I love the color #f00, #00f is awful') => { "#f00"=>RGB [#ff0000], "#00f"=>RGB [#ff00ff] }

Also, it would be cool to get the CSS name given the html string.

r = Color::CSS::Red
r.css_name  #=> "red"

Taking it one step further, maybe even return the closest matching name, if there is no exact match.

r = Color::RGB.from_html("#ff1111")
r.css_name  #=> "red"

Remove startup overhead?

The colors gem is slow to require because it generates a lot of constants and structures at boot time. For instance:

named [0xf0, 0xf8, 0xff], :AliceBlue

Would it be possible to lazy load these named constants and hashes only upon first access?

add Color::RGB.from_rgba

This is my monkey patch :P

Color::RGB.class_eval do 

  def self.from_rgba(rgba)
    r,g,b = *rgba.scan(/\d+/).map(&:to_f)
    self.new(r,g,b, rgba.match(/%/) ? 100 : 255)
  end

end

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.