GithubHelp home page GithubHelp logo

folcon / colors Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jolby/colors

0.0 3.0 0.0 181 KB

Color and colorspace calculation, manipulation and conversion in Clojure.

Home Page: http://github.com/jolby/colors

Clojure 100.00%

colors's Introduction

About

Colors provides color manipulation routines to Clojure.

Further references:

Install

Colors is now up on clojars, so you can add it as a dependency to your lein project like normal:

:dependencies [[com.evocomputing/colors "1.0.0-SNAPSHOT"]
               ...other deps ]]

Example Usage

Create Color Objects

The first point of entry is to create a color object. This package takes a wide range of representations to be passed to the create-color multimethod

(use 'com.evocomputing.colors)

;;Symbolic: Either a string or keyword or symbol that matches an entry
;;in the symbolic color pallete. Currently, this is defaults to the
;;html4 colors map and x11 colors map, but the end user of this library
;;can set any named palette they want.

(create-color "blue")
(create-color :blue)

;;Hexstring: A hex string representation of an RGB(A) color

(create-color "0xFFCCAA")
(create-color "#FFCCAA")
(create-color "Ox80FFFF00") ;; alpha = 128

;; Integer: An integer representation of an RGB(A) color
(create-color 0xFFCCAA) ;; integer in hexidecimal format
(create-color 16764074) ;; same integer in decimal format

;;Sequence or array of RGB(A) integers
(create-color [255 0 0])
(create-color [255 0 0 128]) ;;alpha = 128

;;Map of either RGB (A) kw/values or HSL(A) kw/values
;;Allowable RGB keys: :r :red :g :green :b :blue
;;Allowable HSL keys: :h :hue :s :saturation :l :lightness

(create-color {:r 255 :g 0 :blue 0})
(create-color {:r 255 :g 0 :blue 0 :a 128})
(create-color {:h 120.0 :s 100.0 :l 50.0})
(create-color {:h 120.0 :s 100.0 :l 50.0 :a 128})

Convert colors

You can easily convert color objects into java.awt.Color objects, or a packed 32 bit integer representation, or its component R, G, B, A or H, S, L, A parts.

(use 'com.evocomputing.colors)

(def red-color (create-color :red))
;;Convert to java.awt.Color
(awt-color red-color)

;;get the rgba integer representation
(rgba-int red-color)

;;get the hexstring representation
(rgb-hexstr red-color)

;;get a vector of the constituent rgba components
(:rgba red-color)

;;likewise for the HSL constituent components
(:hsl red-color)

Manipulate colors

You can easily manipulate and adjust colors with simple operations

(use 'com.evocomputing.colors)

(def blue-color (create-color :blue))
;; => "#<color: blue R: 0, G: 0, B: 255, H: 240.00, S: 100.00, L:#50.00, A: 255>"

;;Create new color 1/3 way around color wheel
;;to get new primary red color
(adjust-hue blue-color 120)
;; => "#<color: red R: 255, G: 0, B: 0, H: 0.00, S: 100.00, L: 50.00, A: 255>"

;;lighten by 20%
(lighten blue-color 20)
;; => "#<color: 0xff6666ff R: 102, G: 102, B: 255, H: 240.00, S: 100.00, L: 70.00, A: 255>"

;;darken by 20%
(darken blue-color 20)
;; => "#<color: 0xff000099 R: 0, G: 0, B: 153, H: 240.00, S: 100.00,#L: 30.00, A: 255>"

Color Palettes

You can use the com.evocomputing.colors.palettes package to easily create semantic color palettes. The functions in com.evocomputing.colors.palettes.core follow the functions in the R colorspaces package. http://cran.r-project.org/web/packages/colorspace/index.html

(use 'com.evocomputing.colors)
(use 'com.evocomputing.colors.palettes.core)
(use 'com.evocomputing.colors.palettes.color-brewer)

;;Create a rainbow qualitative palette of 10 colors
;;each with different hues given a single value of each
;;saturation and lightness
(rainbow-hsl 10)

;;Create a diverging palette of 10 colors, composed of a set of colors
;;diverging from a neutral center (grey or white, without color) to two
;;different extreme colors (blue and red by default).
(diverge-hsl 10)

;;Create heat palette in HSL space. By default, it goes from a red to
;;a yellow hue, while simultaneously going to lighter colors (i.e.,
;;increasing lightness) and reducing the amount of color (i.e.,
;;decreasing saturation).
(heat-hsl 10)

;;Create an 8 item ColorBrewer sequential palette "YlOrRd" (Yellow,
;;Orange, Red)
(get-color-brewer-palette "YlOrRd" 8)

Documentation

API Documentation for colors is located at: Colors API

colors's People

Contributors

austinjones avatar jolby avatar

Watchers

 avatar  avatar  avatar

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.