| 188 | /////////////////////////////////////////// |
| 189 | |
| 190 | color128 gradient_get(gradient_t gradient, float at) { |
| 191 | if (gradient->count == 0) |
| 192 | return { 1,0,0,1 }; |
| 193 | if (at < gradient->keys[0].position) |
| 194 | return gradient->keys[0].color; |
| 195 | if (at >= gradient->keys[gradient->count - 1].position) |
| 196 | return gradient->keys[gradient->count - 1].color; |
| 197 | |
| 198 | for (int32_t i = 1; i < gradient->count; i++) { |
| 199 | if (gradient->keys[i].position >= at) { |
| 200 | float pct = (at - gradient->keys[i-1].position) / (gradient->keys[i].position - gradient->keys[i-1].position); |
| 201 | return color_lerp(gradient->keys[i-1].color, gradient->keys[i].color, pct); |
| 202 | } |
| 203 | } |
| 204 | return { 1,0,0,1 }; |
| 205 | } |
| 206 | |
| 207 | /////////////////////////////////////////// |
| 208 |
no test coverage detected