It is currently April 19th, 2024, 9:08 pm

Index UV - Color Changer

Get help with creating, editing & fixing problems with skins
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Index UV - Color Changer

Post by PtitChat107 »

After the discovery of this topic on the change of color that can be applied to a bar, I decided to apply it to my own skin but only concerning the UV index.
So I declare the list of colors to use in the lua file but I always get this green color and I do not understand where my error may come from.

Code: Select all

-- ColorChanger v1.3 by Smurfier (smurfier20@gmail.com)
-- This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.

PROPERTIES={Colors='0,255,0|255,128,0|255,0,0';MeasureName='measureW1';MinimumValue=0;MaximumValue=10;}

function Initialize()
   MinValue,Colors,Measure=tonumber(PROPERTIES.MinimumValue),{},SKIN:GetMeasure(PROPERTIES.MeasureName)
   for a=1,4 do Colors[a]={} end
   if string.len(PROPERTIES.Colors)==0 or not string.match(PROPERTIES.Colors,'%d+%s-,%s-%d+%s-,%s-%d+') then
      print('ColorChanger: Invalid color string')
   elseif not Measure then
      print('ColorChanger: Cannot retrieve Measure '..PROPERTIES.MeasureName)
   else
      for a in string.gmatch(PROPERTIES.Colors,'[^%|]+') do
         local b={}
         for c in string.gmatch(a,'[^,]+') do table.insert(b,tonumber(c)) end
         for d=1,4 do table.insert(Colors[d],b[d] and b[d] or 255) end
      end
      Divider=math.ceil((tonumber(PROPERTIES.MaximumValue)-MinValue)/(#Colors[1]-1))
   end
end

function Update()
   if #Colors[1]<2 or not Measure then
      return #Colors[1]==1 and string.gsub(PROPERTIES.Colors,'|','') or '255,255,255,255'
   else
      local rValue,uColor=Measure:GetValue()-MinValue,{}
      Num=math.floor(rValue/Divider)
      for i=1,4 do table.insert(uColor,Average(Colors[i][Num+1],Colors[i][Num+2],rValue%Divider,Divider)) end
      return table.concat(uColor,',')
   end
end

function Average(a,b,c,d) return (a*(d-c)+(b and b or 0)*c)/d end

Code: Select all

; Weather info based on Rainmeter Illustro and VClouds Weather 2

[Rainmeter]
Update=300

[Metadata]
Name=Weather
Description=This skin shows the current weather conditions

[Variables]
fontName=Trebuchet MS
textSize=8
colorText=255,255,255,205
Key=6fe233ecf6999f2e8e6f4abb4b0d0b78
Lat=47.238
Lont=6.0243
Uni=ca
Lang=fr

;ConditionsWeather
[measureW0]
Measure=Plugin
Plugin=WebParser.dll
UpdateRate=900
Url=https://api.darksky.net/forecast/#Key#/#Lat#,#Lont#?lang=#Lang#&units=#Uni#&exclude=hourly,flags
RegExp=(?siU).*uvIndex":(.*)},

;Index UV
[measureW1]
Measure=Plugin
Plugin=WebParser.dll
Url=[measureW0]
StringIndex=1
MinValue=0
MaxValue=10
Substitute="":"..."

[measureW1Lua]
Measure=Script
ScriptFile=\ColorChanger.lua
MeasureName=measureW1

; --------------------------
; METERS
; Note: not in reading order
; --------------------------

[meterLabelIndexUV]
Meter=STRING
MeterStyle=styleLeftText
X=10
Y=140
W=190
H=14
Text="Index UV"

[meterValueIndexUV]
Meter=STRING
MeterStyle=styleRightText
MeasureName=measureW1
X=200
Y=0r
W=190
H=14
Text="%1 / 10"

[meterBarIndexUV]
Meter=BAR
MeterStyle=styleBar
colorBar=#[measureW1Lua]#
MeasureName=measureW1
DynamicVariables=1
X=10
Y=152
W=190
H=1

; ----------------------------------
; STYLES
; ----------------------------------

[styleLeftText]
StringAlign=LEFT
StringCase=NONE
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleRightText]
StringAlign=RIGHT
StringCase=NONE
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleBar]
BarOrientation=HORIZONTAL
SolidColor=50,240,255,255
I simplify this to the maximum so that it is more comprehensible but despite that I still do not understand.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Index UV - Color Changer

Post by FreeRaider »

A question: What should this script do?
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Re: Index UV - Color Changer

Post by PtitChat107 »

It should simply retrieve the "UV index" data and change the color of the bar (between 0 and 10) according to the data stored in the lua file.
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Index UV - Color Changer

Post by balala »

First of all, you should try to fix the name of the colorBar option of the [meterBarIndexUV] meter. Correctly this option is BarColor, not colorBar.
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Re: Index UV - Color Changer

Post by PtitChat107 »

balala wrote:First of all, you should try to fix the name of the colorBar option of the [meterBarIndexUV] meter. Correctly this option is BarColor, not colorBar.
Same result, always this green color :(
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Index UV - Color Changer

Post by balala »

PtitChat107 wrote:Same result, always this green color :(
To be honest I couldn't get the lua script to work properly. So, please pack the whole config and upload it, maybe this way I'll be able to test it.
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Re: Index UV - Color Changer

Post by PtitChat107 »

I had to change the coordinates gps to be able to test with different UV indexes but it seems that the green color becomes lightened when the index increases; Except that there is no green color in the lua file (finally not totally) !
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Index UV - Color Changer

Post by balala »

PtitChat107 wrote:I had to change the coordinates gps to be able to test with different UV indexes but it seems that the green color becomes lightened when the index increases; Except that there is no green color in the lua file (finally not totally) !
Just remove the # characters from the BarColor option of the [meterBarIndexUV] meter: BarColor=[measureW1Lua] (instead of the existing BarColor=[color=#FF0000]#[/color][measureW1Lua][color=#FF0000]#[/color]). They are not needed, because the [measureW1Lua] Script measure returns the proper color code.