how do i use or

i have - but i have NO idea how to use it, im code illiterate :frowning:

so i would LOVE to animate the sun moving, but if thats not possible or way outside my skills, then just rendering stills would be fine.

i need to be able to calculate by lat+long.

sorry if this has been answered already…

edit: heres a link to where i got the file:

and heres another one which i also dont understand:


Python is used extensively around www and doesn’t signify compatibility with blender. Just stick to the .py scripts available from Elysiun, you’ll probably get more help!

But if your insistant you should email Henrik Härkönen. The person who wrote it. [email protected]

Ummm…Henrik Härkönen <—hey! he’s from that movie…DUNE ! :stuck_out_tongue:

Usually you can tell if there blender compatible by loading the .py into wordpad. You should look for code like below, also usually you’ll find the key word “Blender”


Name: ‘BRayBaker 3.3’
Blender: 240
Group: ‘Wizards’
Tooltip: ‘Bake the skin of an object.’

import Blender
from Blender import Scene
from Blender.Scene import Render
from Blender.BGL import *
from Blender.Draw import *
from Blender import Object

So what are you trying to do with this script or what were you hoping to achieve?


ahhhh, ok, thanks. i only tried to use it cuz someone recommended it to me once for blender…but yeah i guess maybe its not for blender. it sure dosen seem like it is based on ur description…ummm…i guess all ask that dude like us suggested.

anyway - i want to be able to 3d model the suns position accurately based on location, time, date.

then i can place a lamp object on and make it track my building and generate precise (w/in reason) shadows for any time of day…maybe IP a path and animate shadow movement too.

…any other suggestions?

i did see this thread:

but that solution seems kinda clunky. i was hopin for something more efficient/error-proof.


#                                                 #
#            Calculating Sun position             #
#            by Grzegorz Rakoczy '2004            #
#                [email protected]               #
#                                                 #
#                                                 #
#       all calculation are based on page         #
#  #
#                by Paul Schlyter                 #
#                                                 #

#How to use this script?                                                 
#1. In top view create new Empty at you desired Sun rotating position
#2. Along X axis of Empty create lamp for Sun so far as you need
#3. Select the Sun, then the Empty, press Ctr-P to Parent the Sun to Empty
#4. If when you are rotating your Empty, then Sun should move.
#5. Change date, position, multiplier, empty_name and orientation below
#6. Run the script with Alt-P. Empty and Sun should rotate
#7. If you want to animate Sun link this script in script window to:
#   "Frame Changed"
#8. Thats all, enjoy!

import Blender
from Blender import *
from math import *
import os
import array

#write here start date
y = 2005
m = 12
day = 24
h = 10
mins = 25

#write here your position
lat = 52
long = 19

#how many minutes for one frame
multiplier = 5

#Name of your Empty object
empty_name = "Empty"

#scene orientation in degrees
orientation = 180

#and now some calculations

frame = float(Get('curframe')-1)

minsp = mins+frame*multiplier
daysp = float(minsp)/1440
h = float(h + mins/60 + minsp/60)

tpi = 2* pi
twopi = tpi
degs = 180 / pi
rads = pi / 180

#   Get the days to J2000
#   h is UT in decimal hours
#   FNday only works between 1901 to 2099 - see Meeus chapter 7
def FNday (y, m, d, h):
	days = 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d - 730531.5 + h / 24
	return float(days)

#   the function below returns the true integer part,
#   even for negative numbers
def FNipart(x):
	return int(sqrt(x*x))

#   the function below returns an angle in the range
#   0 to two pi
def FNrange(x):
    b = x / tpi
    a = tpi * (b - FNipart(b))
    if a &lt; 0:  
			a = tpi + a
    return a

#   Find the ecliptic longitude of the Sun
def FNsun(d):
	L = FNrange(280.461 * rads + 0.9856474 * rads * d)  #   mean longitude of the Sun
	g = FNrange(357.528 * rads + 0.9856003 * rads * d)  #   mean anomaly of the Sun
	return FNrange(L + 1.915 * rads * sin(g) + 0.02 * rads * sin(2 * g))  #   Ecliptic longitude of the Sun

def rev(x):
	rv = x - int(x/360)*360
	if rv &lt;0:
		rv = rv + 360
	return rv

d = FNday(y, m, day, h)

w = 282.9404 + 4.70935E-5 * d
a = 1.000000
e = 0.016709 - 1.151E-9 * d 
M = 356.0470 + 0.9856002585 * d
M = rev(M)

oblecl = 23.4393 - 3.563E-7 * d
L = rev(w + M)

E = M + degs * e * sin(M*rads) * (1 + e * cos(M*rads))

x = cos(E*rads) - e
y = sin(E*rads) * sqrt(1 - e*e)
r = sqrt(x*x + y*y)
v = atan2( y, x ) *degs
lon = rev(v + w)

xequat = r * cos(lon*rads) 
yequat = r * sin(lon*rads) * cos(oblecl*rads)
zequat = r * sin(lon*rads) * sin(oblecl*rads) 

RA = atan2(yequat, xequat)*degs / 15
Decl = asin(zequat / r) * degs

GMST0 = (L*rads + 180*rads) / 15 * degs
SIDTIME = GMST0 + h + long/15
HA = rev((SIDTIME - RA))*15

x = cos(HA*rads) * cos(Decl*rads)
y = sin(HA*rads) * cos(Decl*rads)
z = sin(Decl*rads)

xhor = x * sin(lat*rads) - z * cos(lat*rads)
yhor = y
zhor = x * cos(lat*rads) + z * sin(lat*rads)

azimuth = atan2(yhor, xhor)*degs + 180
altitude = atan2(zhor, sqrt(xhor*xhor+yhor*yhor))*degs

empty = Blender.Object.Get(empty_name)

x = 90
y = 90
z = 0

ax = azimuth/degs
az = altitude/degs

empty.RotZ = -ax+orientation
empty.RotY = -az 

actualh = h % 24

print "azimuth= ", azimuth 
print "altitude= ", altitude 
print "actualh   = ",actualh
print "d         = ",d
print " "

This script seems to work.

Maybe some Python Genius out there who wants to make a little interface for this?

I wonder if this script could be adapted to the game engine, that way realistic -real-time- lighting could be created for a scene?



Look I don’t mean too nosey. :o … though, what are you designing, is it some sort of architectural shadows study or just because you can/want to or…

Just recently my wife & I attended a 6-week straw bale house-building course.
And a substantial part was sustainability & energy efficiency theory/design. Now in Australia were required to supply Energy Efficiency Certificate that include detailed; shadow, light/heat, airflow, seasonal sun position drawings.


softork: SWWEEEETTT!!! thanks man…i wish i was a python genius :frowning: oh well, i get to work on this soon and maybe post some feedback or something

dlomas: no prob, being nosy is good…

