It is currently December 7th, 2022, 10:20 pm

Easing functions Simulator with ActionTimer plugin / 2022-12-01 updated

Tips and Tricks from the Rainmeter Community
nek
Posts: 77
Joined: November 3rd, 2019, 12:00 am

Easing functions Simulator with ActionTimer plugin / 2022-12-01 updated

Post by nek »

Easing functions Simulator with ActionTimer plugin for skin creators
Image
Steps and Wait represent ActionTimer plugin ActionListN option
ActionListN=Repeat ActionName, Wait(Wait time number in milliseconds), Steps(Repeat count number)


💡 All easing function name are in the Rainmeter\Skins\Easing Simulator\Skin.ini


📦 EasingSimulator.rmskin (GitHub.com, 60 KB)
SHA256 b22cca42a437f1f92bf76eb6ba54f70c085c5d06450e979b03ad82bf3620644a

This skin is for creators to find out the best easing function and values of Steps and Wait.

Example code: (skin included)
Image

Code: Select all


[Variables]

;; Scaling
$=1.00

SLIDE_X_MIN=0
SLIDE_X_MAX=240

;; These variables are used in the ActionTimer plugin. | https://docs.rainmeter.net/manual/plugins/actiontimer/#ActionList
;; Repeat (Action name), (Wait time number in milliseconds), (Repeat count number)
;; EASING_STEPS=(Repeat count number), EASING_STEPS_WAIT=(Wait time number in milliseconds)
EASING_STEPS=15
EASING_STEPS_WAIT=20

ACT_UPDATE_OBJECT=[!SetOption Object "X" "[#*OBJECT_OPTION_VALUE_NEW*]"][!UpdateMeter Object][!Redraw]

COLOR_OBJECT=FFFFFF
;;
;; # Temporary Variables
;;
;; EASING_COUNTER, OBJECT_OPTION_VALUE_START, OBJECT_OPTION_VALUE_END, OBJECT_OPTION_VALUE_NEW, OBJECT_WIDTH
;;

[Rainmeter]
Update=-1
;DefaultUpdateDivider=-1
AccurateText=1
MouseActionCursor=0
OnRefreshAction=[!Delay 800][!CommandMeasure pSlide "Execute 1"]

[sScript]
Measure=Script
ScriptFile=#@#Scripts\easings.lua
Disabled=1

;;  function outQuint(x, s, e)
;;    @param   {number} x - counter/steps | range 0.0-1.0 | counter value start with 1, end with value equal to steps
;;    @param   {number} s - meter option start value
;;    @param   {number} e - meter option end value
;;    @returns {number}   - meter option new value
;;
[pSlide]
Measure=Plugin
Plugin=ActionTimer

ActionList1=StartUp1 | Wait 1 | Repeat Easing1,#EASING_STEPS_WAIT#,[#EASING_STEPS] | Wait 1200 | StartUp2 | Wait 1 | Repeat Easing2,#EASING_STEPS_WAIT#,[#EASING_STEPS] | Wait 1 | FinishUp

StartUp1=[!SetVariable OBJECT_OPTION_VALUE_START (#SLIDE_X_MAX#*#$#)][!SetVariable OBJECT_OPTION_VALUE_END (#SLIDE_X_MIN#*#$#)][!SetVariable EASING_COUNTER 0]
Easing1=[!SetVariable EASING_COUNTER ([#EASING_COUNTER]+1)][!SetVariable OBJECT_OPTION_VALUE_NEW ([&sScript:outQuint(([#EASING_COUNTER]*1/[#EASING_STEPS]),[#OBJECT_OPTION_VALUE_START],[#OBJECT_OPTION_VALUE_END])])]#ACT_UPDATE_OBJECT#

StartUp2=[!SetVariable OBJECT_OPTION_VALUE_START (#SLIDE_X_MIN#*#$#)][!SetVariable OBJECT_OPTION_VALUE_END (-[#OBJECT_WIDTH])][!SetVariable EASING_COUNTER 0]
Easing2=[!SetVariable EASING_COUNTER ([#EASING_COUNTER]+1)][!SetVariable OBJECT_OPTION_VALUE_NEW ([&sScript:inBack(([#EASING_COUNTER]*1/[#EASING_STEPS]),[#OBJECT_OPTION_VALUE_START],[#OBJECT_OPTION_VALUE_END])])]#ACT_UPDATE_OBJECT#

FinishUp=[!SetVariable OBJECT_OPTION_VALUE_NEW [#OBJECT_OPTION_VALUE_END]]#ACT_UPDATE_OBJECT#


[Container]
Meter=Image
W=(240*#$#)
Group=gBackground
SolidColor=FFFFFF

[Background]
Meter=Image
W=(240*#$#)
Container=Container
Group=gBackground
SolidColor=1F2937
LeftMouseUpAction=[!CommandMeasure pSlide "Stop 1"][!Delay 16][!CommandMeasure pSlide "Execute 1"]

[Object]
Meter=String
X=0R
Text=Click to start sliding
AntiAlias=1
Container=Container
FontColor=#COLOR_OBJECT#
FontFace=Segoe UI
FontSize=(18*#$#)
FontWeight=600
Padding=(8*#$#),0,(8*#$#),0

[Ninja]
Meter=String
Hidden=1
OnUpdateAction=[!SetOptionGroup gBackground H "[Object:H]"][!UpdateMeterGroup gBackground][!SetVariable OBJECT_WIDTH "[Object:W]"]



💡 [#EASING_COUNTER] is a nested variable. 📗 Nesting Variables

Code: Select all

[Variables]
COUNTER=0

[Meter]
...
LeftMouseUpAction=[!SetVariable COUNTER "([#COUNTER]+1)"][!Log "standard=#COUNTER#, nested=[#COUNTER]"]
Output standard=0, nested=1



@Resources\Scripts\easings.lua

Code: Select all


-- 2022-12-01 | UTF-16 LE BOM | Lua 5.1  | https://github.com/nek7u

-- ## Common

local pi, pow, sqrt, sin, cos = math.pi, math.pow, math.sqrt, math.sin, math.cos
local function trunc(x) return (math.modf(x)) end

--[=====[

  Easing math functions by https://easings.net

--]=====]

local c1, c2, c3, c4, c5 = 1.70158, 2.5949095, 2.70158, (2 * pi) / 3, (2 * pi) / 4.5
local n1, d1 = 7.5625, 2.75

local function OutBounce(x)
	if x < 1 / d1 then
		return n1 * x * x
	elseif x < 2 / d1 then
		return n1 * (x - 1.5 / d1) * (x - 1.5 / d1) + 0.75
	elseif x < 2.5 / d1 then
		return n1 * (x - 2.25 / d1) * (x - 2.25 / d1) + 0.9375;
	else
		return n1 * (x - 2.625 / d1) * (x - 2.625 / d1) + 0.984375;
	end
end

-- ## slow In

local function easeInSine(x)
	return 1 - cos((x * pi) / 2)
end

local function easeInQuad(x)
	return x * x
end

local function easeInCubic(x)
	return x * x * x
end

local function easeInQuart(x)
	return x * x * x * x
end

local function easeInQuint(x)
	return x * x * x * x * x
end

local function easeInExpo(x)
	return 0==x and 0 or pow(2, 10 * x - 10)
end

local function easeInCirc(x)
	return 1 - sqrt(1 - pow(x, 2))
end

local function easeInBack(x)
	return c3 * x * x * x - c1 * x * x
end

local function easeInElastic(x)
	if 0==x then
		return 0
	elseif 1==x then
		return 1
	else
		return -pow(2, 10 * x - 10) * sin((x * 10 - 10.75) * c4)
	end
end

local function easeInBounce(x)
	return 1 - OutBounce(1 - x)
end

-- ## slow Out

local function easeOutSine(x)
	return sin((x * pi) / 2)
end

local function easeOutQuad(x)
	return 1 - ( 1 - x) * (1 - x)
end

local function easeOutCubic(x)
	return 1 - pow(1 - x, 3)
end

local function easeOutQuart(x)
	return 1 - pow(1 - x, 4)
end

local function easeOutQuint(x)
	return 1 - pow(1 - x, 5)
end

local function easeOutExpo(x)
	return 1==x and 1 or 1 - pow(2, -10 * x)
end

local function easeOutCirc(x)
	return sqrt(1 - pow(x - 1, 2))
end

local function easeOutBack(x)
	return 1 + c3 * pow(x - 1, 3) + c1 * pow(x - 1, 2)
end

local function easeOutElastic(x)
	if 0==x then
		return 0
	elseif 1==x then
		return 1
	else
		return pow(2, -10 * x) * sin((x * 10 - 0.75) * c4) + 1
	end
end

local function easeOutBounce(x)
	return OutBounce(x)
end

-- ## slow InOut

local function easeInOutSine(x)
	return -(cos(pi * x) - 1) / 2
end

local function easeInOutQuad(x)
	return x < 0.5 and 2 * x * x or 1 - pow(-2 * x + 2, 2) / 2
end

local function easeInOutCubic(x)
	return x < 0.5 and 4 * x * x * x or 1 - pow(-2 * x + 2, 3) / 2
end

local function easeInOutQuart(x)
	return x < 0.5 and 8 * x * x * x * x or 1 - pow(-2 * x + 2, 4) /2
end

local function easeInOutQuint(x)
	return x < 0.5 and 16 * x * x * x * x * x or 1 - pow(-2 * x + 2, 5) / 2
end

local function easeInOutExpo(x)
	if 0==x then
		return 0
	elseif 1==x then
		return 1
	else
		return x < 0.5 and pow(2, 20 * x - 10) / 2 or (2 - pow(2, -20 * x + 10)) / 2
	end
end

local function easeInOutCirc(x)
	return x < 0.5 and (1 - sqrt(1 - pow(2 * x, 2))) / 2 or (sqrt(1 - pow(-2 * x + 2, 2)) + 1) / 2
end

local function easeInOutBack(x)
	return x < 0.5 and (pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2 or (pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2
end

local function easeInOutElastic(x)
	if 0==x then
		return 0
	elseif 1==x then
		return 1
	elseif x < 0.5 then
		return -(pow(2, 20 * x - 10) * sin((20 * x - 11.125) * c5)) / 2
	else
		return (pow(2, -20 * x + 10) * sin((20 * x - 11.125) * c5)) / 2 + 1
	end
end

local function easeInOutBounce(x)
	return x < 0.5 and (1 - OutBounce(1 - 2 * x)) / 2 or (1 + OutBounce(2 * x - 1)) / 2
end


--[=====[

  Easing functions for Rainmeter skin

  @param   {number} x - counter/steps | range 0.0-1.0 | counter value start with 1, end with value equal to steps
  @param   {number} s - meter option start value
  @param   {number} e - meter option end value
  @returns {number}   - meter option new value

--]=====]

function Linear(x, s, e)
	return trunc(x * (e-s) + s)
end

-- ## slow in

function inSine(x, s, e)
	return trunc(easeInSine(x) * (e-s) + s)
end

function inQuad(x, s, e)
	return trunc(easeInQuad(x) * (e-s) + s)
end

function inCubic(x, s, e)
	return trunc(easeInCubic(x) * (e-s) + s)
end

function inQuart(x, s, e)
	return trunc(easeInQuart(x) * (e-s) + s)
end

function inQuint(x, s, e)
	return trunc(easeInQuint(x) * (e-s) + s)
end

function inExpo(x, s, e)
	return trunc(easeInExpo(x) * (e-s) + s)
end

function inCirc(x, s, e)
	return trunc(easeInCirc(x) * (e-s) + s)
end

function inBack(x, s, e)
	return trunc(easeInBack(x) * (e-s) + s)
end

function inElastic(x, s, e)
	return trunc(easeInElastic(x) * (e-s) + s)
end

function inBounce(x, s, e)
	return trunc(easeInElastic(x) * (e-s) + s)
end

-- ## slow out

function outSine(x, s, e)
	return trunc(easeOutSine(x) * (e-s) + s)
end

function outQuad(x, s, e)
	return trunc(easeOutQuad(x) * (e-s) + s)
end

function outCubic(x, s, e)
	return trunc(easeOutCubic(x) * (e-s) + s)
end

function outQuart(x, s, e)
	return trunc(easeOutQuart(x) * (e-s) + s)
end

function outQuint(x, s, e)
	return trunc(easeOutQuint(x) * (e-s) + s)
end

function outExpo(x, s, e)
	return trunc(easeOutExpo(x) * (e-s) + s)
end

function outCirc(x, s, e)
	return trunc(easeOutCirc(x) * (e-s) + s)
end

function outBack(x, s, e)
	return trunc(easeOutBack(x) * (e-s) + s)
end

function outElastic(x, s, e)
	return trunc(easeOutElastic(x) * (e-s) + s)
end

function outBounce(x, s, e)
	return trunc(easeOutBounce(x) * (e-s) + s)
end

-- ## slow inout

function inoutSine(x, s, e)
	return trunc(easeInOutSine(x) * (e-s) + s)
end

function inoutQuad(x, s, e)
	return trunc(easeInOutQuad(x) * (e-s) + s)
end

function inoutCubic(x, s, e)
	return trunc(easeInOutCubic(x) * (e-s) + s)
end

function inoutQuart(x, s, e)
	return trunc(easeInOutQuart(x) * (e-s) + s)
end

function inoutQuint(x, s, e)
	return trunc(easeInOutQuint(x) * (e-s) + s)
end

function inoutExpo(x, s, e)
	return trunc(easeInOutExpo(x) * (e-s) + s)
end

function inoutCirc(x, s, e)
	return trunc(easeInOutCirc(x) * (e-s) + s)
end

function inoutBack(x, s, e)
	return trunc(easeInOutBack(x) * (e-s) + s)
end

function inoutElastic(x, s, e)
	return trunc(easeInOutElastic(x) * (e-s) + s)
end

function inoutBounce(x, s, e)
	return trunc(easeInOutBounce(x) * (e-s) + s)
end

Note: There are some gaps to consider. `(#SLIDE_X_MAX#*#$#)` might be `96.25`, 30 steps: `1/30`=`0.03333`

📗 ActionTimer, Inline Lua
> The skin is based on DanielPodo's code
> Understanding the Basics(recommended!) by DanielPodo << Thank you!
> Easing math functions are from https://easings.net