Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com > PHP Changing a div colour via fetching the Sunrise and Sunset times and calculating the..

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 02-16-2013, 10:16 PM PM User | #1 MrTIMarshall Regular Coder   Join Date: Nov 2010 Posts: 347 Thanks: 44 Thanked 1 Time in 1 Post Changing a div colour via fetching the Sunrise and Sunset times and calculating the.. // Fetch Data form an external website, for this data I used timeanddate.com. Feb 16, 2013; SunRise: 7:12 AM SunSet: 5:18 PM //Changing their values into seconds var SunRise = calc ((7*3600)+(60*12)))) var SunSet = calc (43200+((5*3600)+(18*60))) // How long the day time is Var DayTIme = calc SunSet - SunRise // Calculating how long a particular sky colour lasts for (day). var DayColourSwitch = DayTime/10 // Working out when the sky colours change. var DayColourTime01 = SunRise var DayColourTime02 = SunRise + DayColourSwitch var DayColourTime03 = SunRise + (DayColourSwitch *2) var DayColourTime04 = SunRise + (DayColourSwitch *3) var DayColourTime05 = SunRise + (DayColourSwitch *4) var DayColourTime06 = SunRise + (DayColourSwitch *5) var DayColourTime07 = SunRise + (DayColourSwitch *6) var DayColourTime08 = SunRise + (DayColourSwitch *7) var DayColourTime09 = SunRise + (DayColourSwitch *8) var DayColourTime10 = SunRise + (DayColourSwitch *9) So above is the calculations for how long the say tie is which will be based upon the actual sun rise and sun set. To start with, the colour of the sky will change throughout the day, first starting to become bright at DayColourTime01 and then you will see the final daytime bright colour at DayColourTime10. Eventually there will also be a sun in the sky which you first see at DayColourTime01 and unnoticeable to the user will go across the sky and disappear once it reaches SunSet. The whole reason I have calculated the colour switches, is due to, in the past having difficulties gaining help on this to load the correct colour upon loading the website, therefore using the my above calculations, you can then check the GMT time upon loading the website and load the correct time and then whilst they are on the website, it will listen to the time to know when to switch the colour. On to the nighttime colours: // Fetch tomorrows SunRise time which is 7:10 AM // Next days sunrise in seconds from 00:00 var NextSunRise = calc ((7*3600)+(60*10)))) // Calculating the Night Time period var NightTime = (86400-(SunSet))+NextSunRise // Calculating how long a particular sky colour lasts for (night). var NightColourSwitch = NightTime/10 This is where I yet again become stuck with teh theory on how to do this. Although I don't know how to do this programming wise, I understand the theory, whether it is a good on or not. I know how to calculate the times for the listening for when to swich the colour, however I do not know how to do it when it goes past 00:00, whether you can put an iff statement into a calculation. I do hope what I am trying to explain what I am trying to do, does not look like a big mess and I will be watching my thread to explain any answers. To summarize: I want a div on my website for the sky to dynamically change throughout the day but not by a fixed time. I would like to actually fetch the sun rise and sun set times and calculate the tweens between the colour changes, eventually add a moon and sun motion into the div with only show between these periods and progress from there. Thank you very much for any help and/or advice in helping me achieve what I am trying to accomplish. Best Regards, Tim
 02-16-2013, 10:44 PM PM User | #2 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,595 Thanks: 4 Thanked 2,597 Times in 2,566 Posts Are you looking for a PHP replacement for this? __________________ PHP Code: header('HTTP/1.1 420 Enhance Your Calm');
02-16-2013, 11:53 PM   PM User | #3
MrTIMarshall
Regular Coder

Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
Quote:
 Originally Posted by Fou-Lu Are you looking for a PHP replacement for this?
A PHP replacement is what I am hoping to achieve, to learn a little more basic PHP and fetching information from an external website. I also need help on the theory I have planned out for that I have done so far, whereas the method I use to space out when the colours change, it would exceed 86400 seconds/24 hours and if so, I would need to add an iff statement to take 86400 away from the calculation to continue the path.

Best Regards,
Tim

 02-17-2013, 05:37 PM PM User | #4 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,595 Thanks: 4 Thanked 2,597 Times in 2,566 Posts Fetching information from external websites can be done via file_get_contents if allow_url_fopen directive is enabled, or by using curl or sockets to send a new request remote. You can also perform sunrise/sunset commands if you know the latitude and longitude of where you are looking for. If its always the same place hardcoded, than you can manually provide these. User based takes more work since I don't believe any PHP extension includes approximate latitude / longitude, but the client side JS may be able to coerce the browser to reveal it. Once you have a valid latitude and longitude, PHP can use the date_sun_info function available since 5.1.2. This gives you a lot of information including sunrise, sunset and transit (ie: "noon"). So I'm not exactly sure what you want to do with the transition periods, but they can all be calculated based off of the sunrise, sunset, transit. Pretty sure the transit is the time for the sun's zenith. If you give it a specific lat/long, then that would be the best approach. You can use date add/sub/diff functionality to determine which step you are between them. Also, if you really want to use an external site, I would suggest looking for a soap server on the site itself. Weather sites often have soap services enabled so it makes implementation near flawless. You would establish a soap connection to them, and call functions from their api just as if they were your own. So if they had one to get sun phases, it may be along the lines of \$soapClient->getSunPhases(\$lat, \$long); for example. The site you have provided definitely has an api, but I haven't looked into what it actually provides. __________________ PHP Code: header('HTTP/1.1 420 Enhance Your Calm');
 02-18-2013, 03:33 AM PM User | #5 byrondallas New Coder   Join Date: Jul 2011 Location: USA Posts: 39 Thanks: 0 Thanked 1 Time in 1 Post You can grab the latitude and longitude from google maps like I've done in this example: http://byrondallas.heliohost.org/php..._info_form.php

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 02:17 PM.