It is currently March 29th, 2024, 7:40 am

Questions About Calc Measure

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

balala wrote: March 6th, 2020, 6:52 pm Yep, just tested and it does.
Nice - thanks for letting me know. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Questions About Calc Measure

Post by jsmorley »

Yeah, my original Lua was intended to be used with the day of the month...

Here is a more robust example:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureRandom]
Measure=Calc
Formula=Random
LowBound=100
HighBound=99999
UpdateRandom=1
UpdateDivider=5

[MeasureBigNumber]
Measure=String
String=13452345645670392874958343

[Lua]
Measure=Script
ScriptFile=NumbersToWords.lua
Disabled=1

[MeterDisplayRandom]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
InlineSetting=Case | Sentence
Text=[MeasureRandom]#CRLF#[&Lua:ConvertNumToWords('[&MeasureRandom]')]

[MeterDisplayBigNumber]
Meter=String
Y=10R
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
ClipString=2
ClipStringW=600
DynamicVariables=1
InlineSetting=Case | Sentence
Text=[MeasureBigNumber]#CRLF#[&Lua:ConvertNumToWords('[&MeasureBigNumber]')]

As written, requires an integer, although it wouldn't necessarily need to...

Code: Select all

function Initialize()

	inverse_units = {
		"vigintillion ",     -- 10^63
		"novemdecillion ",   -- 10^60
		"octodecillion ",    -- 10^57
		"septendecillion ",  -- 10^54
		"sexdecillion ",     -- 10^51
		"quindecillion ",    -- 10^48
		"quattuordecillion ",-- 10^45
		"tredecillion ",     -- 10^42
		"duodecillion ",    -- 10^39
		"undecillion ",     -- 10^36
		"decillion ",       -- 10^33
		"nonillion ",       -- 10^30
		"octillion ",       -- 10^27
		"septillion ",      -- 10^24
		"sextillion ",      -- 10^21
		"quintillion ",     -- 10^18
		"quadrillion ",     -- 10^15
		"trillion ",        -- 10^12
		"billion ",         -- 10^9
		"million ",         -- 10^6
		"thousand ",        -- 10^3
	} -- inverse_units
  
	inverse_numbers = {
		"one ",
		"two ",
		"three ",
		"four ",
		"five ",
		"six ",
		"seven ",
		"eight ",
		"nine ",
		"ten ",
		"eleven ",
		"twelve ",
		"thirteen ",
		"fourteen ",
		"fifteen ",
		"sixteen ",
		"seventeen ",
		"eighteen ",
		"nineteen ",
		"twenty ",
		[30] = "thirty ",
		[40] = "forty ",
		[50] = "fifty ",
		[60] = "sixty ",
		[70] = "seventy ",
		[80] = "eighty ",
		[90] = "ninety ",
	}  -- inverse_numbers
 
end

function ConvertNumToWords(arg)
  
	-- Convert a number to words
	-- Original Author: Nick Gammon
	-- Date: 18th March 2010

	-- See: http://www.gammon.com.au/forum/?id=10155

	-- preliminary sanity checks
	
	s = tostring(arg)
	
	if not type(tonumber(s)) == "number" then
		print("Not a number")
		return 0
	end

	if string.match(s, "-") then
		negPrefix = "negative "
		s = string.gsub(s, "-", "")
	else 
		negPrefix = ""
	end

	if #s == 0 then
		print("No number supplied")
		return 0
	elseif #s > 66 then
		print("Number too big to convert to words")
		return 0
	end -- if
	
	-- make multiple of 3
	while #s % 3 > 0 do
		s = "0" .. s
	end -- while
      
	result = ""
	start = #inverse_units - (#s / 3) + 2
  
	for i = start, #inverse_units do
		group = tonumber(string.sub (s, 1, 3))
	if group > 0 then
		result = result .. ConvertTo999 (group) .. inverse_units [i]
	end -- if not zero
		s = string.sub(s, 4)    
	end -- for
  
	result = result .. ConvertTo999(tonumber (s)) 

	if result == "" then
		result = "zero"
	end -- if
  
	return negPrefix .. (string.gsub(result, " +$", ""))  -- trim trailing spaces

end -- ConvertNumToWords

function ConvertTo999(n)

	if n <= 0 then
		return ""
	end -- if zero
  
	hundreds = math.floor(n / 100)
	tens = math.floor(n % 100)
	result = ""

	-- if over 99 we need to say x hundred  
	if hundreds > 0 then
  
    result = inverse_numbers[hundreds] .. "hundred "
    if tens == 0 then
      return result
    end -- if only a digit in the hundreds column
  
	-- to have "and" between things like "hundred and ten"
	-- uncomment the next line
	result = result .. "and "

	end -- if
  
	-- up to twenty it is then just five hundred (and) fifteen
	if tens <= 20 then
		return result .. inverse_numbers[tens] 
	end -- if

	-- otherwise we need: thirty (something)
	result = result .. inverse_numbers[math.floor(tens / 10) * 10] 
  
	-- get final digit (eg. thirty four)
	local digits = math.floor(n % 10)

	-- to put a hyphen between things like "forty-two" 
	-- uncomment the WITH HYPHEN line and 
	-- comment out the NO HYPHEN line

	if digits > 0 then
		-- result = result ..  inverse_numbers [digits]  -- NO HYPHEN
		result = string.sub(result, 1, -2) .. "-" ..  inverse_numbers[digits]  -- WITH HYPHEN
	end -- if 

	return result
  
end -- ConvertTo999

1.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Questions About Calc Measure

Post by balala »

jsmorley wrote: March 6th, 2020, 7:19 pm Yeah, my original Lua was intended to be used with the day of the month...
Ok, this explains why it didn't properly work in any circumstances.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

jsmorley wrote: March 6th, 2020, 7:19 pmHere is a more robust example [...]
Yes, that's a better example to emphasize Lua's usefulness. Not the best, as regex could probably do reasonably well here too (I know, right?), but much better than the previous one. Oh, and I love your wallpaper, haha! That's one big ugly dinosaur you have there... :twisted:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Questions About Calc Measure

Post by jsmorley »

DragonFace.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

Thanks for the full image. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: Questions About Calc Measure

Post by Lssg97 »

jsmorley wrote: March 5th, 2020, 2:35 pm Here is another example...


Image
Hi jsmorley
Did you make this skin? I am actually looking for similar skin. May I use it?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Questions About Calc Measure

Post by jsmorley »

Lssg97 wrote: March 10th, 2020, 5:06 am Hi jsmorley
Did you make this skin? I am actually looking for similar skin. May I use it?
https://forum.rainmeter.net/viewtopic.php?f=27&t=22696#p119763
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: Questions About Calc Measure

Post by Lssg97 »

Thank You very much. :rosegift:
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

Not quite similar, but really flexible and powerful (and now without flickering, due to the custom tooltips ;-) ):
Feeds.jpg
P.S. For the Rainmeter feed, jsmorley's one is better than mine, because it only displays the items' title. :thumbup:
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth