Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (31 sloc) 1.07 KB
/* ------------------------------------ *\
TOOLS - Linear Interpolation
\* ------------------------------------ */
////
/// @group Tools: Utilities
/// @author Mike Mai
////
/// Calculate the definition of a line between two points
/// @param {map} $map - A SASS map of viewport widths and size value pairs
/// @return {Number} A linear equation as a calc() function
/// @see bolt-list-sort
/// @link https://gist.github.com/Jakobud/7414f91142e0f540f221a3e3cafdf856
/// @example
/// font-size: bolt-linear-interpolation((320px: 18px, 768px: 26px));
@function bolt-linear-interpolation($map) {
$keys: map-keys($map);
@if (length($keys) != 2) {
@error 'linear-interpolation() $map must be exactly 2 values';
}
// The slope
$m: (map-get($map, nth($keys, 2)) - map-get($map, nth($keys, 1))) / ( nth($keys, 2) - nth($keys, 1));
// The y-intercept
$b: map-get($map, nth($keys, 1)) - $m * nth($keys, 1);
// Determine if the sign should be positive or negative
$sign: '+';
@if ($b < 0) {
$sign: '-';
$b: abs($b);
}
@return calc(#{$m * 100}vw #{$sign} #{$b});
}
You can’t perform that action at this time.