Jump to content

MrTIMarshall

Members
  • Posts

    69
  • Joined

  • Last visited

Everything posted by MrTIMarshall

  1. I'm guessing that I have gone wrong somewhere as the div constantly says 40% and hasn't changed colour...
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style> body { margin:0; padding:0; } </style> </head> <body> <?php $lat = 52; $long= -2; // $timenow = time(); // live version $hour = isset($_GET['hour']) ? $_GET['hour'] : 0; $timenow = mktime($hour,0,0); // testing version $today = mktime(0,0,0); $todayInfo = date_sun_info($today, $lat, $long); $nighttime = false; switch(true) { case $timenow < $todayInfo['sunrise']: // is it pre-sunrise // get last night's sunset $nighttime = true; $yesterdayInfo = date_sun_info(strtotime('-1 days', $today), $lat, $long); $percent = round(($timenow - $yesterdayInfo['sunset'] )*100/($todayInfo['sunrise'] - $yesterdayInfo['sunset'])); break; case $timenow > $todayInfo['sunset']: // get tomorrow's sunrise $nighttime = true; $tomorrowInfo = date_sun_info(strtotime('+1 days', $today), $lat, $long); $percent = round(($timenow - $todayInfo['sunset'] )*100/($tomorrowInfo['sunrise'] - $todayInfo['sunset'])); break; default: $percent = round(($timenow - $todayInfo['sunrise'])*100/($todayInfo['sunset'] - $todayInfo['sunrise'])); break; } if ($nighttime) { $bg = '#000'; $fg = '#FFF'; } else { $bg = '#FFF'; $fg = '#000'; } if ($nighttime) { $bgcols = array ( 20 => '#CCC', 40 => '#888', 60 => '#333', 80 => '#888', 100 => '#CCC' ); foreach ($bgcols as $pc => $color) { if ($percent <= $pc) { $bg = $color; break; } } $fg = '#FFF'; } else { $bgcols = array ( 20 => '#BAF', #A0ACFE 40 => '#56F', #5166FD 60 => '#02F', #0220F0 80 => '#56F', 100 => '#BAF' ); foreach ($bgcols as $pc => $color) { if ($percent <= $pc) { $bg = $color; break; } } $fg = '#FFF'; } echo "<div style='width:100%; height:100px; text-align:center; border: 0; background-color:$bg; color:$fg; padding:0; margin: 0;'>"; printf ("Today, sunrise is %s, sunset is %s", date('g:ia', $todayInfo['sunrise']), date('g:ia', $todayInfo['sunset'])); echo "<br /> $percent%</div>"; ?> </body> </html> I've pieced together the code you've provided, edited it slightly which results in the following page http://sunlightgardenservices.co.uk/SkyTest2.php Has how I've pieced things together correct?
  3. Once again, thank you Barand. I really do need to research PHP more as although I understand what the above does and how to implement more colours, I do not know where this code goes exactly and how I use it to edit the colour, I understand that the above picks the colour, but not how it edits the css, presumably I do something like this? <?php //Your code here... <div class="bla" style="background: 'SOME CODE HERE?' ;"> </div> ?> My greater goal I now understand that I will need to learn a lot more about PHP to be able to do so, therefore I have set my standards lower to just do the sky with the moon and sun showing rotating across the screen and the sky colour changing. Best Regards, Tim
  4. Hiya Barand, I don't suppose you could further help a little as I'm not sure how to make something dynamic where it'll change without needing a page refresh, I gather it needs loads of if statements to check what percent then show the correct colour? I'll watch some PHP tutorials and figure out the the colours and whatnot in the meanwhile to hopefully hear back from you. Best Regards, Tim
  5. This code does not seem to change for the day, the times seem to stay the same although other websites state that the times change daily appropriately by 2 minutes?
  6. Hello, On a previous thread, thanks to Barand, I have something to say when the sunrise and sunset for an area will be based upon the longitude and latitude. I would like to make this unique for each user using GeoIP location. http://dev.maxmind.com/geoip/geolite I would like to start off by using the free version, however I do not know where to begin, I don't know which download I need for the co-ordinates and country/city and I do not know how to install it on the 1and1 myadmin PHP or echo anything onto the page. I know I've not said much, however I hardly know anything about this and don't even know where to begin as I can't find any tutorials or videos to help me get something set up. Best Regards, Tim
  7. Thank you Christian F. Does the moon cycle apply to the entire world so if it's a half moon for the UK, it's the same for USA, Australia and whatnot?
  8. That is just fantastic! Thank you so much! I don't want to go too far just yet, I need to get this working, I am just wondering if there is code for moon rise and set times and how much of the moon can be seen using the longitude and latitude as well? Best Regards, Tim
  9. Rises: 08:18 Sets: 18:26 Day length: 607 minutes Day elapsed: 446 minutes (73%) Bingo! I just phoned my service provider and they told me there's an option in my control panel to choose my PHP version.
  10. Version of PHP? I don't have a clue how to check that, all I know is that I am on the 1and1.co.uk business package. I'll try and find out.
  11. It won't allow me to edit my reply, I quoted the wrong message, I was meant to quote your last message, which is the following; Do you know why, when I added your code to a PHP page on my server it displayed errors but works for you?
  12. Wow, that just sounds really useful, I'm sorry I misunderstood. How does this work, I mean where is the information coming from exactly and is it possible to also do this for the sunset to sunrise too? Thank you so much for your help!
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Day and Night</title> </head> <body> <?php $info = date_sun_info(mktime(0,0,0), 53.3761, -2.1897); // Cheshire UK $rise = new datetime(date('Y-m-d H:i:s', $info['sunrise'])); $set = new datetime(date('Y-m-d H:i:s', $info['sunset'])); list($daylightHrs, $daylightMins) = explode(':', $set->diff($rise)->format('%h:%i')); list($elapsedHrs, $elapsedMins) = explode(':', $rise->diff(new DateTime())->format('%h:%i')); $daylight = $daylightHrs*60 + $daylightMins; $elapsed = $elapsedHrs*60 + $elapsedMins; $percent = $elapsed*100/$daylight; printf('Rises: %s<br>Sets: %s<br>Day length: %d minutes<br>Day elapsed: %d minutes (%d%%)', $rise->format('H:i'), $set->format('H:i'), $daylight, $elapsed, $percent ); ?> </body> </html> The following is on my page at http://sunlightgardenservices.co.uk/Dayandnight.php which doesn't seem to work?
  14. Okay, so I'm guessing from when the results were posted, 460 minutes (76%), this was the amount of time gone by since 00:00? I'm not sure how I can use this, if I were to have everything running to make things static such as when the sunrise and sunset times are, I could use this perfectly, however I am not sure if it can be done for what I have in mind where as, lets say there are 10 different colours for the night and day at all times, in the summer days are longer so these will just be a slower tween, however in the winter it will be much faster as the days are shorter, same goes for the nights. I would like the daytime colour tween to start at sunrise and end at sunset as for the nighttime colours to go from sunset to the next days sun rise. Maybe I can use this but don't understand how to? I don't understand any of the PHP code you have provided, I can work it out but what I mean is I don't think I yet know enough to modify anything you have provided without breaking it. I'll make a page on one of the domains I own and study the results. I also need to learn if there is a way I can find out a rough location of the user on the site to personalize it for them, their sunrise and sunset, possibly moving on to their weather and whatnot. Best Regards, Tim
  15. Day elapsed: 460 minutes (76%) What does this mean and thank you, I guess there is no need to set up a cron job and eventually I can learn to personalize this based upon the users location
  16. Thank you PaulRyan, I currently have a cron job running for something else, of which I have completely forgot how to do and I don't have a clue how my friend set up the xml/json page, however this sounds like a good starting point, I just need to figure out when the website updates and whatnot... I will also look into what you have mentioned Barand, thank you for your reply too! I know it's not usually the case, but I'm oping I can pick up the language fairly quick, however it is hard to read loads of documentation and debugging loads when you don't know a language due to being registered blind/severally-sighted and needing the windows magnifier on at least x500 magnified... In the past I've learnt via going into the deep end first, looking at code, I'm hoping this is not too big as it is something I've wanted to set up for a while now! I'll be checking back at this thread later on to check for any more replies or to update you of any progress as I've stupidly staying up for I think more than 24 hours now and I am really tired... Best Regards, Tim
  17. Hello, This is my first thread on <?php Freaks, however I am by no means a PHP Freak myself due to lack of experience in the field. I will start off by what I want to accomplish, my end goal, and then continue to my theory on how do achieve this. What I am trying to Achieve? I would like to achieve a website which dynamically changes my websites page so content such as the sky colour is shown differently, the moon is shown, the sun is shown and whatnot depending on the GMT. I believe if I can fetch the information of these times from a website so I know the sunrise and sunset, I can mathematically calculate the tween of sky colours and so on. My Theory on How It is Done. First of all, I would need to know how to store information on a fire on my server to improve loading times for the website, the calculations and events and whatnot, if the file already has so much data already calculated, there is no need to keep opening up a connection to an external website and doing all the mathematical calculations. From the likes of TimeAndDate.com, the information can be found on the sunrise and sunset in London, both of these times are in analogue and not digital, therefore their time in seconds needs to be calculated differently; Date Sunrise Sunset Feb 17, 2013 7:10 AM 5:19 PM The calculation in seconds past 00:00 for when the sunrise. var SunRise = (7*3600)+(10*60) The calculation in seconds past 00:00 for when the sunset. Var SunSet = (5*3600)+(19*60) - either take this figure away from 86400 (24 hours in seconds) or add on 43200 (12 hours in seconds) due to the times being in analogue. Now we have the very basic figures needed to make a, somewhat basic colour switch between day and night switch. If we take away the SunSet time from the SunRise time, we will know how long the DayTime period will be. This will be split up into so many values regardless of how much time is in between, longer days will just last longer on certain colours. I plan on doing it like this: Var DayTime = SunSet - SunRise Var DayColour01 = SunRise Var DayColour01 = SunRise + (DayTime/10) Var DayColour01 = SunRise + ((DayTime/10)*2) ...and so on giving us the time of day in seconds when the next colour change will happen if we were to spit it up into 10 segments. This would also allow for the time to be checked upon loading the website, to load the correct colour. The nighttime tween follows the same method with slight differences in calculations, still using the current days sunset time, but the following days sunrise time. I would also explain the theory, however I am unsure whether each one of these calculations would need to start from 0 seconds (the beginning of what seconds start from) or if it will be done by day, if it is done by day, I am not sure whether iff statements are able to be implemented into calculations, ie; if the total number of seconds is greater than 86400, the seconds in a day, 86400 would need to be taken away from the figure to be able to say when the next colour change will happen in the new day. This is the basic start I would like to accomplish, where I would like to continue this dynamic changing website depending on the GMT timezone to show the sun going across the time only starting to appear at the SunRise time and going completely out of view at the SunSet time, the same with the moon, however a little more advanced to show different images depending on how much of the moon is visible, and so on and so fourth. Although for someone to be able to program this for me would be brilliant, this is not always the case so I would just like to ask if you reply to this thread, if you could dumb things down a little for me as although I have little experiences in other programming languages, sometimes I just really cannot understand things until it's shown as a very basic level where at this point I feel stupid for not understanding it in the first place... Lastly, I thank you for reading such a big thread and for any help/and advice in your replies and your time spent in doing so, in advanced. Best Regards, Tim I do apologize for for formatting errors of this thread, I cannot seem to get the bb-codes to work correctly although everything was appearing fine before making this thread live for people to view.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.