Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make swatch background/text reactive to their partner. #12

Closed
lewisgoddard opened this issue May 16, 2018 · 1 comment
Closed

Make swatch background/text reactive to their partner. #12

lewisgoddard opened this issue May 16, 2018 · 1 comment

Comments

@lewisgoddard
Copy link
Member

lewisgoddard commented May 16, 2018

I assume this will require some JavaScript magic to identify when something has too little contrast.

@lewisgoddard
Copy link
Member Author

lewisgoddard commented May 16, 2018

I'm not sure I can guarantee that this returns >= 0 and <= 255, but otherwise it works.

<?php
////	Get Brightness
// Returns a brightness value from 0 to 255
// for a given 6-digit hexadecimal color string
function get_brightness(string $hex): number {
	// strip off any leading #
	$hex = str_replace('#', '', $hex);
	$c_r = hexdec(substr($hex, 0, 2));
	$c_g = hexdec(substr($hex, 2, 2));
	$c_b = hexdec(substr($hex, 4, 2));
	return ( ($c_r * 299) + ($c_g * 587) + ($c_b * 114) ) / 1000;
}

Constructing an equivalent in JavaScript shouldn't be too difficult.

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

No branches or pull requests

1 participant