Blog

Calculate Moon Rise and Set in PHP

If you've been paying attention to my Twitter account, you've probably seen a reference or two about how I've been calculating the positions of astronomical bodies. Well, today I release part of that to you.

Download: Source

The above code is pretty much a direct port of Keith Burnett's implementation here. Outside of porting, my only changes were some code clean up and having the timezone be calculated automatically for the longitude given. This means that you will always get back a time stamp that is local to the point of origin.

How to Use

Moon::calculateMoonTimes(month, day, year, latitude, longitude);

Code: php
  1. date_default_timezone_set('America/Chicago');
  2. include('moon.php');
  3. print_r(Moon::calculateMoonTimes(6, 28, 2011, 36.754478, -96.110291));
  4. ?>

The above code will output the following result:

Code: output
  1. stdClass Object ( [moonrise] => 1309246800 [moonset] => 1309300560 )

Moonrise and moonset, as stated previously, are a Unix time stamp local to the latitude and longitude given.

How Many Times Can One Man Code the Same Thing?

I mentioned some days ago my intent to create Tetris Attack clone worthy of its source material for the iPad. This got me to realizing that I've coded this particular game to some varying level to completion five times now, six if you include the yet to be written iPad version.

Six times. And now you'll get the code for a good many of those.

First Attempt

Bask in its shittiness

Source: Download

My first shot for a TAttack clone didn't make it too far. It was little more of a see-if-I-could attempt. Written in Visual Basic and using GDI for graphics, there's not much to see here except how terrible it is.

Read More

Racing the Clock for a Code Release

Pushing it a bit close tonight, but that's what happens when you go to a once in a lifetime screening of the extended cut of Two Towers in the theater and it's nearly four hours long. But, whatever.

Makes a very nice screensaver indeed

Download: Source

Some time ago, a coworker passed along a link to this very nifty Colour Clock which displays the time and uses the values of said time to drive the background color. It's really quite pretty and nifty. Back when he linked me, there was the flash version on the site and a download for an OS X screen saver. No Windows love.

So, I fired up my copy of Visual Studio and set about correcting this sadness. I never really polished it to the extent I wanted, which is why I'm putting it up as a source code release. There is a binary in there, but no installer or anything.

Also, before I created this version, I also conjured up a JavaScript one as well, which you can see here.

Make it open - The Tetras

The Tetra logo, courtesy of Don Kennedy

Tetra: [ Download ]

Tetra 2: [ Download ]

Picking up where I left off last time, we shall progress forward with my CMS releases.

After realizing that the core model of YPNgine seemed broken (looking back it may not have been, but whatever), I decided to scrap the entire project and go a completely different route. When I began conceptualizing this new CMS, there were a few things that I needed to consider from the very start: security and extensibility. With that, I began working on Tetra (named after the type of fish I had at the time).

Read More