It is currently October 27th, 2020, 4:26 am

## Convert a number range to another range, maintaining ratio

Tips and Tricks from the Rainmeter Community
StArL0rd84
Posts: 358
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

### Convert a number range to another range, maintaining ratio

Imagine you have a counting calc or loop measure that operate within a certain number range. (1-100)
But you need a different range of numbers for a animation elsewhere in the skin (0-255), but synced to the first measure.
Instead of creating measures for each and every little thing, you can convert (1-100) to (0-255) with a formula.

The formula:
((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)

And this is how it looks with the values inserted.
(([YourRangeMeasure] - 1) * (255 - 0) / (100 - 1) + 1)

Here i used the new range to control the alpha value of an image meter:
And we can round the number for accuracy. (Thank balala ;P)

Code: Select all

``````[MeterImage]
Meter=Image
ImageTint=255,0,0,(Round(([YourRangeMeasure] - 1) * (255 - 0) / (100 - 1) + 1))
DynamicVariables=1``````

And in the example skin i used the new range for the alpha value in the text meter. (20-255)
TexasRanger.gif
You do not have the required permissions to view the files attached to this post.
Last edited by StArL0rd84 on May 1st, 2019, 6:58 pm, edited 1 time in total.
([mWorkTime] = 1 ? #Work# : ([mEnergyLoss:%] >= 70% ? #Chillmode# : </>))
balala
Rainmeter Sage
Posts: 11634
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

### Re: Convert a number range to another range, maintaining ratio

Good point, but I have a suggestion here.
In such cases, when you're using the calculated value into an option which needs integer value (like ImageTint or FontColor), I'd round the calculated value, using a Round function. For example in the code of the uploaded skin, I'd replace the existing FontColor option of the [Text] meter (FontColor=255, 255, 255, (([MeasureRange] - #in_min#) * (#out_max# - #out_min#) / (#in_max# - #in_min#) + #out_min#)) with something like the following one: FontColor=255,255,255,(Round(([MeasureRange] - #in_min#) * (#out_max# - #out_min#) / (#in_max# - #in_min#) + #out_min#)).
Yes, this doesn't have too much importance, because in such cases, the not integer value is converted to integer, but just to be a little bit more precise.
StArL0rd84
Posts: 358
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

### Re: Convert a number range to another range, maintaining ratio

balala wrote: May 1st, 2019, 6:49 pm Good point, but I have a suggestion here.
In such cases, when you're using the calculated value into an option which needs integer value (like ImageTint or FontColor), I'd round the calculated value, using a Round function. For example in the code of the uploaded skin, I'd replace the existing FontColor option of the [Text] meter (FontColor=255, 255, 255, (([MeasureRange] - #in_min#) * (#out_max# - #out_min#) / (#in_max# - #in_min#) + #out_min#)) with something like the following one: FontColor=255,255,255,(Round(([MeasureRange] - #in_min#) * (#out_max# - #out_min#) / (#in_max# - #in_min#) + #out_min#)).
Yes, this doesn't have too much importance, because in such cases, the not integer value is converted to integer, but just to be a little bit more precise.
Astute observation balala, sharp as always ;P
I have updated the skin and documentation with your suggestion.
Thank you
([mWorkTime] = 1 ? #Work# : ([mEnergyLoss:%] >= 70% ? #Chillmode# : </>))
balala
Rainmeter Sage
Posts: 11634
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

### Re: Convert a number range to another range, maintaining ratio

StArL0rd84 wrote: May 1st, 2019, 7:00 pm Astute observation balala, sharp as always ;P
I have updated the skin and documentation with your suggestion.