mirror of
https://github.com/kidoman/embd
synced 2025-07-04 20:37:46 +02:00
initial commit
This commit is contained in:
commit
b3bad4e383
114 changed files with 14939 additions and 0 deletions
128
bower_components/gumby/sass/extensions/modular-scale/lib/modular-scale.rb
vendored
Executable file
128
bower_components/gumby/sass/extensions/modular-scale/lib/modular-scale.rb
vendored
Executable file
|
@ -0,0 +1,128 @@
|
|||
require 'compass'
|
||||
# require 'sassy-math'
|
||||
|
||||
# This tells Compass what your Compass extension is called, and where to find
|
||||
# its files
|
||||
# Replace 'extension' with the name of your extension. Spaces allowed.
|
||||
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
||||
Compass::Frameworks.register('modular-scale', :path => extension_path)
|
||||
|
||||
# Version and date of version for your Compass extension.
|
||||
# Replace Extension with the name of your extension
|
||||
# Letters, numbers, and underscores only
|
||||
# Version is a number. If a version contains alphas, it will be created as
|
||||
# a prerelease version
|
||||
# Date is in the form of YYYY-MM-DD
|
||||
module ModularScale
|
||||
VERSION = "1.0.6"
|
||||
DATE = "2012-08-13"
|
||||
end
|
||||
|
||||
# This is where any custom SassScript should be placed. The functions will be
|
||||
# available on require of your extension without the need for users to import
|
||||
# any partials. Uncomment below.
|
||||
|
||||
# Modular Scale Sass Script
|
||||
module Sass::Script
|
||||
class Number < Literal
|
||||
# Comparison
|
||||
def <=>(other)
|
||||
value <=> other.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Sass::Script::Functions
|
||||
# Modular Scale
|
||||
def double_octave
|
||||
value = 4 / 1.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def major_twelfth
|
||||
value = 3 / 1.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def major_eleventh
|
||||
value = 8 / 3.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def major_tenth
|
||||
value = 5 / 2.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def octave
|
||||
value = 2 / 1.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def major_seventh
|
||||
value = 15 / 8.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def minor_seventh
|
||||
value = 16 /9.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def major_sixth
|
||||
value = 5 / 3.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def minor_sixth
|
||||
value = 8 / 5.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def fifth
|
||||
value = 3 / 2.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def augmented_fourth
|
||||
value = Math.sqrt(2) / 1.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def fourth
|
||||
value = 4 / 3.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def major_third
|
||||
value = 5 / 4.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def minor_third
|
||||
value = 6 / 5.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def major_second
|
||||
value = 9 / 8.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
def minor_second
|
||||
value = 16 / 15.0
|
||||
Sass::Script::Number.new(value)
|
||||
end
|
||||
|
||||
# Lists
|
||||
def sort_list(list)
|
||||
sep = list.separator if list.is_a?(Sass::Script::List)
|
||||
list = list.to_a.sort
|
||||
Sass::Script::List.new(list, sep)
|
||||
end
|
||||
def reverse_list(list)
|
||||
sep = list.separator if list.is_a?(Sass::Script::List)
|
||||
list = list.to_a.reverse
|
||||
Sass::Script::List.new(list, sep)
|
||||
end
|
||||
def trim_list(list, threshold, ascending)
|
||||
# remove list items above or below a threshold
|
||||
sep = list.separator if list.is_a?(Sass::Script::List)
|
||||
list = list.to_a
|
||||
if ascending.value
|
||||
list = list.delete_if {
|
||||
|x| x.value <= threshold.value
|
||||
}
|
||||
else
|
||||
list = list.delete_if {
|
||||
|x| x.value >= threshold.value
|
||||
}
|
||||
end
|
||||
Sass::Script::List.new(list, sep)
|
||||
end
|
||||
end
|
310
bower_components/gumby/sass/extensions/modular-scale/stylesheets/_modular-scale.scss
vendored
Executable file
310
bower_components/gumby/sass/extensions/modular-scale/stylesheets/_modular-scale.scss
vendored
Executable file
|
@ -0,0 +1,310 @@
|
|||
// SASSY MODULAR-SCALE
|
||||
// https://github.com/scottkellum/modular-scale
|
||||
|
||||
// Defaults
|
||||
$ratio: golden_ratio() !default;
|
||||
$base-size: 16px !default;
|
||||
$round-pixels: true !default;
|
||||
|
||||
// Modular Scale function
|
||||
@function modular-scale($multiple, $base-size: $base-size, $ratio: $ratio, $round-pixels: $round-pixels) {
|
||||
|
||||
// return the $base-size if $multiple is zero
|
||||
@if $multiple == 0 {
|
||||
@if type-of($base-size) == "list" {
|
||||
$base-size: sort_list($base-size);
|
||||
@return nth($base-size, 1);
|
||||
}
|
||||
|
||||
// return just the simple $base-size value if it's not a list
|
||||
@return $base-size;
|
||||
}
|
||||
|
||||
// if multiple base-sizes are passed in as a list
|
||||
// and multiple ratios are passed in as a list
|
||||
// calculate values in using each base-size / ratio combination
|
||||
@if type-of($base-size) == "list" and type-of($ratio) == "list" {
|
||||
@if unit(ms-multibase-multiratio($multiple, $base-size, $ratio)) == "px" and $round-pixels == true {
|
||||
@return round(ms-multibase-multiratio($multiple, $base-size, $ratio));
|
||||
}
|
||||
@return ms-multibase-multiratio($multiple, $base-size, $ratio);
|
||||
}
|
||||
|
||||
// if multiple base-sizes are passed in as a list
|
||||
// calculate values in using each base-size
|
||||
@if type-of($base-size) == "list" and type-of($ratio) == "number" {
|
||||
@if unit(ms-multibase($multiple, $base-size, $ratio)) == "px" and $round-pixels == true {
|
||||
@return round(ms-multibase($multiple, $base-size, $ratio));
|
||||
}
|
||||
@return ms-multibase($multiple, $base-size, $ratio);
|
||||
}
|
||||
|
||||
// if multiple ratios are passed in as a list
|
||||
// calculate values in using each ratio
|
||||
@if type-of($base-size) == "number" and type-of($ratio) == "list" {
|
||||
@if unit(ms-multiratio($multiple, $base-size, $ratio)) == "px" and $round-pixels == true {
|
||||
@return round(ms-multiratio($multiple, $base-size, $ratio));
|
||||
}
|
||||
@return ms-multiratio($multiple, $base-size, $ratio);
|
||||
}
|
||||
|
||||
// If there are no lists just run the simple function
|
||||
@if unit(power($ratio, $multiple) * $base-size) == "px" and $round-pixels == true {
|
||||
@return round(power($ratio, $multiple) * $base-size);
|
||||
}
|
||||
@return power($ratio, $multiple) * $base-size;
|
||||
}
|
||||
|
||||
// calculate values in using each base-size / ratio combination
|
||||
@function ms-multibase-multiratio($multiple, $base-size: $base-size, $ratio: $ratio) {
|
||||
|
||||
// start with an empty list to place all values in
|
||||
$scale-values: ();
|
||||
|
||||
// make sure base sizes are in ascending order
|
||||
$base-size: sort_list($base-size);
|
||||
|
||||
// take each base-size in turn
|
||||
$k: 1;
|
||||
@while $k <= length($base-size) {
|
||||
|
||||
// add each $base-size to the list except the first
|
||||
@if $k > 1 {
|
||||
$scale-values: append($scale-values, nth($base-size, $k));
|
||||
}
|
||||
|
||||
// take each ratio in turn
|
||||
$j: 1;
|
||||
@while $j <= length($ratio) {
|
||||
|
||||
// reset $modular-scale for each set
|
||||
$modular-scale: nth($base-size, $k);
|
||||
|
||||
// do the scale for each base-size using this ratio
|
||||
@if $multiple > 0 {
|
||||
|
||||
// up $multiple times
|
||||
// and add the result to $scale-values
|
||||
@for $i from 1 through $multiple {
|
||||
$modular-scale: power(nth($ratio, $j), $i) * nth($base-size, $k);
|
||||
$scale-values: append($scale-values, $modular-scale);
|
||||
}
|
||||
|
||||
// and down until the value is lower than the lowest $base-size
|
||||
// and add the result to $scale-values
|
||||
$i: -1;
|
||||
$modular-scale: nth($base-size, $k);
|
||||
@while $modular-scale >= nth($base-size, 1) {
|
||||
$modular-scale: power(nth($ratio, $j), $i) * nth($base-size, $k);
|
||||
$scale-values: append($scale-values, $modular-scale);
|
||||
$i: $i - 1;
|
||||
}
|
||||
}
|
||||
@if $multiple < 0 {
|
||||
|
||||
// do the scale down for each set to below 1px
|
||||
$i: 0;
|
||||
$modular-scale: nth($base-size, $k);
|
||||
@while $i >= $multiple {
|
||||
$modular-scale: power(nth($ratio, $j), $i) * nth($base-size, $k);
|
||||
$scale-values: append($scale-values, $modular-scale);
|
||||
$i: $i - 1;
|
||||
}
|
||||
}
|
||||
$j: $j + 1;
|
||||
}
|
||||
$k: $k + 1;
|
||||
}
|
||||
|
||||
// return trimmed and sorted final list
|
||||
@return trim-sort($multiple, $scale-values, $base-size);
|
||||
}
|
||||
|
||||
// calculate values in using each base-size
|
||||
@function ms-multibase($multiple, $base-size: $base-size, $ratio: $ratio) {
|
||||
|
||||
// start with an empty list to place all values in
|
||||
$scale-values: ();
|
||||
|
||||
// make sure base sizes are in ascending order
|
||||
$base-size: sort_list($base-size);
|
||||
|
||||
// take each base-size in turn
|
||||
$k: 1;
|
||||
@while $k <= length($base-size) {
|
||||
|
||||
// add each $base-size to the list except the first
|
||||
@if $k > 1 {
|
||||
$scale-values: append($scale-values, nth($base-size, $k));
|
||||
}
|
||||
|
||||
// reset $modular-scale for each set
|
||||
$modular-scale: nth($base-size, $k);
|
||||
|
||||
// do the scale for each base-size using this ratio
|
||||
@if $multiple > 0 {
|
||||
|
||||
// up $multiple times
|
||||
// and add the result to $scale-values
|
||||
@for $i from 1 through $multiple {
|
||||
$modular-scale: power($ratio, $i) * nth($base-size, $k);
|
||||
$scale-values: append($scale-values, $modular-scale);
|
||||
}
|
||||
|
||||
// and down until the value is lower than the lowest $base-size
|
||||
// and add the result to $scale-values
|
||||
$i: -1;
|
||||
$modular-scale: nth($base-size, $k);
|
||||
@while $modular-scale >= nth($base-size, 1) {
|
||||
$modular-scale: power($ratio, $i) * nth($base-size, $k);
|
||||
$scale-values: append($scale-values, $modular-scale);
|
||||
$i: $i - 1;
|
||||
}
|
||||
}
|
||||
@if $multiple < 0 {
|
||||
|
||||
// do the scale down for each set to below 1px
|
||||
$i: 0;
|
||||
$modular-scale: nth($base-size, $k);
|
||||
@while $i >= $multiple {
|
||||
$modular-scale: power($ratio, $i) * nth($base-size, $k);
|
||||
$scale-values: append($scale-values, $modular-scale);
|
||||
$i: $i - 1;
|
||||
}
|
||||
}
|
||||
$k: $k + 1;
|
||||
}
|
||||
|
||||
// return trimmed and sorted final list
|
||||
@return trim-sort($multiple, $scale-values, $base-size);
|
||||
}
|
||||
|
||||
// calculate values in using each ratio
|
||||
@function ms-multiratio($multiple, $base-size: $base-size, $ratio: $ratio) {
|
||||
|
||||
// start with an empty list to place all values in
|
||||
$scale-values: ();
|
||||
|
||||
// If $multiple is a positive integer (up the scale)
|
||||
@if $multiple > 0 {
|
||||
|
||||
// take each ratio in turn
|
||||
$j: 1;
|
||||
@while $j <= length($ratio) {
|
||||
|
||||
// reset $modular-scale for each set
|
||||
$modular-scale: $base-size;
|
||||
|
||||
// do the scale using this ratio thru the multiple, and add the result to $scale-values
|
||||
@for $i from 1 through $multiple {
|
||||
$modular-scale: power(nth($ratio, $j), $i) * $base-size;
|
||||
$scale-values: append($scale-values, $modular-scale);
|
||||
}
|
||||
$j: $j + 1;
|
||||
}
|
||||
|
||||
// sort acsending
|
||||
$scale-values: sort_list($scale-values);
|
||||
|
||||
// return the final value using the laced list
|
||||
@return nth($scale-values, $multiple);
|
||||
}
|
||||
|
||||
// If $multiple is a negative integer (down the scale)
|
||||
@if $multiple < 0 {
|
||||
|
||||
// take each ratio in turn
|
||||
$j: 1;
|
||||
@while $j <= length($ratio) {
|
||||
|
||||
// reset $modular-scale for each set
|
||||
$modular-scale: $base-size;
|
||||
|
||||
// do the scale using this ratio thru the multiple, and add the result to $scale-values
|
||||
@for $i from 1 through $multiple * -1 {
|
||||
$modular-scale: power(nth($ratio, $j), -$i) * $base-size;
|
||||
$scale-values: append($scale-values, $modular-scale);
|
||||
}
|
||||
$j: $j + 1;
|
||||
}
|
||||
|
||||
// sort decending
|
||||
$scale-values: reverse_list(sort_list($scale-values));
|
||||
|
||||
// return the final value using the laced list
|
||||
@return nth($scale-values, $multiple * -1);
|
||||
}
|
||||
}
|
||||
|
||||
// trim and sort the final list
|
||||
@function trim-sort($multiple, $scale-values: $scale-values, $base-size: $base-size) {
|
||||
@if $multiple > 0 {
|
||||
|
||||
// trim list so we can count from the lowest $base-size
|
||||
$scale-values: trim_list($scale-values, nth($base-size, 1), true);
|
||||
|
||||
// sort acsending
|
||||
$scale-values: sort_list($scale-values);
|
||||
|
||||
// return the final value using the laced list
|
||||
@return nth($scale-values, $multiple);
|
||||
}
|
||||
@else {
|
||||
|
||||
// trim list so we can count from the lowest $base-size
|
||||
$scale-values: trim_list($scale-values, nth($base-size, 1), false);
|
||||
|
||||
// sort acsending
|
||||
$scale-values: reverse_list(sort_list($scale-values));
|
||||
|
||||
// return the final value using the laced list
|
||||
@return nth($scale-values, -$multiple);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// alias for golden_ratio()
|
||||
@function golden() {
|
||||
@return golden_ratio();
|
||||
}
|
||||
|
||||
// Shortcut
|
||||
@function ms($multiple, $base-size: $base-size, $ratio: $ratio, $round-pixels: $round-pixels) {
|
||||
// Return the value from the Modular Scale function
|
||||
@return modular-scale($multiple, $base-size, $ratio, $round-pixels);
|
||||
}
|
||||
|
||||
// Write Modular Scale List
|
||||
@function modular-scale-list($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio, $round-pixels: $round-pixels) {
|
||||
$ms-list: unquote("MS-LIST:");
|
||||
@for $i from $start through $finish {
|
||||
$ms-list: append($ms-list, ms($i, $base-size, $ratio, $round-pixels));
|
||||
}
|
||||
@return $ms-list;
|
||||
}
|
||||
|
||||
@function ms-list($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio, $round-pixels: $round-pixels) {
|
||||
@return modular-scale-list($start, $finish, $base-size, $ratio, $round-pixels);
|
||||
}
|
||||
|
||||
@mixin modular-scale-list($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio, $round-pixels: $round-pixels) {
|
||||
@debug modular-scale-list($start, $finish, $base-size, $ratio, $round-pixels);
|
||||
}
|
||||
|
||||
@mixin ms-list($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio, $round-pixels: $round-pixels) {
|
||||
@debug modular-scale-list($start, $finish, $base-size, $ratio, $round-pixels);
|
||||
}
|
||||
|
||||
@mixin modular-scale-list-output($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio, $round-pixels: $round-pixels) {
|
||||
MODULAR-SCALE-LIST {
|
||||
ms-list: modular-scale-list($start, $finish, $base-size, $ratio, $round-pixels);
|
||||
}
|
||||
}
|
||||
|
||||
@mixin ms-list-output($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio, $round-pixels: $round-pixels) {
|
||||
@include modular-scale-list-output($start, $finish, $base-size, $ratio, $round-pixels);
|
||||
}
|
||||
|
||||
// Other libraries can easily query if this function is avalible
|
||||
$modular-scale-loaded: true;
|
159
bower_components/gumby/sass/extensions/sassy-math/lib/sassy-math.rb
vendored
Executable file
159
bower_components/gumby/sass/extensions/sassy-math/lib/sassy-math.rb
vendored
Executable file
|
@ -0,0 +1,159 @@
|
|||
require 'compass'
|
||||
Compass::Frameworks.register("sassy-math", :path => "#{File.dirname(__FILE__)}/..")
|
||||
|
||||
# Sassy math Functions
|
||||
module Sass::Script::Functions
|
||||
# Exponents
|
||||
def exponent(base, powerNum, powerDen)
|
||||
base = base.value.to_f
|
||||
powerNum = powerNum.value.to_f
|
||||
powerDen = powerDen.value.to_f
|
||||
result = base ** (powerNum / powerDen)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def power(base, exponent)
|
||||
base = base.value.to_f
|
||||
exponent = exponent.value.to_f
|
||||
result = base ** exponent
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def sqrt(number)
|
||||
number = number.value.to_f
|
||||
result = Math.sqrt(number)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def nth_root(number, root)
|
||||
number = number.value.to_f
|
||||
root = root.value.to_f
|
||||
result = number ** (1.0 / root)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
# Logarithms
|
||||
def ln(num)
|
||||
result = Math.log(num.value)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def log10(num)
|
||||
result = Math.log10(num.value)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
# Miscellaneous
|
||||
def factorial(number)
|
||||
result = 1
|
||||
number = number.value
|
||||
if number > 0
|
||||
(1..number).each do |i|
|
||||
result = result * i
|
||||
end
|
||||
end
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def random(max = Sass::Script::Number.new(100)) ## shamelessly taken from here: https://gist.github.com/1561650
|
||||
Sass::Script::Number.new(rand(max.value), max.numerator_units, max.denominator_units)
|
||||
end
|
||||
def hypot(a, b)
|
||||
a = a.value.to_f
|
||||
b = b.value.to_f
|
||||
result = Math.hypot(a, b)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
# Constants
|
||||
def pi
|
||||
pi = Math::PI
|
||||
Sass::Script::Number.new(pi)
|
||||
end
|
||||
def e
|
||||
e = Math::E
|
||||
Sass::Script::Number.new(e)
|
||||
end
|
||||
def golden_ratio()
|
||||
result = (1.0 / 2.0) + (Math.sqrt(5) / 2.0)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
# Comparative Functions
|
||||
def is_int(number)
|
||||
number = number.value.to_f
|
||||
if number - number.floor != 0
|
||||
result = false
|
||||
else
|
||||
result = true
|
||||
end
|
||||
Sass::Script::Bool.new(result)
|
||||
end
|
||||
def is_float(number)
|
||||
number = number.value
|
||||
if number - number.floor != 0
|
||||
result = true
|
||||
else
|
||||
result = false
|
||||
end
|
||||
Sass::Script::Bool.new(result)
|
||||
end
|
||||
# Trigonometric Functions
|
||||
def deg_to_rad(degree)
|
||||
result = degree.value.to_f * Math::PI / 180
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def rad_to_deg(rad)
|
||||
result = rad.value.to_f * 180 / Math::PI
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def cosh(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.cosh(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def acos(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.acos(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def acosh(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.acosh(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def sinh(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.sinh(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def asin(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.asin(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def asinh(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.asinh(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def tanh(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.tanh(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def atan(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.atan(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def atan2(y, x)
|
||||
y = y.value.to_f
|
||||
x = x.value.to_f
|
||||
result = Math.atan2(y, x)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
def atanh(rad)
|
||||
rad = rad.value.to_f
|
||||
result = Math.atanh(rad)
|
||||
Sass::Script::Number.new(result)
|
||||
end
|
||||
end
|
||||
|
||||
module SassyMath
|
||||
|
||||
VERSION = "1.5"
|
||||
DATE = "2012-07-29"
|
||||
|
||||
end
|
310
bower_components/gumby/sass/extensions/sassy-math/stylesheets/_math.scss
vendored
Executable file
310
bower_components/gumby/sass/extensions/sassy-math/stylesheets/_math.scss
vendored
Executable file
|
@ -0,0 +1,310 @@
|
|||
// SASSY MATH
|
||||
|
||||
@charset "UTF-8";
|
||||
|
||||
//////////////////////////////
|
||||
// Variables
|
||||
//////////////////////////////
|
||||
$pi: 3.1415926535897932384626433832795028841971693993751;
|
||||
$π: $pi;
|
||||
$e: 2.71828182845904523536028747135266249775724709369995;
|
||||
|
||||
$iter: 50;
|
||||
|
||||
//////////////////////////////
|
||||
// Random Number
|
||||
// Working from http://xkcd.com/221/
|
||||
// Chosen by fair dice roll.
|
||||
// Guarenteed to be random.
|
||||
//////////////////////////////
|
||||
@function rand() {
|
||||
@return 4;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Percent
|
||||
//////////////////////////////
|
||||
@function percent($number) {
|
||||
@return $number * 0.01;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Exponent
|
||||
//////////////////////////////
|
||||
@function exponent($base, $exponent) {
|
||||
// reset value
|
||||
$value: $base;
|
||||
// positive intergers get multiplied
|
||||
@if $exponent > 1 {
|
||||
@for $i from 2 through $exponent {
|
||||
$value: $value * $base; } }
|
||||
// negitive intergers get divided. A number divided by itself is 1
|
||||
@if $exponent < 1 {
|
||||
@for $i from 0 through -$exponent {
|
||||
$value: $value / $base; } }
|
||||
// return the last value written
|
||||
@return $value;
|
||||
}
|
||||
|
||||
@function pow($base, $exponent) {
|
||||
@return exponent($base, $exponent);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Factorial
|
||||
//////////////////////////////
|
||||
@function factorial($number) {
|
||||
// reset value
|
||||
$value: 1;
|
||||
// positive intergers get multiplied
|
||||
@if $number > 0 {
|
||||
@for $i from 1 through $number {
|
||||
$value: $value * $i;
|
||||
}
|
||||
}
|
||||
@return $value;
|
||||
}
|
||||
|
||||
@function fact($number) {
|
||||
@return factorial($number);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// Polynomial Approximation
|
||||
//////////////////////////////
|
||||
// Maclaurin series can be used to estimate Sine and Consine
|
||||
@function maclaurin($start, $key, $number) {
|
||||
$value: $start;
|
||||
$add: 0;
|
||||
|
||||
@for $i from 1 through $iter {
|
||||
@if $add == 0 {
|
||||
$value: $value - ( exponent($number, $key) / factorial($key) );
|
||||
$add: 1;
|
||||
}
|
||||
@else {
|
||||
$value: $value + ( exponent($number, $key) / factorial($key) );
|
||||
$add: 0;
|
||||
}
|
||||
|
||||
$key: $key + 2;
|
||||
}
|
||||
|
||||
@return $value;
|
||||
}
|
||||
// Taylor series can be used to estiamte ln
|
||||
@function taylor($number) {
|
||||
@return taylor;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Basic Trig Functions
|
||||
//////////////////////////////
|
||||
// Bundled in Compass: http://compass-style.org/reference/compass/helpers/trig/
|
||||
// References for implementing using MacLaurin series below:
|
||||
|
||||
//@function sin($number, $unit: 'deg') {
|
||||
// @if $unit == 'deg' {
|
||||
// $number: deg-to-rad($number);
|
||||
// }
|
||||
// @return maclaurin($number, 3, $number);
|
||||
//}
|
||||
//
|
||||
//@function cos($number, $unit: 'deg') {
|
||||
// @if $unit == 'deg' {
|
||||
// $number: deg-to-rad($number);
|
||||
// }
|
||||
// @return maclaurin(1, 2, $number);
|
||||
//}
|
||||
//
|
||||
//// Trig Identity: Tangent = Sine divided by Cosine.
|
||||
//@function tan($number, $unit: 'deg') {
|
||||
// @if $unit == 'deg' {
|
||||
// $number: deg-to-rad($number);
|
||||
// }
|
||||
// @return sin($number) / cos($number);
|
||||
//}
|
||||
|
||||
//////////////////////////////
|
||||
// Reciprocal Trig Functions
|
||||
//////////////////////////////
|
||||
@function csc($number, $unit: 'deg') {
|
||||
@if $unit == 'deg' {
|
||||
$number: deg-to-rad($number);
|
||||
}
|
||||
@return 1 / sin($number);
|
||||
}
|
||||
|
||||
@function scs($number, $unit: 'deg') {
|
||||
@if $unit == 'deg' {
|
||||
$number: deg-to-rad($number);
|
||||
}
|
||||
@return 1 / cos($number);
|
||||
}
|
||||
|
||||
@function cot($number, $unit: 'deg') {
|
||||
@if $unit == 'deg' {
|
||||
$number: deg-to-rad($number);
|
||||
}
|
||||
@return 1 / tan($number);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Hyperbolic Functions
|
||||
//////////////////////////////
|
||||
@function sinh($number) {
|
||||
$top: exponent($e, (2 * $number)) - 1;
|
||||
$bottom: 2 * exponent($e, $number);
|
||||
@return $top / $bottom;
|
||||
}
|
||||
|
||||
@function cosh($number) {
|
||||
$top: exponent($e, (2 * $number)) + 1;
|
||||
$bottom: 2 * exponent($e, $number);
|
||||
@return $top / $bottom;
|
||||
}
|
||||
|
||||
@function tanh($number) {
|
||||
$top: exponent($e, (2 * $number)) - 1;
|
||||
$bottom: exponent($e, (2 * $number)) + 1;
|
||||
@return $top / $bottom;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Reciprocal Hyperbolic Functions
|
||||
//////////////////////////////
|
||||
@function csch($number) {
|
||||
@return 1 / sinh($number);
|
||||
}
|
||||
|
||||
@function sech($number) {
|
||||
@return 1 / cosh($number);
|
||||
}
|
||||
|
||||
@function coth($number) {
|
||||
@return 1/ tanh($number);
|
||||
}
|
||||
|
||||
|
||||
@function log($number) {
|
||||
@return $number;
|
||||
}
|
||||
|
||||
@function ln($number) {
|
||||
@if $number > 0 and $number < 1 {
|
||||
$value: 0;
|
||||
@for $i from 1 through $iter {
|
||||
$value: $value + ( pow(-1, $i) * pow(-1 * (1 - $number), $i)) / $i;
|
||||
}
|
||||
$value: -1 * $value;
|
||||
|
||||
@return $value;
|
||||
}
|
||||
@else if $number == 1 {
|
||||
@return 0;
|
||||
}
|
||||
@else {
|
||||
@return ERROR;
|
||||
@warn ln input must be greater than zero and less than or equal to 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// Degree/Radian Conversion
|
||||
//////////////////////////////
|
||||
@function deg-to-rad($number) {
|
||||
@return $number * $pi / 180deg;
|
||||
}
|
||||
|
||||
@function rad-to-deg($number) {
|
||||
@return $number * 180deg / $pi;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Root Functions
|
||||
//////////////////////////////
|
||||
// Basic General-Purpose Root Function
|
||||
@function n-root($number, $n) {
|
||||
@if $number < 1 {
|
||||
@return ERROR;
|
||||
@warn ROOT ERROR;
|
||||
}
|
||||
// If a whole number, generate it quickly
|
||||
@for $i from 1 through $number {
|
||||
@if exponent($i, $n) == $number {
|
||||
@return $i;
|
||||
}
|
||||
}
|
||||
// Else, run through other options
|
||||
@for $i from 1 through $number * 1000 / 2 {
|
||||
@if round(exponent($i / 1000, $n) * 100) == round($number * 100) {
|
||||
@return $i / 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@function root($number, $n) {
|
||||
@return n-root($number, $n);
|
||||
}
|
||||
|
||||
// Square Roots
|
||||
@function √($number) {
|
||||
@return sqrt($number);
|
||||
}
|
||||
|
||||
@function sqrt($number) {
|
||||
$guess: rand();
|
||||
$root: $guess;
|
||||
@for $i from 1 through $iter {
|
||||
$root: $root - (pow($root, 2) - $number) / (2 * $root);
|
||||
}
|
||||
@return $root;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Golden Ratio
|
||||
//////////////////////////////
|
||||
@function golden() {
|
||||
@return 1/2 + sqrt(5) / 2;
|
||||
}
|
||||
@function ϕ() {
|
||||
@return golden();
|
||||
}
|
||||
|
||||
$golden-ratio: golden();
|
||||
$ϕ: $golden-ratio;
|
||||
|
||||
//////////////////////////////
|
||||
// Is Int and Is Float
|
||||
//////////////////////////////
|
||||
@function is-int($number) {
|
||||
@if type-of($number) != 'number' {
|
||||
@warn '#{$number} is not a number! It cannot be an integer if it is not a number!';
|
||||
@return false;
|
||||
}
|
||||
@if $number - floor($number) != 0 {
|
||||
@return false;
|
||||
}
|
||||
@else {
|
||||
@return true;
|
||||
}
|
||||
}
|
||||
|
||||
@function is-float($number) {
|
||||
@if type-of($number) != 'number' {
|
||||
@warn '#{$number} is not a number! It cannot be an decimal if it is not a number!';
|
||||
@return false;
|
||||
}
|
||||
@if $number - floor($number) != 0 {
|
||||
@return true;
|
||||
}
|
||||
@else {
|
||||
@return false;
|
||||
}
|
||||
}
|
||||
|
||||
@function is-decimal($number) {
|
||||
@return is-float($number);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue