forked from at-import/Sassy-math
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
177 lines (169 loc) · 4.36 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Require any additional compass plugins here.
require 'fraction'
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false
# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
# Sass Script Proving Grounds
# 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