xss-dimmer: simplify easing function names

This commit is contained in:
Vincent Bernat 2021-09-29 15:30:26 +02:00
parent 6be90d5830
commit b48064be34

View file

@ -109,13 +109,13 @@ def on_draw(widget, event, options, background, start):
# See: https://easings.net/ # See: https://easings.net/
easing_functions = { easing_functions = {
"none": lambda x: x, "none": lambda x: x,
"ease-out-circ": lambda x: math.sqrt(1 - pow(x - 1, 2)), "out-circ": lambda x: math.sqrt(1 - pow(x - 1, 2)),
"ease-out-sine": lambda x: math.sin(x * math.pi / 2), "out-sine": lambda x: math.sin(x * math.pi / 2),
"ease-out-cubic": lambda x: 1 - pow(1 - x, 3), "out-cubic": lambda x: 1 - pow(1 - x, 3),
"ease-out-quint": lambda x: 1 - pow(1 - x, 5), "out-quint": lambda x: 1 - pow(1 - x, 5),
"ease-out-expo": lambda x: 1 - pow(2, -10 * x), "out-expo": lambda x: 1 - pow(2, -10 * x),
"ease-out-quad": lambda x: 1 - (1 - x) * (1 - x), "out-quad": lambda x: 1 - (1 - x) * (1 - x),
"ease-out-bounce": ( "out-bounce": (
lambda n1, d1: lambda x: n1 * x * x lambda n1, d1: lambda x: n1 * x * x
if x < 1 / d1 if x < 1 / d1
else n1 * pow(x - 1.5 / d1, 2) + 0.75 else n1 * pow(x - 1.5 / d1, 2) + 0.75
@ -124,20 +124,20 @@ easing_functions = {
if (x < 2.5 / d1) if (x < 2.5 / d1)
else n1 * pow(x - 2.625 / d1, 2) + 0.984375 else n1 * pow(x - 2.625 / d1, 2) + 0.984375
)(7.5625, 2.75), )(7.5625, 2.75),
"ease-out-elastic": ( "out-elastic": (
lambda x: pow(2, -10 * x) * math.sin((x * 10 - 0.75) * (2 * math.pi) / 3) + 1 lambda x: pow(2, -10 * x) * math.sin((x * 10 - 0.75) * (2 * math.pi) / 3) + 1
), ),
"ease-inout-quad": lambda x: 2 * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 2) / 2, "inout-quad": lambda x: 2 * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 2) / 2,
"ease-inout-quart": ( "inout-quart": (
lambda x: 8 * x * x * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 4) / 2 lambda x: 8 * x * x * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 4) / 2
), ),
"ease-inout-expo": ( "inout-expo": (
lambda x: pow(2, 20 * x - 10) / 2 if x < 0.5 else (2 - pow(2, -20 * x + 10)) / 2 lambda x: pow(2, 20 * x - 10) / 2 if x < 0.5 else (2 - pow(2, -20 * x + 10)) / 2
), ),
"ease-inout-bounce": ( "inout-bounce": (
lambda x: (1 - easing_functions["ease-out-bounce"](1 - 2 * x)) / 2 lambda x: (1 - easing_functions["out-bounce"](1 - 2 * x)) / 2
if x < 0.5 if x < 0.5
else (1 + easing_functions["ease-out-bounce"](2 * x - 1)) / 2 else (1 + easing_functions["out-bounce"](2 * x - 1)) / 2
), ),
} }
@ -154,7 +154,7 @@ if __name__ == "__main__":
add("--background", help="use a background instead of black") add("--background", help="use a background instead of black")
add( add(
"--easing-function", "--easing-function",
default="ease-out-bounce", default="out-bounce",
choices=easing_functions.keys(), choices=easing_functions.keys(),
help="easing function for opacity", help="easing function for opacity",
) )