[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft/
0

Configure Feed

Select the types of activity you want to include in your feed.

shapecraft / src / color / utils.ts
936 B 33 lines
1import * as THREE from 'three' 2import type { ColorInput } from '../core/types' 3 4export function parseColorToRgb(input: ColorInput): [number, number, number] { 5 if (typeof input === 'number') { 6 const c = new THREE.Color(input) 7 return [c.r, c.g, c.b] 8 } 9 if (typeof input === 'string') { 10 const c = new THREE.Color(input) 11 return [c.r, c.g, c.b] 12 } 13 return [input[0], input[1], input[2]] 14} 15 16export function lerpColor(a: ColorInput, b: ColorInput, t: number): [number, number, number] { 17 const ca = parseColorToRgb(a) 18 const cb = parseColorToRgb(b) 19 return [ 20 ca[0] + (cb[0] - ca[0]) * t, 21 ca[1] + (cb[1] - ca[1]) * t, 22 ca[2] + (cb[2] - ca[2]) * t, 23 ] 24} 25 26export function hexToRgb(hex: string): [number, number, number] { 27 const c = new THREE.Color(hex) 28 return [c.r, c.g, c.b] 29} 30 31export function rgbToHex(r: number, g: number, b: number): string { 32 return '#' + new THREE.Color(r, g, b).getHexString() 33}