Colors and gradients #451
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
| This seems to work: import { css, multiCosineGradient, srgb } from "@thi.ng/color";
const grad = multiCosineGradient({
  num: 10,
  stops: [
    [0.0, [0.8, 0.2, 0.4, 1]],
    [0.7, [0, 0.5, 1, 1]],
    [1.0, [0, 0.8, 1, 1]],
  ],
  tx: srgb,
});
console.log(grad);
console.log(css(grad[0])); | 
Beta Was this translation helpful? Give feedback.
-
| Hi @cristianvogel - welcome & nice to see you here! I'm sorry about this issue you're having, there're a few things going on here, but mainly it's because I somehow forgot to update these code snippets in the readme (and that seemingly for at least a few years). I've just gone through all the readme examples and fixed several of them. Also pushing a new release in a few minutes (incl. a minor bug fix I uncovered just too now...) To your actual example: 
 The fully working example looks like this (also updated in the readme now): import { css, multiCosineGradient, srgb } from "@thi.ng/color";
const gradient = multiCosineGradient({
	num: 10,
	// gradient stops (normalized positions)
	stops: [
		[0.1, [1, 0, 0, 1]],
		[0.5, [0, 1, 0, 1]],
		[0.9, [0, 0, 1, 1]],
	],
	// optional color transform/coercion
	tx: srgb
});
console.log(gradient);
// [
// 	[1, 0, 0, 1],
// 	[1, 0, 0, 1],
// 	[0.854, 0.146, 0, 1],
// 	[0.5, 0.5, 0, 1],
// 	[0.146, 0.854, 0, 1],
// 	[0, 1, 0, 1],
// 	[0, 0.854, 0.146, 1],
// 	[0, 0.5, 0.5, 1],
// 	[0, 0.146, 0.853, 1],
// 	[0, 0, 1, 1],
// 	[0, 0, 1, 1]
// ]
// convert to CSS
console.log(gradient.map((x) => css(x)));
// [
//   "#ff0000",
//   "#ff0000",
//   "#da2500",
//   "#807f00",
//   "#25da00",
//   "#00ff00",
//   "#00da25",
//   "#00807f",
//   "#0025da",
//   "#0000ff",
//   "#0000ff",
// ]Hope that helps & please let me know if anything else is unclear... 👍 | 
Beta Was this translation helpful? Give feedback.

Hi @cristianvogel - welcome & nice to see you here!
I'm sorry about this issue you're having, there're a few things going on here, but mainly it's because I somehow forgot to update these code snippets in the readme (and that seemingly for at least a few years). I've just gone through all the readme examples and fixed several of them. Also pushing a new release in a few minutes (incl. a minor bug fix I uncovered just too now...)
To your actual example:
srgbais a typo (or rather ancient naming) and should besrgbinstead (without thea). For your use case (WebGL) that transform is also not really required....map(css)part is also needing a minor update to.map((x) => css(x)). Th…