Not too clear on the math (not a rocket scientist), so it's accurate to within... I dunno, 2%?

Code: Select all

```
[Rainmeter]
; Uncomment (with loop formula below) for fast demo
;Update=20
Update=3600
[Metadata]
Name=Moon Phase
Author=PigAndante
Information=Shows the moon's current phase (roughly; the numbers are handwavey)
Version=1.0
License=Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
[Variables]
MoonDiameter=120
MoonRadius=(#MoonDiameter#/2)
BrightColor=077d9bff
DarkColor=115161ff
RightColor=#BrightColor#
MiddleColor=#DarkColor#
LeftColor=#BrightColor#
; from http://astropixels.com/ephemeris/phasescat/phases1601.html
MoonCycleLengthInSeconds=2551442.803200
; from empirical research
MoonCycleOffset=1537695
[MeasureTime]
Measure=Time
Timezone=0
[MeasureMoonPhaseCompletion]
; percentage from full moon (0.0) to full moon (1.0)
Measure=Calc
; Uncomment this formula for demo mode
;Formula=([MeasureLoop]/300)
Formula=(([MeasureTime:]-#MoonCycleOffset#)/#MoonCycleLengthInSeconds#)%1
DynamicVariables=1
; If waning, right side bright; otherwise, right side dark
IfCondition =([MeasureMoonPhaseCompletion] < 0.5)
IfTrueAction =[!SetVariable RightColor #DarkColor#][!SetVariable LeftColor #BrightColor#]
IfFalseAction =[!SetVariable RightColor #BrightColor#][!SetVariable LeftColor #DarkColor#]
; If crescent (25%-75%), middle section is dark; otherwise (gibbous) middle section is light
IfCondition2 =(0.25 < [MeasureMoonPhaseCompletion]) && ([MeasureMoonPhaseCompletion] < 0.75)
IfTrueAction2 =[!SetVariable MiddleColor #DarkColor#]
IfFalseAction2=[!SetVariable MiddleColor #BrightColor#]
; Optimization to get down to two shapes drawn: join the middle with the correct side of the moon
IfCondition3 =([MeasureMoonPhaseCompletion] <= 0.25) || ((0.5 <= [MeasureMoonPhaseCompletion]) && ([MeasureMoonPhaseCompletion] < 0.75))
IfTrueAction3 =[!SetVariable ShapeToUnionWith Shape4]
IfFalseAction3=[!SetVariable ShapeToUnionWith Shape5]
[MeasureLoop]
Measure=Loop
StartValue=0
EndValue=300
Increment=1
[ProgressCircle]
H=(#MoonDiameter#)
W=(#MoonDiameter#)
Meter=Shape
DynamicVariables=1
; Left side
Shape =Rectangle 0,0,#MoonRadius#,(#MoonDiameter#) | FillColor #LeftColor# | StrokeWidth 0
; Right side
Shape2=Rectangle #MoonRadius#,0,(#MoonDiameter#),(#MoonDiameter#) | FillColor #RightColor# | StrokeWidth 0
; Moon outline
Shape3=Ellipse #MoonRadius#,#MoonRadius#,#MoonRadius#,#MoonRadius#
; Left Portion
Shape4=Combine Shape | Intersect Shape3
; Right Portion
Shape5=Combine Shape2 | Intersect Shape3
; Contested portion
Shape6=Ellipse #MoonRadius#,#MoonRadius#,(#MoonRadius#*cos(2*PI*[MeasureMoonPhaseCompletion])),#MoonRadius# | FillColor #MiddleColor# | StrokeWidth 0
; Optimization: Join the middle with the correct side
Shape7=Combine Shape6 | Union #ShapeToUnionWith#
```