I've started to work with your idea and here's what I reached:
Equation.ini:
Code: Select all
[Rainmeter]
Update=-1
BackgroundMode=2
SolidColor=80,80,80,220
[Variables]
Equation=x^2+8x+12=0
[MeasureLuaScript]
Measure=Script
ScriptFile=Script.lua
[MeterColor]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=255,255,255
FontEffectColor=0,0,0
StringEffect=Shadow
FontSize=10
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=#Equation##CRLF##Res1##CRLF##Res2#
DynamicVariables=1
Script.lua:
Code: Select all
function Initialize()
Equation = SKIN:GetVariable('Equation')
a, b, c = '', '', ''
n = 0
Coefficients = {}
for i=1,#Equation do
Coefficients[i] = '0'
end
for i = 1,#Equation do
Coefficients[i] = string.sub(Equation, i, i)
end
i = 0
repeat
i = i + 1
until ((( Coefficients[i] == 'x' ) and ( Coefficients[i+1] == '^' ) and ( Coefficients[i+2] == '2' )) or i == #Equation)
if i < #Equation then
for i = 1,#Equation do
if ( Coefficients[i] == 'x' ) and ( Coefficients[i+1] == '^' ) and ( Coefficients[i+2] == '2' ) then
if i-1 >= 1 then
for j = 1,(i-1) do
a = a .. Coefficients[j]
end
end
if i-1 < 1 then
a = '1'
end
n = i + #a + 2
end
end
for i = 1,#Equation do
if ( Coefficients[i] == 'x' ) and ( Coefficients[i+1] ~= '^' ) then
for j = n,(i-1) do
b = b .. Coefficients[j]
end
n = i+1
end
end
for i = 1,#Equation do
if Coefficients[i] == '=' then
for j = n,(i-1) do
c = c .. Coefficients[j]
end
n = i+1
end
end
a, b, c = tonumber(a), tonumber(b), tonumber(c)
if Delta(a, b, c) >= 0 then
SKIN:Bang('!SetVariable', 'Res1', 'x1='..(math.floor(Result1(a, b, c))+(math.floor(100*(Result1(a, b, c)-math.floor(Result1(a, b, c)))))/100))
SKIN:Bang('!SetVariable', 'Res2', 'x2='..(math.floor(Result2(a, b, c))+(math.floor(100*(Result2(a, b, c)-math.floor(Result2(a, b, c)))))/100))
else
SKIN:Bang('!SetVariable', 'Res1', 'This equation has no real solutions.')
SKIN:Bang('!SetVariable', 'Res2', '')
end
else
for i = 1,#Equation do
if Coefficients[i] == 'x' then
for j = 1,(i-1) do
a = a .. Coefficients[j]
end
n = i+1
end
end
for i = 1,#Equation do
if Coefficients[i] == '=' then
for j = n,(i-1) do
b = b .. Coefficients[j]
end
n = i+1
end
end
a, b = tonumber(a), tonumber(b)
SKIN:Bang('!SetVariable', 'Res1', 'x='..(-b/a))
SKIN:Bang('!SetVariable', 'Res2', '')
end
end
function Delta(a, b, c)
return (b*b - 4*a*c)
end
function Result1(a, b, c)
return ((-b-math.sqrt(Delta(a, b, c)))/(2*a))
end
function Result2(a, b, c)
return ((-b+math.sqrt(Delta(a, b, c)))/(2*a))
end
function Update()
end
This skin can handle the first and second degree equation. The first must have this form: eg 6x-12=0, the second: x^2-3x+2=0. Until now other forms are not accepted (eg 2+x^2-3x=0 or x^2-3x=-2). I'm not very good in lua scripting, I hope you'll not laughing on a such convoluted code. Maybe someone much better than me will help us.