Skip to content

Add gradient feature. - #164

Open
aurium wants to merge 3 commits into
Qix-:masterfrom
aurium:master
Open

Add gradient feature.#164
aurium wants to merge 3 commits into
Qix-:masterfrom
aurium:master

Conversation

@aurium

@aurium aurium commented Oct 21, 2019

Copy link
Copy Markdown

Methods for two color models: gradientRGB and gradientHSL.
The gradientHSL supports clokwise and counterclokwise hue rotations.

Methods for two color models: gradientRGB and gradientHSL.
The gradientHSL supports clokwise and counterclokwise hue rotations.
@Qix-

Qix- commented Oct 21, 2019

Copy link
Copy Markdown
Owner

What's the point of this? Why not use .mix()? seems like this is gold plating.

@aurium

aurium commented Oct 21, 2019

Copy link
Copy Markdown
Author

To do a gradient, mix is more computationally costly.

@aurium

aurium commented Oct 21, 2019

Copy link
Copy Markdown
Author

The Travis errors are not related to my patch... Node 0.12 still a valid target?

@Qix- Qix- left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that some of the above below (github keeps changing) comments apply to both functions.


I did a benchmark and the gradient function is indeed faster for steps >= 4.

const Color = require('./color');
const benchmark = require('benchmark');

const srcColor = new Color('#FF0000');
const destColor = new Color('#00FF00');

new benchmark.Suite()
	.add('mix3', function () {
		const gradient = [
			srcColor,
			srcColor.mix(destColor, 0.5),
			destColor
		];
	})
	.add('grad3', function () {
		const gradient = srcColor.gradientRGB(destColor, 3);
	})
	.on('cycle', function(event) {
		console.log(String(event.target));
	})
	.on('complete', function() {
		console.log('Fastest is ' + this.filter('fastest').map('name'));
	})
	.run({ 'async': true });


new benchmark.Suite()
	.add('mix4', function () {
		const gradient = [
			srcColor,
			srcColor.mix(destColor, 0.33),
			srcColor.mix(destColor, 0.66),
			destColor
		];
	})
	.add('grad4', function () {
		const gradient = srcColor.gradientRGB(destColor, 4);
	})
	.on('cycle', function(event) {
		console.log(String(event.target));
	})
	.on('complete', function() {
		console.log('Fastest is ' + this.filter('fastest').map('name'));
	})
	.run({ 'async': true });


new benchmark.Suite()
	.add('mix5', function () {
		const gradient = [
			srcColor,
			srcColor.mix(destColor, 0.25),
			srcColor.mix(destColor, 0.5),
			srcColor.mix(destColor, 0.75),
			destColor
		];
	})
	.add('grad5', function () {
		const gradient = srcColor.gradientRGB(destColor, 5);
	})
	.on('cycle', function(event) {
		console.log(String(event.target));
	})
	.on('complete', function() {
		console.log('Fastest is ' + this.filter('fastest').map('name'));
	})
	.run({ 'async': true });

Comment thread index.js Outdated
Comment thread index.js
Comment thread index.js
@Qix-

Qix- commented Oct 25, 2019

Copy link
Copy Markdown
Owner

The Travis errors are not related to my patch... Node 0.12 still a valid target?

No, don't worry about CI. I'll let you know if there are any actionable items. This package needs to be refreshed sometime soon anyway - 0.12 will be removed, but not before this PR is merged unfortunately.

* Do not require ECMA6.
* Do not round channel values.
* Do not compute small and obivious gradients.
@aurium

aurium commented Nov 29, 2019

Copy link
Copy Markdown
Author

Hi @Qix-, is this ok? Do you need any help with this repo?

@Qix-

Qix- commented Nov 30, 2019

Copy link
Copy Markdown
Owner

See https://github.com/Qix-/color/pull/158#issuecomment-558352861 on why changes take forever for me to merge.

@aurium

aurium commented Dec 2, 2019

Copy link
Copy Markdown
Author

There is a channel where you share your thoughts about this? A page at @Qix-/color/wiki maybe?
Do you use Telegram? You can find me with this same @name there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants