It is currently November 30th, 2022, 12:09 am

Easing functions Simulator with ActionTimer plugin / 2022-11-28 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-11-28 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, 50 KB)
SHA256 3796be6f0b1ca591e1e61b2e4b37a2b4a155109e6a315400631ecf2c408a11bc

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
;;
SRC_CONFIG=#CURRENTCONFIG#
SRC_FILE=#CURRENTFILE#
SYMBOL_SUBMENU=[\x0009][\x23F5]
ACT1=[!DeactivateConfigGroup "#ROOTCONFIG#\@Contexts"][!WriteKeyValue Rainmeter @Include "[#*INC*]" "#ROOTCONFIGPATH#@Contexts\Menu.ini"][!WriteKeyValue Variables SRC_CONFIG "#SRC_CONFIG#" "#ROOTCONFIGPATH#@Contexts\Menu.ini"][!WriteKeyValue Variables SRC_FILE "#SRC_FILE#" "#ROOTCONFIGPATH#@Contexts\Menu.ini"][!ActivateConfig "#ROOTCONFIG#\@Contexts" "Menu.ini"]

[Rainmeter]
Update=-1
;DefaultUpdateDivider=-1
AccurateText=1
MouseActionCursor=0
DefaultKeepOnScreen=0
DefaultSnapEdges=0
DefaultWindowX=(#WORKAREAWIDTH#/8)
DefaultWindowY=(#WORKAREAHEIGHT#/8)
OnRefreshAction=[!Delay 800][!CommandMeasure pSlide "Execute 1"]

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

;;
;; @example  easeOutQuint(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 | Repeat Easing1,#EASING_STEPS_WAIT#,[#EASING_STEPS] | Wait 1200 | StartUp2 | 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:easeOutQuint(([#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:easeInBack(([#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=171717
LeftMouseUpAction=[!CommandMeasure pSlide "Stop 1"][!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-11-28 | UTF-16 LE BOM | Lua 5.1  | https://github.com/nek7u

-- Easing math functions are from https://easings.net

-- ## Common

local modf, pi, pow, sqrt, sin, cos = math.modf, math.pi, math.pow, math.sqrt, math.sin, math.cos
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 nv(r, s, e)
	local n = modf(s + (e-s) * r)
	return n
end

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


--[=====[
  Easing functions

  @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
--]=====]


-- ## Linear

function Linear(x, s, e)
	local r = x
	return nv(r, s, e)
end


-- ## slow In

function easeInSine(x, s, e)
	local r = 1 - cos((x * pi) / 2)
	return nv(r, s, e)
end

function easeInQuad(x, s, e)
	local r = x * x
	return nv(r, s, e)
end

function easeInCubic(x, s, e)
	local r = x * x * x
	return nv(r, s, e)
end

function easeInQuart(x, s, e)
	local r = x * x * x * x
	return nv(r, s, e)
end

function easeInQuint(x, s, e)
	local r = x * x * x * x * x
	return nv(r, s, e)
end

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

function easeInCirc(x, s, e)
	local r = 1 - sqrt(1 - pow(x, 2))
	return nv(r, s, e)
end

function easeInBack(x, s, e)
	local r = c3 * x * x * x - c1 * x * x
	return nv(r, s, e)
end

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

function easeInBounce(x, s, e)
	local r = 1 - OutBounce(1 - x)
	return nv(r, s, e)
end


-- ## slow Out

function easeOutSine(x, s, e)
	local r = sin((x * pi) / 2)
	return nv(r, s, e)
end

function easeOutQuad(x, s, e)
	local r = 1 - ( 1 - x) * (1 - x)
	return nv(r, s, e)
end

function easeOutCubic(x, s, e)
	local r = 1 - pow(1 - x, 3)
	return nv(r, s, e)
end

function easeOutQuart(x, s, e)
	local r = 1 - pow(1 - x, 4)
	return nv(r, s, e)
end

function easeOutQuint(x, s, e)
	local r = 1 - pow(1 - x, 5)
	return nv(r, s, e)
end

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

function easeOutCirc(x, s, e)
	local r = sqrt(1 - pow(x - 1, 2))
	return nv(r, s, e)
end

function easeOutBack(x, s, e)
	local r = 1 + c3 * pow(x - 1, 3) + c1 * pow(x - 1, 2)
	return nv(r, s, e)
end

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

function easeOutBounce(x, s, e)
	local r = OutBounce(x)
	return nv(r, s, e)
end


-- ## slow InOut

function easeInOutSine(x, s, e)
	local r = -(cos(pi * x) - 1) / 2
	return nv(r, s, e)
end

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

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

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

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

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

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

function easeInOutBack(x, s, e)
	local r = 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
	return nv(r, s, e)
end

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

function easeInOutBounce(x, s, e)
	local r = x < 0.5 and (1 - OutBounce(1 - 2 * x)) / 2 or (1 + OutBounce(2 * x - 1)) / 2
	return nv(r, s, e)
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