It is currently March 28th, 2024, 11:07 am

Smooth Meter Fade In/Out

Discuss the use of Lua in Script measures.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: Smooth Meter Fade In/Out

Post by eclectic-tech »

Dany Gee wrote: July 15th, 2022, 8:27 pm You have the contents of the ini file in my original post and the lua contents in the first post.
You literally don't need anything else besides some local pics to test.
The lua code in the first post cross-fades 2 lines of text read by a second lua script from a text file.
But your code only has 1 image meter bound to the Quote plugin. It cannot cross fade a single image, you need 2 images to use the cross-fade action of the script.

One solution might be a scheme to handle a fade out the current image and fade in the next image obtained since you only have 1 image source (Quote plugin).

Or 2 image meters, one displaying the initial Quote plugin value and the second image meter a different Quote plugin value, then 2 Fade measures that can that control the fade of each image.

The 2-image variant was discussed in a later post between TweaknFreak and Kaelri.

Let us know which way to proceed; the single image fade out/fade in is simplest variation.

Single image fade out/in code in spoiler

Code: Select all

[Rainmeter]
Author=Jlynn @ WWW.neon-ink.TK
Update=16
MiddleMouseUpAction=!Refresh

;RESIZER
MouseScrollUpAction=[!SetVariable Scale "(#Scale#+#ScrollMouseIncrement#)"][!WriteKeyValue Variables Scale "(#Scale#+#ScrollMouseIncrement#)"][!Refresh] 
MouseScrollDownAction=[!SetVariable Scale "(#Scale#-#ScrollMouseIncrement# < 0.1 ? 0.1 : #Scale#-#ScrollMouseIncrement#)"][!WriteKeyValue Variables Scale "(#Scale#-#ScrollMouseIncrement# < 0.1 ? 0.1 : #Scale#-#ScrollMouseIncrement#)"][!Refresh]

[Metadata]
Name=9-48 Polaroid (Large)
Version=1.0
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

[Variables]
ImagesPath=D:\MEGA\Pictures\Franczeska_Piorko\Slideshow\Temp
@Include=#@#Variables.inc
Scale=1
ScrollMouseIncrement=0.3

;SCRIPT CALCULATED FADE
[Fade]
Measure=Script
ScriptFile=Fade.lua
;OPTIONAL SETTINGS:
Min=0
Max=255
Start=255
Step=20

;PLAY A SOUND ONCE ON SKIN LOAD
[MeasurePlayOnce]
Measure=Calc
Formula=Counter
IfEqualValue=1
IfEqualAction=[Play "#@#crystal.wav"][!DisableMeasure MeasurePlayOnce]

;TIMEDPICTURECHANGE
[Timer]
DynamicVariables=1
Measure=Calc
Formula=(Timer+1)%3600
IfCondition=(Timer=0)
IfTrueAction=[!CommandMeasure Fade Activate('out')][!Delay 1500][!UpdateMeasure ImageRandomizer][!UpdateMeter Image][!Redraw][!CommandMeasure Fade Activate('in')]

;PHOTO RANDOMIZER
[ImageRandomizer]
DynamicVariables=1
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
PathName=#ImagesPath#
FileFilter=*.jpg;*.jpeg;*.gif;*.bmp;*.png
Subfolders=0
;PHOTO CHANGE INTERVAL
UpdateDivider=-1

