|
Last change
on this file since a762898 was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | import {rgb as colorRgb} from "d3-color";
|
|---|
| 2 | import basis from "./basis.js";
|
|---|
| 3 | import basisClosed from "./basisClosed.js";
|
|---|
| 4 | import nogamma, {gamma} from "./color.js";
|
|---|
| 5 |
|
|---|
| 6 | export default (function rgbGamma(y) {
|
|---|
| 7 | var color = gamma(y);
|
|---|
| 8 |
|
|---|
| 9 | function rgb(start, end) {
|
|---|
| 10 | var r = color((start = colorRgb(start)).r, (end = colorRgb(end)).r),
|
|---|
| 11 | g = color(start.g, end.g),
|
|---|
| 12 | b = color(start.b, end.b),
|
|---|
| 13 | opacity = nogamma(start.opacity, end.opacity);
|
|---|
| 14 | return function(t) {
|
|---|
| 15 | start.r = r(t);
|
|---|
| 16 | start.g = g(t);
|
|---|
| 17 | start.b = b(t);
|
|---|
| 18 | start.opacity = opacity(t);
|
|---|
| 19 | return start + "";
|
|---|
| 20 | };
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | rgb.gamma = rgbGamma;
|
|---|
| 24 |
|
|---|
| 25 | return rgb;
|
|---|
| 26 | })(1);
|
|---|
| 27 |
|
|---|
| 28 | function rgbSpline(spline) {
|
|---|
| 29 | return function(colors) {
|
|---|
| 30 | var n = colors.length,
|
|---|
| 31 | r = new Array(n),
|
|---|
| 32 | g = new Array(n),
|
|---|
| 33 | b = new Array(n),
|
|---|
| 34 | i, color;
|
|---|
| 35 | for (i = 0; i < n; ++i) {
|
|---|
| 36 | color = colorRgb(colors[i]);
|
|---|
| 37 | r[i] = color.r || 0;
|
|---|
| 38 | g[i] = color.g || 0;
|
|---|
| 39 | b[i] = color.b || 0;
|
|---|
| 40 | }
|
|---|
| 41 | r = spline(r);
|
|---|
| 42 | g = spline(g);
|
|---|
| 43 | b = spline(b);
|
|---|
| 44 | color.opacity = 1;
|
|---|
| 45 | return function(t) {
|
|---|
| 46 | color.r = r(t);
|
|---|
| 47 | color.g = g(t);
|
|---|
| 48 | color.b = b(t);
|
|---|
| 49 | return color + "";
|
|---|
| 50 | };
|
|---|
| 51 | };
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | export var rgbBasis = rgbSpline(basis);
|
|---|
| 55 | export var rgbBasisClosed = rgbSpline(basisClosed);
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.