My Little Prototype

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411


Hi guys

I just thought I'd share a prototype of my latest little coding project with you :) It basically utilises PHP to construct a cartoon-like image of the view from my window at home.

What's so special about that? Well, the image created is dynamic and thus changes appearance according to the data it is provided.

At present, the code behind the image retrieves real-time XML weather data for my locality and reflects this in the image it produces, so if it's snowing outside my window it will be snowing in the image.

The image also changes according to what time of day it is (sunrise, daytime, sunset or night time), and calculates the daylight hours from accurate sunrise and sunset times at my location. Finally, the image produced also reflects what season of the year it is (spring, summer, autumn or winter).

At present the whole thing is just a proof of concept, so the images are nothing like the final ones (especially the weather images which don't really represent the weather accurately). Also the seasons and a few other bits and bobs are missing at present. However, when it's all finished everything should function as follows:


Code:
[u]Sky[/u]

[i]Season[/i] - The hours of daylight are calculated from accurate sunrise and sunset times. (Implemented)
[i]Time of Day[/i] - The sky changes according to whether it is sunrise, daytime, sunset or night time. (Implemented)
[i]Weather[/i] - Accurate weather information changes the appearance of the sky (e.g. clouds, sunshine etc.). (Semi-Implemented)

[u]Trees[/u]

[i]Season[/i] - The trees change appearance with the season (e.g. colour and number of leaves etc.). (Unimplemented)
[i]Time of Day[/i] - The shadows cast by the trees elongate at sunrise and sunset. (Unimplemented)
[i]Weather[/i] - Trees sway when windy, get covered in snow etc. (Unimplemented)

[u]Road[/u]

[i]Time of Day[/i] - The street lights on the road glow amber and yellow at sunset and night time. (Implemented)
[i]Weather[/i] - uddles and snow appear in the road when raining or snowing. (Unimplemented)

[u]Fields[/u]

[i]Weather[/i] - Puddles and snow appear in the road when raining or snowing. (Unimplemented)

[u]River[/u]

[i]Weather[/i] - The river freezes over during in wintertime. (Unimplemented)

[u]Possibilities[/u]

I'd also like to try and accurately move the sun and moon across the sky and a few sheep and cows to boot too.
The script itself has been heavily optimised and only runs at set, albeit frequent, intervals - not everytime a user visits - thus reducing the load on the server and on the number of requests to the XML weather provider.

Well, that's about it :) Like I say, this is a prototype, so be gentle with me as there's still a lot more to do.

Kind Regards

Jonty

P.S. Although the coding, images etc. are mine, the original idea of using weather data is this way is not. I'll try and dig out the site if I can find it again, as it's truly spectacular.
 

wyrd_fish

Fledgling Freddie
Joined
Dec 27, 2003
Messages
537
thats cool....

is it GD, or is XML more complicated than i thought

PS: can you do layers in GD???
 

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411
Hi wyrd_fish

Yes, it just uses the standard image PHP libraries. Essentially the script just acquires the XML data, parses it for the bits it needs, calculates a few temporal variables, and then utilises PHP's image functions to compile a new image according to the data it receives.

Technically PHP can't handle layers in the way, say, PhotoShop or Paint Shop Pro can, but it does allow you to copy one image onto another and merge the two together (PHP also supports PNG's alpha transparency, which helps a lot). You could actually skip this stage and just create all the images offline and use the data to pick an image instead of making it, but the more variables there are the more possible images you would need (the image above will, for example, have hundreds of possible permutations).

Kind Regards
 

wyrd_fish

Fledgling Freddie
Joined
Dec 27, 2003
Messages
537
cool, so you have loads of pics
ie, trees in winter in 0%alpha and trees at other times etc...

then you merge the relavant ones???

are does it draw it

sorry, i being thick today...

PS i thought you quit BW???

PPS what functions do you use to merge the images...?
 

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411
Hello

Yes, lots of piccies :) At present there are backgrounds for each time of day (sunrise etc.) and then individual foreground pictures (trees etc.). Then the weather conditions (40-some in total) are separate again. In the end only a handful of images are required to compile an image (positioned and merged appropriately, as you say) so the strain on the server isn't too great.

PHP doesn't actually have to draw anything itself, just compile a new image from lots of exisiting ones. However, the image's I've made are all based around simple vector objects (circles, squares, lines etc.), so in theory PHP could draw some of the objects itself if needs be. However there's not much point, though, as it would end up being quite demanding the more complicated the scenes got.

And no, you're not being thick at all, so don't put yourself down!

Kind Regards

Jonty