;BLACK BG BEHIND PHOTO
[DefaultBackground]
Meter=IMAGE
ImageName=#ROOTCONFIGPATH#@Resources\Pic-LrgBg.png
ImageRotate=5
;SolidColor=255,255,255,0
X=(12*#Scale#)
Y=(-40*#Scale#)
W=(532*#Scale#)
H=(532*#Scale#)

;ACTUAL PHOTO
[Image]
MeasureName=ImageRandomizer
Meter=IMAGE
DynamicVariables=1
ImageRotate=5
X=(72*#Scale#)
Y=(30*#Scale#)
W=(385*#Scale#)
H=(385*#Scale#)
Hidden=0
PreserveAspectRatio=0
ImageAlpha=[Fade]
;ImageTint=0,0,0,200
LeftMouseUpAction=[!CommandMeasure Fade Activate('out')][!Delay 1500][!UpdateMeasure ImageRandomizer][!UpdateMeter Image][!Redraw][!CommandMeasure Fade Activate('in')]

;POLAROID PHOTO FRAME
[PolaroidFrame]
Meter=IMAGE
ImageName=#ROOTCONFIGPATH#@Resources\FP_Photo3.png
ImageRotate=0
SolidColor=255,255,255,0
X=(0*#Scale#)
Y=(0*#Scale#)
W=(530*#Scale#)
H=(530*#Scale#)
User avatar
Dany Gee
Posts: 33
Joined: July 11th, 2012, 8:32 am

Re: Smooth Meter Fade In/Out

Post by Dany Gee »

Thanks a lot! @eclectic-tech :thumbup:
Exactly what I was expecting.
You nicely explained everything and suggested two sleek solutions.
For now I went for the single image fade out - it does the job pretty well.
I will maybe later try out the second option.
Attachments
fade_effect.gif
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Smooth Meter Fade In/Out

Post by balala »

Dany Gee wrote: July 14th, 2022, 1:40 pm The target: to have cross-fade between photos on click and after randomizer interval runs out.
I still believe there is no need for a lua script for fading in and out two images:

Code: Select all

[Rainmeter]
Update=1000

[Variables]
Alpha=0
Cycle=0
Step=25.5
Scale=1
Upd=[!UpdateMeasure "MeasureAlpha"][!UpdateMeterGroup "Images"][!Redraw]
ImagesPath=D:\MEGA\Pictures\Franczeska_Piorko\Slideshow\Temp
ChangeInterval=10

[MeasureTime]
Measure=Calc
Formula=(( MeasureTime + 1 ) % #ChangeInterval# )
IfCondition=((#CURRENTSECTION#=#ChangeInterval#/2)&&(#Cycle#=0))
IfTrueAction=[!UpdateMeasure "MeasureImage1"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Stop 2"]
IfCondition2=((#CURRENTSECTION#=#ChangeInterval#/2)&&(#Cycle#=1))
IfTrueAction2=[!UpdateMeasure "MeasureImage0"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Stop 2"]
IfCondition3=((#CURRENTSECTION#=0)&&(#Cycle#=0))
IfTrueAction3=[!SetVariable Cycle "1"][!CommandMeasure "MeasureAlpha" "Execute 1"][!CommandMeasure "MeasureAlpha" "Stop 2"]
IfCondition4=((#CURRENTSECTION#=0)&&(#Cycle#=1))
IfTrueAction4=[!SetVariable Cycle "0"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Execute 2"]
DynamicVariables=1

[MeasureAlpha]
Measure=Plugin
Plugin=ActionTimer
ActionList1=Repeat FadeIn,40,10
FadeIn=[!SetVariable Alpha "(Clamp((#Alpha#+#Step#),0,255))"]#Upd#
ActionList2=Repeat FadeOut,40,10
FadeOut=[!SetVariable Alpha "(Clamp((#Alpha#-#Step#),0,255))"]#Upd#
DynamicVariables=1

[MeasureImage0]
Measure=Plugin
Plugin=QuotePlugin
PathName=#ImagesPath#
FileFilter=*.jpg;*.jpeg;*.gif;*.bmp;*.png
Subfolders=0
UpdateDivider=-1

[MeasureImage1]
Measure=Plugin
Plugin=QuotePlugin
PathName=#ImagesPath#
FileFilter=*.jpg;*.jpeg;*.gif;*.bmp;*.png
Subfolders=0
UpdateDivider=-1

[MeterImage0]
MeasureName=MeasureImage0
Meter=IMAGE
DynamicVariables=1
;ImageRotate=5
X=(72*#Scale#)
Y=(30*#Scale#)
W=(385*#Scale#)
H=(385*#Scale#)
Hidden=0
PreserveAspectRatio=1
ImageAlpha=(255-#Alpha#)
DynamicVariables=1
Group=Images

[MeterImage1]
MeasureName=MeasureImage1
Meter=IMAGE
DynamicVariables=1
;ImageRotate=5
X=0r
Y=0r
W=(385*#Scale#)
H=(385*#Scale#)
Hidden=0
PreserveAspectRatio=1
ImageAlpha=#Alpha#
DynamicVariables=1
Group=Images
See there is no lua script file, no need for it. The ChangeInterval is the time for which an image is kept visible. If needed, the code can be altered to get the transition only on click, or whatever else. A great advantage of this code is that it uses the default Update=1000 option on the [Rainmeter] section, but has to be further improved.
If you are interested in this code and need further assistance, please let me know.
User avatar
Dany Gee
Posts: 33
Joined: July 11th, 2012, 8:32 am

Re: Smooth Meter Fade In/Out

Post by Dany Gee »

Thank you @balala!
Your config is also very neat! :thumbup:
And the end effect is pleasing enough.
Attachments
fade_effect_without_lua.gif
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Smooth Meter Fade In/Out

Post by balala »

Dany Gee wrote: July 18th, 2022, 6:39 pm Your config is also very neat! :thumbup:
Thanks!
Dany Gee wrote: July 18th, 2022, 6:39 pm And the end effect is pleasing enough.
You can alter how the effect is working (for instance its speed) by altering the Wait parameter on the ActionList1 and ActionList2 options of the [MeasureAlpha] measure. The ActionList1 looks like this in my example: ActionList1=Repeat FadeIn,40,10. The red colored 40 is the Wait parameter I'm talking about (expressed in milliseconds). It is how long the plugin waits between two consecutive executions of ActionList1. If you increase this value, you get slowing down the effect, decreasing it speeds the effect up. Play a little bit with these values, to get the effect as you want / like. And obviously same applies for ActionList2 as well. In any case I recommend you to use the same values, if you change one, change the other as well (with the same amount).
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: Smooth Meter Fade In/Out

Post by eclectic-tech »

Well, this is what happens when a 10-year-old post is referenced. :D

When Kaelri posted this script, the ActionTimer measure did not exist O.O, and since the OP wanted to use the script, a method was offered.

But I agree with balala that using the ActionTimer is a better method.
Even though both give similar results, the ActionTimer is more efficient. :thumbup:
User avatar
Dany Gee
Posts: 33
Joined: July 11th, 2012, 8:32 am

Re: Smooth Meter Fade In/Out

Post by Dany Gee »

@balala
Could you please add the fade out effect to also activate on click on the photo?
For a poor programmer like me this task is already impossible :confused:
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Smooth Meter Fade In/Out

Post by balala »

Dany Gee wrote: July 19th, 2022, 7:36 am @balala
Could you please add the fade out effect to also activate on click on the photo?
For a poor programmer like me this task is already impossible :confused:
Definitely possible, however before starting to work I have a question. Do you want the transition take place only on click? I mean that in my code the transition take place after certain period (which can be set with the ChangeInterval variable). Should this be removed and get the image transition only on click, or the periodical transition should be kept and the click controlled transition should be added?
User avatar
Dany Gee
Posts: 33
Joined: July 11th, 2012, 8:32 am

Re: Smooth Meter Fade In/Out

Post by Dany Gee »

Click controlled transition should be added :)
THANK YOU IN ADVANCE! :thumbup:
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: Smooth Meter Fade In/Out

Post by eclectic-tech »

Dany Gee wrote: July 19th, 2022, 10:16 am Click controlled transition should be added :)
THANK YOU IN ADVANCE! :thumbup:
Give this variant of balala's code a try.

I added a MeasureClick to control the transition.
I also modified the MeasureTimer to update the next image after 2 seconds (originally was done halfway through the interval).
Added a TotalSteps variable to allow controlling the speed of the transition; higher value equals a slower transition.
When clicked to initiate a transition, the timer measure is reset.

Code: Select all

[Rainmeter]
Update=1000

[Variables]
Alpha=0
Cycle=0
; Set TotalSteps to control the transition time (Higher value equals slower transition)
TotalSteps=50
; Do not change this formula (Used to set alpha from 0~255)
Step=(256/#TotalSteps#)
Scale=1
Upd=[!UpdateMeasure "MeasureAlpha"][!UpdateMeterGroup "Images"][!Redraw]
ImagesPath=D:\MEGA\Pictures\Franczeska_Piorko\Slideshow\Temp
ChangeInterval=10

; Updates a new second image after 2 seconds and controls which is displayed
[MeasureTime]
Measure=Calc
Formula=(( MeasureTime + 1 ) % #ChangeInterval# )
IfCondition=((#CURRENTSECTION#>=2)&&(#Cycle#=0))
IfTrueAction=[!UpdateMeasure "MeasureImage1"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Stop 2"]
IfCondition2=((#CURRENTSECTION#>=2)&&(#Cycle#=1))
IfTrueAction2=[!UpdateMeasure "MeasureImage0"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Stop 2"]
IfCondition3=((#CURRENTSECTION#=0)&&(#Cycle#=0))
IfTrueAction3=[!SetVariable Cycle "1"][!CommandMeasure "MeasureAlpha" "Execute 1"][!CommandMeasure "MeasureAlpha" "Stop 2"]
IfCondition4=((#CURRENTSECTION#=0)&&(#Cycle#=1))
IfTrueAction4=[!SetVariable Cycle "0"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Execute 2"]
DynamicVariables=1

; Changes to the next image and resets the change interval
[MeasureClick]
Measure=Calc
Formula=#Cycle#
IfCondition=(#Cycle#=0)
IfTrueAction=[!UpdateMeasure "MeasureImage1"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Stop 2"][!SetVariable Cycle "1"][!CommandMeasure "MeasureAlpha" "Execute 1"]
IfCondition2=(#Cycle#=1)
IfTrueAction2=[!UpdateMeasure "MeasureImage0"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Stop 2"][!SetVariable Cycle "0"][!CommandMeasure "MeasureAlpha" "Stop 1"][!CommandMeasure "MeasureAlpha" "Execute 2"]
DynamicVariables=1
Disabled=1

[MeasureAlpha]
Measure=Plugin
Plugin=ActionTimer
ActionList1=Repeat FadeIn,40,#TotalSteps#
FadeIn=[!SetVariable Alpha "(Clamp((#Alpha#+#Step#),0,255))"]#Upd#
ActionList2=Repeat FadeOut,40,#TotalSteps#
FadeOut=[!SetVariable Alpha "(Clamp((#Alpha#-#Step#),0,255))"]#Upd#
DynamicVariables=1

[MeasureImage0]
Measure=Plugin
Plugin=QuotePlugin
PathName=#ImagesPath#
FileFilter=*.jpg;*.jpeg;*.gif;*.bmp;*.png
Subfolders=0
UpdateDivider=-1

[MeasureImage1]
Measure=Plugin
Plugin=QuotePlugin
PathName=#ImagesPath#
FileFilter=*.jpg;*.jpeg;*.gif;*.bmp;*.png
Subfolders=0
UpdateDivider=-1

[MeterImage0]
MeasureName=MeasureImage0
Meter=IMAGE
DynamicVariables=1
;ImageRotate=5
X=(72*#Scale#)
Y=(30*#Scale#)
W=(385*#Scale#)
H=(385*#Scale#)
Hidden=0
PreserveAspectRatio=1
ImageAlpha=(255-#Alpha#)
DynamicVariables=1
Group=Images
LeftMouseUpAction=[!EnableMeasure MeasureClick][!UpdateMeasure MeasureClick][!DisableMeasure MeasureClick][!DisableMeasure MeasureTime][!UpdateMeasure MeasureTime][!EnableMeasure MeasureTime]

[MeterImage1]
MeasureName=MeasureImage1
Meter=IMAGE
DynamicVariables=1
;ImageRotate=5
X=0r
Y=0r
W=(385*#Scale#)
H=(385*#Scale#)
Hidden=0
PreserveAspectRatio=1
ImageAlpha=#Alpha#
DynamicVariables=1
Group=Images
LeftMouseUpAction=[!EnableMeasure MeasureClick][!UpdateMeasure MeasureClick][!DisableMeasure MeasureClick][!DisableMeasure MeasureTime][!UpdateMeasure MeasureTime][!EnableMeasure MeasureTime]

Post Reply