Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 25

Lua Scripting • Re: Newbie asking for tips / samples

$
0
0
Each of the 8 sectors is one of my CPU core and shows some data about it.
I would like to make them to change color from blue to red to show the core temp, and change the size (the external diameter) to show the core load.

Given that each sector has to make the same math, i THINK that some common functions could be a better solution than rewriting everything 8 times. And, for what i've understand, functions are a LUA scripts thing.
For sure it is possible with a lua script as well, however for first, I'd try with simple Rainmeter code. As you figured out by yourself, the lua approach has the advantage of needing a single function, however let's see now the Rainmeter approach. Later we can switch to lua.
So, theoretically the disadvantage of the following approach is that you should have to calculate the eight color codes on eight different measures. But this is not needed, all calculation can be done on the apropriate meters, no need to add extra measures. Since you didn't share your code, I post a sample, using Image meters. Your meters most probably are some Shape meters, however not knowing them I used the most simple meter type, the Image meters. If we get this working as expected, using Shape meters is a much simpler task.
Let's assume you have some CPU measures, to get the CPU usage of each of the cores. Something like this:

Code:

[MeasureCPU1]Measure=CPUProcessor=1
This is returning the first core usage percent. Just mentioning here that with Windows 11 this values might not be correct, but this is another story. We can come back to this later, if needed.
Using the above measure, the Image meter associated with the first code might look this way:

Code:

[MeterCPU1]...SolidColor=(255*((Clamp([MeasureCPU1],(#Min#+2*(#Max#-#Min#)/3),#Max#))-(#Min#+2*(#Max#-#Min#)/3))/(#Max#-(#Min#+2*(#Max#-#Min#)/3))),(([MeasureCPU1]<=(#Min#+(#Max#-#Min#)/3))?(255*(((Clamp([MeasureCPU1],#Min#,(#Min#+(#Max#-#Min#)/3)))-#Min#)/((#Max#-#Min#)/3))):(255*((100-Clamp([MeasureCPU1],(#Min#+2*(#Max#-#Min#)/3),#Max#)-#Min#)/#Min#))),(255*((Clamp((100-[MeasureCPU1]),(#Min#+(#Max#-#Min#)/3),(#Min#+2*(#Max#-#Min#)/3))-(#Max#-#Min#)/3)-#Min#)/((#Max#-#Min#)/3))DynamicVariables=1
Seems complicated or maybe even frightening? Don't worry, it is not at all. It's not so complicated as it looks. For first I posted here only the SolidColor option, which sets the color based on the value returned by the [MeasureCPU1] measure. Note that is extremely important that this measure to return the value in the 0 - 100 range. If it returns the value into any other range, the meter won't work. Note the needed DynamicVariables=1 option as well, which I posted above. The other options of the meters are depending on how you want to create the meters.
In order this formula to work, you have to define in the [Variables] section the Min and Max variables, which you were talking about. For instance:

Code:

[Variables]Min=20Max=80
For eight cores, you'll have eight such meters, but the eight meters should exist even if you're using an any kind of lua script.
Try out this code and let me know if you could get it working. If you couldn't, post the code of your skin please, with both, the measures returning the CPU usage and the meters showing the usage, to can better advice.
Note that this solution doesn't change the size of the meters so far, but this will be the next step. For now test only the colors, please.

Statistics: Posted by balala — December 8th, 2024, 9:07 pm



Viewing all articles
Browse latest Browse all 25

Trending Articles