Giter Site home page Giter Site logo

colour's Introduction

Colour

Tiny class to represent a colour entity and perform basic transformations.

Build Status

Usage

The class is meant to represent the abstract 'colour' entity. So that it is a good fit to return this object from some accessor like getColour() etc. With this in mind, the object, when cast to a string, will yield a hex string value:

(string) new Colour(255, 255, 255, Colour::RGB); // '#FFFFFF'

It is possible to construct the object either directly from the constructor, specifying RGB or HSV values:

use Dream\Colour;
$colour = new Colour(255, 255, 255, Colour::RGB);
$colour = new Colour(129, 0.5, 1.0, Colour::HSV);

Note the the HSV values for S and V are represented by a fraction from 0 ... 1.0.

A more sensible way to instantiate the object is to factory from the hex value:

use Dream\Colour;
$colour = Colour::factoryHex('#aA1144');

The following accessors are available: R, G, B and H, S, V as show below:

$colour = Colour::factoryHex('#0000FF');
$colour->R = 123;
$colour->G = 255;
echo $colour->R; // 123
echo $colour->G; // 255
echo $colour->B; // 255 (not modified from origianl hex value)

Note that you can get and set RGV and HSV values even in a mixed fashion. So that you may set R to some value, adjust S and then read the B value. Conversions between the RGB and HSV colour systems are handled internally. Any values that exceed the bounds (e.g 256 for R will be set as the highest possible value 255).

As an additonal benefit, it is also possible to calcualte the brightness score for a colour. This can especially aid situations where WCAG 2.0 is relevant.

colour's People

Contributors

arokettu avatar lauri-elevant avatar safaksam avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  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.