Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moon Phase / Mondphase
Hi guys! happy.gif
Here's my new brand script! And it's my first one! We're dealing with... moon phases! Easy, huh?
The main function draws the moon with the given phase. Simple as that.

Here's the output on my CFAG12864B-TMI-V:
user posted image
It the same moon of these days! Check outside the window! biggrin.gif
An animated sample:
user posted image
It also works for other graphic LCDs. Best results with dark background/bright pixels, improvements are scheduled (check the comments).

And here's the script. Sorry for the length! But each function is remarked, at least.
/*** FMod v1.00
 Returns a floating point modulo operation using two parameters.
  Possible improvements:
 - Making it work also for negative quotients./
 %If(%FMod->Para0() < 0) Then{

/*** From70 v1.00
 Returns the number of seconds from 1-1-1970, 12:00 am.
 The function accepts 7 parameters: year, month (January is 1),
 day, hour (0-23), minute, second, millisecond. If no parameter
 is passed, then the system time is used.
  Known bugs:
 - Works only for not-too-weird dates (i.e., it considers 2100
   as a leap year.). I hope it's the only bug!
  Possible improvements:
 - Solving the bug!/
%DefFunc(From70, Local=
 %List.Add(dm,0)  %List.Add(dm,31)  %List.Add(dm,59)  %List.Add(dm,90)
 %List.Add(dm,120)  %List.Add(dm,151)  %List.Add(dm,181)  %List.Add(dm,212)
 %List.Add(dm,243)  %List.Add(dm,273)  %List.Add(dm,304)  %List.Add(dm,334)
 %If(%From70->Para0() = '') Then{
 %If((%Mod(%year(),4) = 2) AND (%month() < 2)) Then{
 %Inc(%Inc(%Inc(%Inc(%Inc(%Mul(%year(),31536000),%Mul(%Inc(%Inc(%day(),%dm(%month())),%leapy()),86400)),%Mul(%hour(),3600)),%Mul(%minute(),60)),%second()),%Div(%millis(),1000)) /Veeery long and obscure piece of code!/

/*** MoonPhase v1.00
 Determines the moon phase based on system time.
 0 = full moon, 0.25 = last quarter,
 0.5 = new moon, 0.75 = first quarter
  Possible improvements:
 - Calculation on given date and time
 - On June 22nd, 2005 the moon is full. It's my birthday! Smile
   And 10:10pm is my "birth time"!/
%DefFunc(MoonPhase, Local=

/*** DrawMoon v0.5
 Draw the "moon". X,Y of the upper left corner are the first two
 arguments, the third is the diameter in pixel. The 4th argument is
 a number expressing the moon phase, as specified in the %MoonPhase()
 function. If omitted, it's calculated using the system time.
  Possible improvements:
 - Mirror bit flag (for Aussies Smile
 - Negative drawing
 - Color selection/
%DefFunc(DrawMoon, Local=
 %If(%DrawMoon->Para3() = '') Then{
 %DefVar(rad, Local=%DrawMoon->Para2())
  %If(%MP() > .5) Then{

/insert textmode script code here/


/Demo: one-minute lunar revolution!/

/Demo: actual moon/

Any opinion? Bug report? Insult? smile.gif

Have a nice scripting!

Forum Jump:

Users browsing this thread: 1 Guest(s)