spinnerbox Posted July 29, 2016 Share Posted July 29, 2016 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 Quote Link to comment Share on other sites More sharing options...
spinnerbox Posted July 29, 2016 Author Share Posted July 29, 2016 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); } Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 29, 2016 Share Posted July 29, 2016 Look into PIXI.utils, it already has rgbToHex, though it does not have special functions with it spinnerbox 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.