| 21 | } |
| 22 | |
| 23 | function hexToVec4(hex: string): [number, number, number, number] { |
| 24 | const hexStr = hex.replace("#", ""); |
| 25 | let r = 0, |
| 26 | g = 0, |
| 27 | b = 0, |
| 28 | a = 1; |
| 29 | if (hexStr.length === 6) { |
| 30 | r = parseInt(hexStr.slice(0, 2), 16) / 255; |
| 31 | g = parseInt(hexStr.slice(2, 4), 16) / 255; |
| 32 | b = parseInt(hexStr.slice(4, 6), 16) / 255; |
| 33 | } else if (hexStr.length === 8) { |
| 34 | r = parseInt(hexStr.slice(0, 2), 16) / 255; |
| 35 | g = parseInt(hexStr.slice(2, 4), 16) / 255; |
| 36 | b = parseInt(hexStr.slice(4, 6), 16) / 255; |
| 37 | a = parseInt(hexStr.slice(6, 8), 16) / 255; |
| 38 | } |
| 39 | return [r, g, b, a]; |
| 40 | } |
| 41 | |
| 42 | const vertexShader = ` |
| 43 | attribute vec2 uv; |