P.S. I did leave BW, yes, but I came back when FH launched.
P.P.S. The images are merged with PHP's imagecopy().
 

Shovel

Part of the furniture
Joined
Dec 22, 2003
Messages
1,350
That is extremely flash Jonty :) This XML business does seem rather clever ;)

While the coding I can offer no advice on, I do have an aesthetic suggestion:

Although this would either take a long time to capture, or a lot of careful photoshopping, could you present the images using actual photographs of your bedroom view? Have a stock for different conditions (sunset etc) and have that generated? That may reduce the functionality though to being no more than an image selector.
 

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411
Hey Shovel

Thanks :) As for your suggestion, it had crossed my mind, but the problem with having so many variables is the number of images I'd have to capture. For weather conditions alone there are around 40-some distinct states, and although Yorkshire doesn't get many sandstorms [;)], that's still a lot of piccies.

What I'm thinking of doing, however, if taking your idea of photographing the landscape and then 'tracing' the objects into cell-shaded images. That way I have the flexibility of simple 'cartoons', but with the realism and scale of accurate photos.

Kind Regards
 

RandomBastard

Can't get enough of FH
Joined
Dec 28, 2003
Messages
1,318
Jonty said:
Hey Shovel

Thanks :) As for your suggestion, it had crossed my mind, but the problem with having so many variables is the number of images I'd have to capture. For weather conditions alone there are around 40-some distinct states, and although Yorkshire doesn't get many sandstorms [;)], that's still a lot of piccies.

What I'm thinking of doing, however, if taking your idea of photographing the landscape and then 'tracing' the objects into cell-shaded images. That way I have the flexibility of simple 'cartoons', but with the realism and scale of accurate photos.

Kind Regards
I live in yorkshire too, well s yorkshire :p
 

wyrd_fish

Fledgling Freddie
Joined
Dec 27, 2003
Messages
537
yo, Rb, Jonty, where you fellas at... i live near york (that too is in yorkshire...)
 

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411
I'm a West Yorkshire man, myself, near 'Last of the Summer Wine' country. York isn't too far away, though, lovely city :)

Kind Regards
 

Will

/bin/su
Staff member
Joined
Dec 17, 2003
Messages
5,259
That rocks Jonty. I'm really hoping you make it in a way that can be transferred to my homepage (working on a new version as we speak). :)
 

Stimpy

Fledgling Freddie
Joined
Dec 22, 2003
Messages
674
Very nice - good job you have a nice view out of your window you'd just see the houses opposite out of mine - don't think it would have the same kind of effect :)
 

SheepCow

Bringer of Code
Staff member
Moderator
Joined
Dec 22, 2003
Messages
1,365
Very nice, but where do you get the weather data from?
 

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411
Hi SheepCow

Weather.com offer free XML weather information and an SDK (registration required for both). Sadly it's US-orientated, but they do offer weather reports on a few major UK cities, which is what I'm utilising at the moment. The XML data basically details any exact location (longitude, latitude, sunrise, sunset etc.) and then includes the nearest weather report for the conditions and temperature etc.

The Met Office also provide XML weather data which is, naturally, UK-orientated (it powers the BBC-I's online weather service) but you have to pay, and there's a minimum £500 per annum fee.

Kind Regards
 

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411
fatbusinessman said:
Ummm...... OUCH?
hehe. In fairness to the Met Office their services are designed for businesses, and you can add additional cities for £20 each. But still, unless you've got plenty of cash to spare, it is a little excessive.

Kind Regards

Jonty

P.S. Did you know the Met-Office's weather calculations are powered in part by Cray super-computers? (modern day ones, naturally) :)
 

Stimpy

Fledgling Freddie
Joined
Dec 22, 2003
Messages
674
The sun takes a while to set by you doesn't it Jonty :)

edit: Ok it's changed I'll let you off ;)
 

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411
Stimpy said:
The sun takes a while to set by you doesn't it Jonty :)
hehe, it certainly does ;) I have to confess that sunrise and sunset are my favourite times of day, so they last for a disproportionately long 3 hours at the moment (the start time is accurate, though). I'll change this in subsequent builds :)

Kind Regards

Jonty

P.S. You should have seen sunrise this morning, there were two suns *oops* hehe :D
 

itcheh

Part of the furniture
Joined
Dec 23, 2003
Messages
740
Where's it gone? I enjoyed having a look at that every day ... and now it's gone ...bring it back Jonty!
 

Jonty

Fledgling Freddie
Joined
Dec 22, 2003
Messages
1,411
Hi itcheh

Sorry about that, broken link :) All fixed now.

Kind Regards
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom