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

Lua Scripting • Re: Newbie asking for tips / samples

$
0
0
Thank you so much for such a detailed answer.
I didn't post my code 'cause it wasn't ready for public exposure.

But i've looked at your formula, and made a simpler skin just to test your code and debug stuffs, so we can have a common base.
Here's the code:

Code:

[Rainmeter]Update=500AccurateText=1BackgroundMode=2SolidColor=32,0,32,192SolidColor2=0,0,64,128GradientAngle=90BevelType=1BevelColor=255,255,255,196BevelColor2=64,64,64,196SkinWidth=500SkinHeight=100;left, top, right, bottom;DragMargins=20,40,60,80[Metadata]Name=Test & DebugAuthor=ParduzInformation=To test and debug scripts and codeVersion=0.1License=Creative Commons Attribution - Non - Commercial - Share Alike 3.0[Variables]TempMin=30TempMax=45TempRange=(#TempMax#-#TempMin#); Color Variation:; B   C   G   Y   R   <== Blue Cyan Green Yellow Red; Min 1   2   3   Max <== The temp range has to be divided by 4;  BBB bbb ... ...       +- Uppercase = 255;  ggg GGG GGG ggg    <==|  Lowercase = proportional value;  ... ... rrr.RRR       +- Dotted    = 0; So, we divide the range by 4TempDiv=(#TempRange#/4); The color value 0-255 then will be proportional to 0-TempDivTempToRGB=(255/#TempDiv#); Some other helper variables just for readability of the formulas; Red Min and Max rangeRMinDiv=(2*#TempDiv#)RMaxDiv=(3*#TempDiv#); Green Min and Max rangeGMinDiv=(0*#TempDiv#)GMaxDiv=(4*#TempDiv#); Blue Min and Max rangeBMinDiv=(2*#TempDiv#)BMaxDiv=(1*#TempDiv#); Debug stuffDebugTempSteps=1[m_DebugLoop]Measure=LoopStartValue=#TempMin#EndValue=#TempMax#Increment=#DebugTempSteps#LoopCount=0DynamicVariables=1[m_PingPong]Measure=CalcIfCondition=m_DebugLoop = #TempMax#IfTrueAction=[!SetOption m_DebugLoop InvertMeasure 1][!UpdateMeasure m_DebugLoop]IfCondition2=m_DebugLoop = #TempMin#IfTrueAction2=[!SetOption m_DebugLoop InvertMeasure 0][!UpdateMeasure m_DebugLoop]; The temperature as if the min is 0[m_0Temp]Measure=CalcFormula=(m_DebugLoop-#TempMin#); The temperature as percent of the range[m_0TempPerc]Measure=CalcFormula=(m_0Temp/#TempRange#); To debug, compute each color as a measure, and print them out[m_DebugRPart]Measure=CalcFormula=(#TempToRGB#*(Clamp(m_0Temp,#RMinDiv#,#RMaxDiv#)-#RMinDiv#))DynamicVariables=1[m_DebugGPart]Measure=CalcFormula=(#TempToRGB#*(m_0Temp <= #RMaxDiv# ? Clamp(m_0Temp, #GMinDiv#, #BMaxDiv#)-#GMinDiv#:#TempDiv#-(Clamp(m_0Temp,#RMaxDiv#,#GMaxDiv#)-#RMaxDiv#)))DynamicVariables=1[m_DebugBPart]Measure=CalcFormula=(#TempToRGB#*(#TempDiv#-(Clamp(m_0Temp,#BMaxDiv#,#BMinDiv#)-#BMaxDiv#)))DynamicVariables=1; The current temp label[mt_TempLabel]Meter=StringMeasureName=m_0TempX=50Y=5StringAlign=RightFontSize=20FontColor=255,255,255,255SolidColor=0,0,0,0Padding=2,2,2,2AntiAlias=1Text="[m_DebugLoop]°"DynamicVariables=1; The current temp as a % of the total range; The color bar SHOULD change, but it doesn't happens[mt_Thermometer]Meter=Bar;BarColor=([m_DebugRPart],[m_DebugGPart],[m_DebugBPart],255)BarColor=((#TempToRGB#*(Clamp(m_0Temp,#RMinDiv#,#RMaxDiv#)-#RMinDiv#)),(#TempToRGB#*(m_0Temp <= #RMaxDiv# ? Clamp(m_0Temp, #GMinDiv#, #BMaxDiv#)-#GMinDiv#:#TempDiv#-(Clamp(m_0Temp,#RMaxDiv#,#GMaxDiv#)-#RMaxDiv#))),(#TempToRGB#*(#TempDiv#-(Clamp(m_0Temp,#BMaxDiv#,#BMinDiv#)-#BMaxDiv#))))BarOrientation=HORIZONTALSolidColor=255,255,255,30MeasureName=m_0TempPercX=50Y=5W=400H=30[mt_ThermoLabelMin]Meter=StringFontColor=255,192,0,255SolidColor=255,255,255,0StringAlign=CenterFontSize=15X=50Y=35Text="#TempMin#"[mt_ThermoLabelMax]Meter=StringFontColor=255,192,0,255SolidColor=255,255,255,0StringAlign=CenterFontSize=15X=450Y=35Text="#TempMax#"; The computed colors, to see the results of the formulae[strStyle]Y=50W=50StringAlign=CenterFontSize=20SolidColor=0,0,0,192Padding=2,2,2,2AntiAlias=1[mt_ShowRPart]Meter=StringMeasureName=m_DebugRPartMeterStyle=strStyleX=100FontColor=255,0,0,255DynamicVariables=1[mt_ShowGPart]Meter=StringMeasureName=m_DebugGPartMeterStyle=strStyleX=160FontColor=0,255,0,255DynamicVariables=1[mt_ShowBPart]Meter=StringMeasureName=m_DebugBPartMeterStyle=strStyleX=220FontColor=0,128,255,255DynamicVariables=1
And this is how it looks:
testskin.jpg
I've modified your formula, and made measures just to show the results (i've tried to comment well the code), but no matter what i try, the bar color never changes from cyan, even if the R, G and B amount are correct.

I don't know what I am doing wrong. Can you point it to me?

A bit more generic question: i've create some variables for "static" numbers like sums or divisions of variables that won't change, and also to make the formulae more readable. The reasoning was to avoid to make the same division over and over, but then i see that variables are a bit like C macros, so them get "expanded" where they are inserted, hence i doubt my reasoning has any value. Do this impact Rainmeter performances? is it a good or bad technique?

Thanks again.

Statistics: Posted by Parduz — Today, 4:27 pm



Viewing all articles
Browse latest Browse all 1071

Trending Articles