Page 1 of 6

Re: An Alternative Little day/night chart

Posted: Tue 05 Feb 2013 3:08 pm
by beteljuice
An Alternative
The beteljuice has a great mistrust of (google) APIs and 'the cloud' etc. prefering to have some degree of control over what happens, and also reducing global internet traffic.

So here's a beteljuice plaything (not quite as neatly drawn) and with a different slant (or two) on display.

EDIT: V2.0 Incorporating drawing improvements / suggestions by Mark.
EDIT: V3.0 Incorporating logic fix by Mark Crossley.
EDIT: V3.1 hours markers option added

Image Midday (Civil) is 'North' and a 24 hour 'clock' hand shows 'now' time.
Image Midday (Civil) is 'North' and a 24 hour 'clock' hand shows 'now' time with hours markers.
Image 'Heavens' rotate East to West through North with a 'now' marker @ North.

As you can see Civil, Nautical and Astronomical twilights are shown.

Practically everything is configurable and most things can be 'posted' on-the-fly.

You MUST be running PHP 5+
If 'safe_mode' exists it should be "off". (Maybe unimportant following tweaks - unproven)
If you are unsure of the above, unzip and run the following file in your webspace:
fdebug.zip
If it suggests that safe_mode is enabled, check your web space control panel / settings and see if you can turn it "off", else contact your support.
If they say "Oh no can't do that its insecure", tell them its caused so much problems that it is depreciated in ver 5.3 and doesn't even exist in ver 5.4 ! - give them this link: http://uk.php.net/manual/en/features.safe-mode.php

GET / VIEW commented CODE

'Tis a beteljuice throwaway freebie ... enjoy or not as you wish :lol:

Edit: Forgot to mention. It's a stand-alone and no weather software is required :o

Edit: Basic usage ...

Using a txt editor such as Notepad++ change the timezone to YOUR location:

Code: Select all

$time_locale = "Europe/London";  // set your timezone - see: http://php.net/manual/en/timezones.php
If you are not using saratoga / carterlake template(s) you won't have a Settings.php so you need to change the lat / long, this is MY location ;)

Code: Select all

//----------------------------------------------------------------------------\\
// SETTINGS: only customise if you have no "Settings.php"                     \\
//----------------------------------------------------------------------------\\
if (!@(include_once "Settings.php")) {
   $SITE['latitude']      = 52.512; // N+, S-
   $SITE['longitude']      = -2.096; // W-, E+
}
   
To use it in an html page just call it like you would any other graphic.
Using your file name ....

Code: Select all

<img src="heavens.php" alt="day / night chart" title="day / night chart" />
EDIT:
If you really must have a bit of JavaScript to update the image on the page, please be aware that the 'resolution' of the graphic (regardless of size) is 1 degree (values rounded) which equates to 4 minutes.
So it would be pointless to have a refresh rate of less than 2 min. ;)

Re: Little day/night chart

Posted: Wed 06 Feb 2013 1:09 am
by gemini06720
mcrossley wrote:I picked this up from WD forum, some people on there were using the old depreciated Google chart API's and PHP to generate a little day/night graphic.
And, I picked up from you (you code modified to PHP), combined it with the code found/posted in the Weather-Watch forums and came up with this: :mrgreen:

Re: Little day/night chart

Posted: Wed 06 Feb 2013 8:55 am
by mcrossley
gemini06720 wrote:And, I picked up from you (you code modified to PHP), combined it with the code found/posted in the Weather-Watch forums and came up with this: :mrgreen:
That's the way to do it, code sharing helps everyone. ;)

Re: Little day/night chart

Posted: Wed 06 Feb 2013 11:30 am
by beteljuice
Just a thought ...
What happens if daylight is all (today) or dawn > dusk is all (today) ?

Re: Little day/night chart

Posted: Wed 06 Feb 2013 11:35 am
by mcrossley
beteljuice wrote:Just a thought ...
What happens if daylight is all (today)
You get a yellow disk?
beteljuice wrote:or dawn > dusk is all (today) ?
There is no night sector - your version with astronomical twilight will not have any night sector in the UK around mid-summer.

If I'm understanding you right.

Re: An Alternative Little day/night chart

