项目作者: sydneyzh

项目描述 :
Store and convert color variables with IRIS.Color
高级语言: JavaScript
项目地址: git://github.com/sydneyzh/iris.git
创建时间: 2017-07-09T01:27:51Z
项目社区:https://github.com/sydneyzh/iris

开源协议:MIT License

下载


iris

Store and convert color variables with IRIS.Color()

Feature

Hands-free instant syncing of internal RGB, HSV, and hex string color representations.

Usage

constructors

  1. var color = new IRIS.Color();
  2. var red = new IRIS.Color( 'ff0000' );
  3. var green = new IRIS.Color( 'g', 255 );
  4. var blue = new IRIS.Color( 'hsv', 240, 100, 100 );

getters and setters

  1. var color = new IRIS.Color();
  2. color.setHSV( 233, 74, 78 );
  3. color.getRed(); // 51.714
  4. color.getHexString(); // 3445c7

Reference

Data Ranges

  • r, g, b are numbers from 0 to 255

  • h is a number from 0 to 360

  • s and v are numbers from 0 to 100

  • hexString is a string representing the colors from '000000' to 'ffffff'

*The setters do not wrap input values. If an out-of-range value is detected, an error will be reported to the console.*

IRIS.Color

Public Methods

  • set( type, x, y, z )

    type can be 'r', 'red', 'g', 'green', 'b', 'blue', 'h', 'hue', 's', 'saturation', 'v', 'value', 'hexString'

  • setRed( val )

  • setGreen( val )

  • setBlue( val )

  • setHue( val )

  • setSaturation( val )

  • setValue( val )

  • setHexString( val )

  • setRGB( r, g, b )

  • setHSV( h, s, v )

  • getRed()

  • getGreen()

  • getBlue()

  • getHue()

  • getSaturation()

  • getValue()

  • getHexString()

  • getRGB()

    returns an array [ r, g, b ]

  • getRGB( out )

    sets the out array with r, g, b

  • getHSV()

    returns an array [ h, s, v ]

  • getHSV( out )

    sets the out array with h, s, v

Bonus

Two infrastructure classes — IRIS.Element and IRIS.Node can be use to implement graph data structures. Details are explained as comments in the source code.

Demos hosted on Codepen