im an architect and big coincidence my focus is on passive/solar/“green” architecture - im working on a project right now in venezuela that is a completely cross-ventilated assembly hall - and im trying to use blender for what i used to do in 3dmax and the other ‘big boys’ do u know? (im doing shadow studies on the building in addition to other stuff…two critical books to have for this kind of design/work:

“sun, wind and light”
“the technology of ecological building”

  • with those two books u can intuitively calculate any numbers u need to compare to what could be done with “active” heating and cooling.

so how was the course? did they give u info on wind? this venezuela project is my first project solely using wind to passively cool a very large space in a hot basically humid location (i normally do small projects in los angeles)

strawww bale - yeah man, big ups to you aussie’s u guys really push environmentally responsible design (architect glen murcott). staw bale is good stuff, i recently codesigned a project combining strawbale and rammed earth (see architect rick joy’s work) ar u familiar with samuel mockbee, his work is quite inspirational in the reuse of rejected and unusual materials? so did u have any questions on stuff in general?..

dlomas: hey he emailed me back, here’s what he says:

Hi Ray!

Sorry, the module is mostly intended as a library for other programs,
it is not so useful as itself to a user. But making such a program that
uses it shouldn’t be too difficult.

The only application which I know uses, is Miguel Tremblay’s web

which produces pretty graphs on sunrise/sunset information. I just wish
I had more free time, to make something really useful with that too. :slight_smile:


…maybe that graphing program could be useful to you.

i pointed him to the thread and whattaya know:

Interesting, I’m a ‘blenderhead’ myself also, though haven’t had time
do anything in a loong time, I just keep drooling at the amazing
features people keep coding in… :slight_smile:

But anyway, if I correctly understood your intentions, I believe
can help you in your quest, especially because Miguel added solar
altitude functionality to the library. The sun-object should work ok
with blender, someone just has to write somekind of interface for it to
move the objects (light) according to date etc.

The elysiun forum seemed to have already some sort of code for that,
most likely that can be ok also, you propably don’t need the
calculations which resolve the sun’s rise and set times, plus different
forms of twilight (unless you want to take that specially into account
in your renderings).

Maybe some day someone will make a celestial body simulator for
that would be cool. :slight_smile:




Well I have intentions of erecting a Portal Frame Steel Shed… I’m not sure if you know about these, anyway just about every second house in Australia has one. So I have had the shed suppliers engineer design a 200sqm freestanding gable carport, once it’s erected I will straw bale infill the walls and I’ll use recycled door & windows etc.

so how was the course? did they give u info on wind? t

Well, the wall building techniques are very different to the “norm”
I’ve been an alternative building fanatic for 20years; I guess my attraction is difficult to explain without these words; natural, hands-on, machine less, gratifying, imperfect, low impact, harmonious, achievable, sustainable.
I recently I brought rural land, I had a choice of 19 blocks, so I brought one half way up a ridge, on east N.E facing slope away form the extremely hot 14hr western sun & protected from the relentless freezing west S.W winter wind. Also in our location we only have 10hrs of direct sun with cool breezes…hehehe

Oh… Now in Australia “Communal Living” is the way of the future, there fully integrated communities i.e. the have there own private collages, shopping centres, medical surgery, parks, sporting facilities, bike paths, veterinarians blah blah etc.
One of these developers “DELFIN” is a huge Australia wide company.
So the point I’m making is they have also allowed some people to build straw bale houses, though with a very strict developer / council building covenant.
The main point I’m making is the authorities are “NOW” acknowledging/allowing renewable sustainable building practices / materials in our “Suburbs”, where as before this was frowned upon event in far away “hippy” type communities. Defin link below

and im trying to use blender for what i used to do in 3dmax and the other ‘big boys’ do u know?

I used Sketchup to do my house plans, shadow designs etc, are you familiar with it? Its simplicity and accuracy is unbeatable with its real-time shadowing abilities.

I get architectural inspirations from here
But I don’t know of those peoples you referred to in your post though.


fascinating - i like that push/pull website alot. im only mildly familiar with sketchup. all my modeling has been confined to rhino, autocad and max…all at different times. im kinda enamoured with blender for now and thats why im tryin to force into submission - i really really like the concepts of sketchup though, and many friends/colleagues swear by it for some time now.

ill have to see what the future holds for me as far as more 3d apps go. sounds like uve got a good handle on stuff, i hope it won’t be long before los angeles building officials follow suit with australia, canada and other enlightened urban/suburban building policy makers.

u might find this guy interesting as well “nader khalili” (i think i got Khalili right)…

happy blending and building dude. pm me anytime.

there’s something I don’t understand in the sun-D script :


minsp = <b>mins</b>+frame*multiplier

add an offset in minutes to the given mins value. ok.

then daysp is computed. (not used in the calculation) gives the number of days added to the given day. ok.

then the given hour + the hour offset is computed :

h = float(h +<b> mins/60 </b>+ minsp/60)

which is like :

h = float(h +<b> mins/60 </b>+ (<b>mins</b>+frame*multiplier)/60)

(used for calculation)
mins is added twice to the hour calculation ? isn’t it odd ? I would have write :

h = float(h + minsp/60)

what do you think ?

I’m currently adapting this script for the game engine, and it works fine now. BUT I’m wondering if there’s not an error somewhere.

I added some code to display the current min and hour during the game :
here is a diff for the alt+a frame link version :

<i>line 232 replace :</i>
hr =GUIdata[5].val
<i>by :</i>
hour =GUIdata[5].val

<i>line 245 replace :</i>
hr = -long/15 + hr
<i>by :</i>
hr = -long/15 + hour

<i>line 256 insert :</i>
print int(hour+minsp/60)%24,':',minsp%60

I suppose this is correct after some tests.
unfortunately the sunrise and sunset times does not correspond to the reality, it seems there’s a rotation offset… I don’t think it’s about altitude. maybe I missed something, I’m not mathematician :confused: … ?
has someone compare reality ans script resuslts for his location ?