Posted: Thu 21 Feb 2013 5:19 pm
by mcrossley
beteljuice wrote: The beteljuice has a great mistrust of (google) APIs and 'the cloud' etc. prefering to have some degree of control over what happens, and also reducing global internet traffic.
Hi betejuice, I ran into a problem with the script. I do not have a 'Settings.php' file and this fails:

Code: Select all

if ((include_once "Settings.php") == 0) {
   $SITE['latitude' ]      = 52.512; // N+, S-
   $SITE['longitude']      = -2.096; // W-, E+
}
I changed it to

Code: Select all

if (!@(include_once "Settings.php")) {
   $SITE['latitude' ]      = 52.512; // N+, S-
   $SITE['longitude']      = -2.096; // W-, E+
}
and the script now runs

Edit: and shouldn't the output header be

Code: Select all

header('Content-Type: image/png');
My implementation: http://weather.wilmslowastro.com/images/sun_graphic.php

Re: Little day/night chart

Posted: Thu 21 Feb 2013 10:36 pm
by beteljuice
No 'Settings' works for me, could this be due to 'safe' mode or someother variation of your php install ?

Edit: In line with response below ... the beteljuice did say "Safe mode should be off"
Edit: and shouldn't the output header be
:oops: See what you mean, I mixed up the header and the output, but it works :lol:
My code now corrected !

Obviously you can output what format you want BUT the line underneath must follow the same regime !

Re: Little day/night chart

Posted: Thu 21 Feb 2013 10:44 pm
by mcrossley
Yep, safe mode was on, I managed to switch it off but I'd changed the code by then.

Re: An Alternative Little day/night chart

Posted: Sun 24 Feb 2013 12:39 pm
by jdc
beteljuice wrote: 'Tis a beteljuice throwaway freebie ... enjoy or not as you wish :lol:
I'm currently enjoying this. Thank you very much for 'throwing' it!

Re: Little day/night chart

Posted: Sun 24 Feb 2013 1:25 pm
by beteljuice
@ jdc - Thanks for the feedback.

Nicely laid out / informative site :D

Re: Little day/night chart

Posted: Sun 24 Feb 2013 1:54 pm
by mcrossley
One 'improvement' I have made the beteljuices excellent code is to add some anti-aliasing (or simulate it).

As the GD sector drawing functions do not support anti-aliasing (even when it is turned on globally for the target image), internally I draw the graphic at 4x the linear size, then at the end resample back down to the 1/4 size required. The resampling creates the anti-aliasing effect for you.

Re: Little day/night chart

Posted: Sun 24 Feb 2013 3:36 pm
by beteljuice
Creep ... :lol:

The beteljuice was going to republish incorporating your changes (with credits), then I found this:

include('imageSmoothArc.php');

Please elucidate ....

Re: Little day/night chart

Posted: Sun 24 Feb 2013 4:06 pm
by mcrossley
Ah, I was going to use that plugin, it draws smooth sectors and arcs, but then when I looked into it further the author had completely changed the parameter meanings from the equivalent GD calls :( So the drawing angle is ant-clockwise instead of clockwise, so you have fiddle with the from/to angles to get it correct, the colour param takes an array rather than a integer colour - though the array can have 4 elements to support transparency.

http://www.ulrichmierendorff.com/softwa ... _arcs.html

I gave up and took the easy way out in the end - forgot to remove the include though!

Re: Little day/night chart

Posted: Sun 24 Feb 2013 5:25 pm
by PaulMy
I have added Mark's original chart and that has been working fine. Just thought I should try beteljuice's version as well but I could not get it to work.

First troubleshooting was to check on safe mode, and with the great help from GoDaddy I wrote my first 2 programs in PHP :) so now safe mode is off.

I copied the beteljuice's code in notepad++, in SETTINGS changed the location to American/Toronto and entered my lat and lon in $SITE[ ]

Saved the file as sunrise-set_chart.php and upload to http://www.komokaweather.com/weather

However http://www.komokaweather.com/weather/su ... _chart.php results in error

Are there other settings or changes I need to do?

Paul

Re: Little day/night chart

Posted: Sun 24 Feb 2013 5:49 pm
by mcrossley
That is the same error I was getting Paul - not sure if it is due to safe mode still being on or not (I thought mine was off, it was 'globally' but 'locally' it was on).

I changed the include once statements to get round it.
https://cumulus.hosiene.co.uk/viewtopic.p ... 532#p77532