Jump to content

Make color of polygon/rectangle a bit darker or brighter


Recommended Posts

I was wondering are there any useful functions in Pixi.js which I can use in my Phaser 2.6 application to darken /brighten fill color of rectangles polygons etc...? For example make rgb(200, 150, 186) 10% darker.

I might code a function like that in JS but should I?

A tool that does the job but it works in NodeJS: https://www.npmjs.com/package/color

Link to comment
Share on other sites

I created this color snippet. Some useful things I found over the web.

        componentToHex = function (c) {
            var hex = c.toString(16);

            return ((hex.length === 1) ? "0" + hex : hex);

        rgbToHex = function (r, g, b) {
            return "#" + this.componentToHex(r) + this.componentToHex(g) + this.componentToHex(b);

        getRGBValue = function (hashString) {
            var result = "";
            if (hashString.indexOf('#') === -1) {
                result = hashString;
            } else {
                result = hashString.replace('#', '');
            return result;

        getDarkerHexColor = function (rgbValue, prcnt) {
            var rgbColor = this.getRGBValue(rgbValue),
                redChannel = this.toHex(rgbColor.substring(0, 2)),
                greenChannel = this.toHex(rgbColor.substring(2, 4)),
                blueChannel = this.toHex(rgbColor.substring(4, 6)),
                hashValue = this.rgbToHex(this.percentToSample(prcnt, redChannel), this.percentToSample(prcnt, greenChannel), this.percentToSample(prcnt, blueChannel));

            return this.getHexColor(hashValue);

        getHexColor = function (hashString) {
            return parseInt(this.getRGBValue(hashString), 16);

        toHex = function (str) {
            return parseInt(str, 16);


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...