It is currently March 28th, 2024, 11:52 pm

Help with Image Rotate/Dynamic Sizing

Get help with creating, editing & fixing problems with skins
HGWT
Posts: 2
Joined: May 3rd, 2021, 6:07 pm

Help with Image Rotate/Dynamic Sizing

Post by HGWT »

Hello, I am having a blockage, and could use some help. In short, I want to do this:
1.Rotate an image around its axis
(While)
2. resizing that image as specified in the code from the file. i.e. if the .png is 1000x1000 i want to be able to specify the image will be 200x200 in the rotate code.

Image rotate works great (https://docs.rainmeter.net/tips/rotate-an-image-around-its-center/) but the image has to be sized in the original file, it cannot be resized in the code. Is there any way to use image rotate but resize the image on import to the code?? Or specify the size? I tried to specify size and it will not work with this code. This is their example code, what would I put in here to resize my .png image file??? I want to make this skin dynamic in sizing so I need some way to scale the image file on the fly....

Code: Select all

[Rainmeter]
Update=50
DynamicWindowSize=1

[Variables]
ImageW=128
ImageH=128

[MeasureRotate]
Measure=Calc
Formula=(MeasureRotate % 360) + 1
MaxValue=360

[MeterRotate]
Meter=Rotator
MeasureName=MeasureRotate
ImageName=Circle.png
OffsetX=(#ImageW# / 2)
OffsetY=(#ImageH# / 2)
W=#ImageW#
H=#ImageH#
Thank you!
Last edited by balala on May 3rd, 2021, 7:24 pm, edited 1 time in total.
Reason: Please use <code> tags whenever are posting code snippets. It's the </> button.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with Image Rotate/Dynamic Sizing

Post by balala »

HGWT wrote: May 3rd, 2021, 6:18 pm Image rotate works great (https://docs.rainmeter.net/tips/rotate-an-image-around-its-center/) but the image has to be sized in the original file, it cannot be resized in the code. Is there any way to use image rotate but resize the image on import to the code?? Or specify the size? I tried to specify size and it will not work with this code. This is their example code, what would I put in here to resize my .png image file??? I want to make this skin dynamic in sizing so I need some way to scale the image file on the fly....
No, there is no way to resize the image used into a Rotator meter. The only way to do this would be the TransformationMatrix, which is an extremely powerful option but unliked by many. It has its own disadvantages, but unfortunately in this case I couldn't get it to properly work in getting the Rotator resized. I suppose this has something to do with the order in which the options are aplied to the Rotator meter, but here a dev peobably would be needed to tell what's going on.
But doesn't matter, I'd propose another way to do this, not the Rotator meter. I'd create an Image meter and would rotate it with the previously mentioned TransformationMatrix option. This can easily be done (well sort of, a rellatively complex math is involved, but definitely can be done).
Please let me know if you are interested, to write a sample code on how to do this.
HGWT
Posts: 2
Joined: May 3rd, 2021, 6:07 pm

Re: Help with Image Rotate/Dynamic Sizing

Post by HGWT »

balala wrote: May 3rd, 2021, 7:58 pm No, there is no way to resize the image used into a Rotator meter. The only way to do this would be the TransformationMatrix, which is an extremely powerful option but unliked by many. It has its own disadvantages, but unfortunately in this case I couldn't get it to properly work in getting the Rotator resized. I suppose this has something to do with the order in which the options are aplied to the Rotator meter, but here a dev peobably would be needed to tell what's going on.
But doesn't matter, I'd propose another way to do this, not the Rotator meter. I'd create an Image meter and would rotate it with the previously mentioned TransformationMatrix option. This can easily be done (well sort of, a rellatively complex math is involved, but definitely can be done).
Please let me know if you are interested, to write a sample code on how to do this.
Yes I am definitely interested. Please let me know how. thanks for your help!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with Image Rotate/Dynamic Sizing

Post by balala »

HGWT wrote: May 3rd, 2021, 8:22 pm Yes I am definitely interested. Please let me know how. thanks for your help!
Alright, here is it. Replace the [MeterRotate] meter with the following one:

Code: Select all

[MeterRotate]
Meter=Image
ImageName=Circle.png
X=0
Y=0
W=#ImageW#
H=#ImageH#
TransformationMatrix=(Cos(Rad([MeasureRotate])));(-Sin(Rad([MeasureRotate])));(Sin(Rad([MeasureRotate])));(Cos(Rad([MeasureRotate])));([#CURRENTSECTION#:X]+[#CURRENTSECTION#:W]/2)-([#CURRENTSECTION#:X]+[#CURRENTSECTION#:W]/2)*Cos(Rad([MeasureRotate]))-([#CURRENTSECTION#:Y]+[#CURRENTSECTION#:H]/2)*Sin(Rad([MeasureRotate]));([#CURRENTSECTION#:Y]+[#CURRENTSECTION#:H]/2)+([#CURRENTSECTION#:X]+[#CURRENTSECTION#:W]/2)*Sin(Rad([MeasureRotate]))-([#CURRENTSECTION#:Y]+[#CURRENTSECTION#:H]/2)*Cos(Rad([MeasureRotate]))
DynamicVariables=1
Note that I added a X=0 and Y=0 option to this meter, but you can place the meter wherever you want / need it, the rotation still will work. Same way doesn't matter how are you resizing the meter.
I admit the TransformationMatrix option is not looking good, but it's not so complicated as it seems on a first look. If you want I can describe how all those elements have been written.
Please test this code and let me know how does it work. Hope it will.