[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] lighting challenge



(apologies if you get this twice, not sure what happened with my first email with attachment)

Hello

I have been playing around with lighting lately. Last pyweek I
implemented a simple lighting, but it was not perfect (its the algorithm
1, see download link below). Therefor I have been experimenting a bit since then.
The result is what you got in the download link. Its a little script that
allows to draw the same scene in different ways. Each region has a
different implementation (see draw1(...) to draw9(...) methods in the
code). The last 3 are not implemented so you can implement your
algorithm and experiment with it.  My idea is to find what looks good
and is somewhat speedy to draw. Maybe there is a faster way by cheating
some (computer graphics is all about that, right?). Ok, I know, with
openGL this would be done with shaders and would look much better, but
is also a bit more complicated and would use 3d models....
And I love pygame. Therefore I'm doing this in pygame using surfaces and
its blit modes.


About the little scene:

Its a top down view on a street. On the street there is a tomato which
is illuminated by a flash light (about same level, in the implementation
the flash light is one layer above the tomato). There is also a tree
that covers the tomato and the flash light. It is a small tree because
the street light shines on it (and also on the tomato and street). And
there is also a bird flying over the streetlight (it should not be
illuminated). So summing up we have following layers:

bird
street light
tree
flashlight
tomato
street


The controls:

Tab:         show help
F1-F9:     show/hide regions with the different algorithms
1-9:         select a single object (street, tomato, flashlight, tree,
...) to move around with arrow keys
arrow keys:    move objects around
a:            ambient color, use up/down arrow to change (make 'day' and
'night')
space:    toggle object highlight
r:             reset scene
escape:  quit

Hopefully you feel interested and experiment some with it.

Enjoy.

Thanks.

~DR0ID

 Download link: https://bitbucket.org/dr0id/pyknic/downloads/2015-07-02-lighting.zip