@automuxer/webgl-color-utils
v0.1.1
Published
WebGL friendly colors
Downloads
64
Readme
@automuxer/webgl-color-utils
Utility functions for converting colors to WebGL friendly formats, forked from @automuxer/webgl-color-utils, sans react dependencies.
Install via npm:
npm install @automuxer/webgl-color-utilsImporting:
import {
useHex,
convertHex,
useRgb,
convertRgb,
} from '@automuxer/webgl-color-utils'convertHex(hex, noAlpha?) => Array
Convert hex colors to WebGL friendly format.
Arguments:
hex: String hex color.
noAlpha (optional): Boolean indicating if you want the alpha value in the array.
Returns:
array: An array of numbers between 0 and 1. A four element array by default and three elements if the noAlpha parameter is used.
Example Usage:
import {
convertHex
} from '@automuxer/webgl-color-utils'
const [r, g, b, a] = useHex('#fff')
// [1, 1, 1, 1]
const clearColor = useHex('#0006')
// [0, 0, 0, 0.4]
convertHex('#4183c4')
// [0.2549019607843137, 0.5137254901960784, 0.7686274509803922, 1]
convertHex('#4183c4', true) // Drop the alpha by passing true as a second param
// [0.2549019607843137, 0.5137254901960784, 0.7686274509803922]
gl.clearColor(...convertHex('#323334'))convertRgb(rgb, noAlpha?) => Array
Convert rgb colors to WebGL friendly format.
Arguments:
rgb: String rgb color e.g. 'rgb(40, 42, 54)' or 'rgba(40, 42, 54, 75%)'.
noAlpha (optional): Boolean indicating if you want the alpha value in the array.
Returns:
array: An array of numbers between 0 and 1. A four element array by default and three elements if the noAlpha parameter is used.
Example Usage:
import {
convertRgb,
} from '@automuxer/webgl-color-utils'
const [r, g, b, a] = useRgb('rgb(255, 255, 255)');
// [1, 1, 1, 1]
const clearColor = convertRgb('rgb(255, 0, 255)', true)
// [1, 0, 1]License
@automuxer/webgl-color-utils Copyright (C) 2026 Software Freedom Conservancy
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
