﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Extensions%3A2.4%2FPy%2FScripts%2FTemp%2FSun_py</id>
	<title>Extensions:2.4/Py/Scripts/Temp/Sun py - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Extensions%3A2.4%2FPy%2FScripts%2FTemp%2FSun_py"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Extensions:2.4/Py/Scripts/Temp/Sun_py&amp;action=history"/>
	<updated>2026-04-30T07:45:38Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Extensions:2.4/Py/Scripts/Temp/Sun_py&amp;diff=51706&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Extensions:2.4/Py/Scripts/Temp/Sun_py&amp;diff=51706&amp;oldid=prev"/>
		<updated>2018-06-28T17:49:54Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 17:49時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Extensions:2.4/Py/Scripts/Temp/Sun_py&amp;diff=51705&amp;oldid=prev</id>
		<title>wiki&gt;Mindrones: moved Extensions:2.4/Py/Scripts/temp/Sun py to Extensions:2.4/Py/Scripts/Temp/Sun py</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Extensions:2.4/Py/Scripts/Temp/Sun_py&amp;diff=51705&amp;oldid=prev"/>
		<updated>2010-10-02T08:57:22Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/Extensions:2.4/Py/Scripts/temp/Sun_py&quot; class=&quot;mw-redirect&quot; title=&quot;Extensions:2.4/Py/Scripts/temp/Sun py&quot;&gt;Extensions:2.4/Py/Scripts/temp/Sun py&lt;/a&gt; to &lt;a href=&quot;/Extensions:2.4/Py/Scripts/Temp/Sun_py&quot; title=&quot;Extensions:2.4/Py/Scripts/Temp/Sun py&quot;&gt;Extensions:2.4/Py/Scripts/Temp/Sun py&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;These two bits of code will allow for an animated sun that can be set to a certain time and date for realistic estimations for shadow/light studies. Both scripts are not necessary, but it is recommended that the GUI is used since it will save default values for use with specific blend files. If not, then the current values used will not be saved or if modified will be the same values for all blend files that use it.&lt;br /&gt;
&lt;br /&gt;
you will need to copy and paste each script into a text editor and save into the blender script directory with the name exactly as it is written as the title of each script. After one updates menus in the script window you will find the script and the GUI under Animation with the names: &amp;quot;sun__py&amp;quot; and &amp;quot;sun__py GUI&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=sun_gui-D.py=&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!BPY&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Name: 'sun__py GUI'&lt;br /&gt;
Blender: 242&lt;br /&gt;
Group: 'Animation'&lt;br /&gt;
Tooltip: 'calculated sun path for specific locales and times'&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# sun__py GUI&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# ***** BEGIN GPL LICENSE BLOCK *****&lt;br /&gt;
#&lt;br /&gt;
# Copyright (C) 2006 Patrick7&lt;br /&gt;
#&lt;br /&gt;
# This program is free software; you can redistribute it and/or&lt;br /&gt;
# modify it under the terms of the GNU General Public License&lt;br /&gt;
# as published by the Free Software Foundation; either version 2&lt;br /&gt;
# of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program; if not, write to the Free Software Foundation,&lt;br /&gt;
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.&lt;br /&gt;
#&lt;br /&gt;
# ***** END GPL LICENCE BLOCK *****&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
__author__ = &amp;quot;Patrick7&amp;quot;&lt;br /&gt;
__url__ = (&amp;quot;blender&amp;quot;, &amp;quot;elysiun&amp;quot;)&lt;br /&gt;
__version__ = &amp;quot;D&amp;quot;&lt;br /&gt;
__bpydoc__ = &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Description: GUI for the script that calculates the sun position based on user input data.&lt;br /&gt;
Usage: follow the onscreen GUI instuctions as far as setup of objects and your scene or see corresponding usage instructions below.&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
####################################################&lt;br /&gt;
# sun__py&lt;br /&gt;
#&lt;br /&gt;
# BACKGROUND&lt;br /&gt;
####################################################&lt;br /&gt;
'''&lt;br /&gt;
20060829&lt;br /&gt;
Most of the actual script that runs this comes from&lt;br /&gt;
a script found here:&lt;br /&gt;
	http://blenderartists.org/forum/showthread.php?s=604b30a11e14814c3ec800527ddaa699&amp;amp;t=59884&amp;amp;highlight=sun.py&lt;br /&gt;
that orginal script had the following header:&lt;br /&gt;
###################################################&lt;br /&gt;
#                                                 #&lt;br /&gt;
#            Calculating Sun position             #&lt;br /&gt;
#            by Grzegorz Rakoczy '2004            #&lt;br /&gt;
#                grzybu@obywatel.pl               #&lt;br /&gt;
#                                                 #&lt;br /&gt;
###################################################&lt;br /&gt;
#                                                 #&lt;br /&gt;
#       all calculation are based on page         #&lt;br /&gt;
#  http://www.stjarnhimlen.se/comp/tutorial.html  #&lt;br /&gt;
#                by Paul Schlyter                 #&lt;br /&gt;
#                                                 #&lt;br /&gt;
################################################### &lt;br /&gt;
&lt;br /&gt;
called aptly &amp;quot;sun.py&amp;quot;.. I was working on a script &lt;br /&gt;
like this when I found there was already one available&lt;br /&gt;
I checked the data it out put and compared it to  a &lt;br /&gt;
couple of sources and found this script to actually&lt;br /&gt;
be rather accurate (eg wihin about 1% of NOAA&lt;br /&gt;
http://www.srrb.noaa.gov/&lt;br /&gt;
&lt;br /&gt;
so I (patrick7) have simply addded a GUI and &lt;br /&gt;
system for saving data while cleaning up some minor&lt;br /&gt;
bugs and orientation issues as I saw them.&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# CODE HISTORY&lt;br /&gt;
####################################################&lt;br /&gt;
'''&lt;br /&gt;
version - date - descriptions&lt;br /&gt;
sun_gui-pa1a/b - 060828 - misc building off off original&lt;br /&gt;
test-fileioandarrays-pa1 - 060828 - new start&lt;br /&gt;
	pa2 - 060828 - ??&lt;br /&gt;
	pa3 - 060828 - somewhat functional&lt;br /&gt;
	pa4 - 060828 - gibberish trying different things&lt;br /&gt;
	pa5 - 060828 - read and gui set works!!&lt;br /&gt;
	pa6 - 060828 - working through final details &amp;amp; clean up&lt;br /&gt;
sun_gui-pc1 -060829- first functional gui with script&lt;br /&gt;
sun_gui-C - 060829 - almost release&lt;br /&gt;
sun_gui-0C - 060830 - fixed globals &lt;br /&gt;
sun_gui-D -060903 - fixed crash problem and added web link&lt;br /&gt;
&lt;br /&gt;
## REFERENCE DEFINITIONS&lt;br /&gt;
0	long&lt;br /&gt;
1	lat&lt;br /&gt;
2	year&lt;br /&gt;
3	month&lt;br /&gt;
4	day&lt;br /&gt;
5	hour&lt;br /&gt;
6	minute&lt;br /&gt;
7	orientation&lt;br /&gt;
8	multiplier&lt;br /&gt;
9 empty name&lt;br /&gt;
'''&lt;br /&gt;
####################################################&lt;br /&gt;
# OPEN ISSUES&lt;br /&gt;
####################################################&lt;br /&gt;
'''&lt;br /&gt;
0. allow for setting multiple days after a period so&lt;br /&gt;
that the highest lowest and middle light periods could&lt;br /&gt;
be studied easily&lt;br /&gt;
2. allow for multiple objects which requires&lt;br /&gt;
	2a. a file per object .. filename needs to be a &lt;br /&gt;
	function to allow for the data to be read correctly&lt;br /&gt;
3. script creates a new datablock instance of the script&lt;br /&gt;
for each object (&amp;gt;1 or if already loaded) at the time the &lt;br /&gt;
script is run &lt;br /&gt;
'''&lt;br /&gt;
####################################################&lt;br /&gt;
# USAGE&lt;br /&gt;
####################################################&lt;br /&gt;
'''&lt;br /&gt;
000. Place the gui &amp;amp; script (sun_gui.py and sun.py)&lt;br /&gt;
	into your scripts directory&lt;br /&gt;
00. Open the GUI script in your script window or open it &lt;br /&gt;
in your text window and hit ALT + P&lt;br /&gt;
----------------------------------------------------&lt;br /&gt;
0. Scene is oriented by top view [num7], North is&lt;br /&gt;
	up (+y), East is right (+x), if this default is&lt;br /&gt;
	changed, then those used may not be the same.&lt;br /&gt;
	NOTE: IF THE DEFAULT VALUES ARE CHANGED THIS &lt;br /&gt;
	APPLICATION SAVES A FILE (*.dat) IN THE DIRECTORY &lt;br /&gt;
	YOU ARE WORKING&lt;br /&gt;
1.In Top view, create a new Empty at the desired&lt;br /&gt;
  sun rotation pivot position	&lt;br /&gt;
2.Along X-axis of Empty create lamp for Sun,&lt;br /&gt;
  position it so far out as needed&lt;br /&gt;
3.Select the sun then Empty and parent [ctrl-P],	&lt;br /&gt;
4.Change location, time, etc definitions as needed	&lt;br /&gt;
5. {Run} runs the script, linking it to the empty if&lt;br /&gt;
			script links are enabled.&lt;br /&gt;
	{reset} resets default position, clears link&lt;br /&gt;
	{rall} as reset plus it deletes the file&lt;br /&gt;
	{exit}/[Qkey]/[ESCKEY] quits gui application&lt;br /&gt;
'''&lt;br /&gt;
####################################################&lt;br /&gt;
# THE INCLUDES&lt;br /&gt;
####################################################&lt;br /&gt;
import Blender, webbrowser&lt;br /&gt;
from Blender.BGL import *&lt;br /&gt;
from Blender.Draw import *&lt;br /&gt;
from Blender import *&lt;br /&gt;
import math&lt;br /&gt;
from math import *&lt;br /&gt;
import os&lt;br /&gt;
import array&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# THE INITIALIZATION OF THE Graphical User Interface&lt;br /&gt;
####################################################&lt;br /&gt;
DFLTdata= {&lt;br /&gt;
	0: 89.600,	#long&lt;br /&gt;
	1: 27.483 ,	#lat&lt;br /&gt;
	2: 2006,		#yea&lt;br /&gt;
	3: 1,				#month&lt;br /&gt;
	4: 1,				#day&lt;br /&gt;
	5: 0,				#hour&lt;br /&gt;
	6: 0.00,		#minute&lt;br /&gt;
	7: 0.00,		#orientation&lt;br /&gt;
	8: 20.00,		#multiplier&lt;br /&gt;
	9: 'Empty'	#empty name&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
n=len(DFLTdata)-1&lt;br /&gt;
&lt;br /&gt;
## Set button variables (settings in the gui)&lt;br /&gt;
GUIdata = {&lt;br /&gt;
	0:Draw.Create(DFLTdata[0]),&lt;br /&gt;
	1:Draw.Create(DFLTdata[1]),&lt;br /&gt;
	2:Draw.Create(DFLTdata[2]),&lt;br /&gt;
	3:Draw.Create(DFLTdata[3]),&lt;br /&gt;
	4:Draw.Create(DFLTdata[4]),&lt;br /&gt;
	5:Draw.Create(DFLTdata[5]),&lt;br /&gt;
	6:Draw.Create(DFLTdata[6]),&lt;br /&gt;
	7:Draw.Create(DFLTdata[7]),&lt;br /&gt;
	8:Draw.Create(DFLTdata[8]),&lt;br /&gt;
	9:Draw.Create(DFLTdata[9])&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
scriptname = &amp;quot;sun__py&amp;quot;&lt;br /&gt;
actualScriptName = &amp;quot;sun-D.py&amp;quot;&lt;br /&gt;
FILE = None&lt;br /&gt;
fileblend = Blender.Get(&amp;quot;filename&amp;quot;)&lt;br /&gt;
filename = fileblend[:fileblend.rfind(&amp;quot;.&amp;quot;)] + &amp;quot;_blend-&amp;quot; + scriptname + &amp;quot;-control_data-DO_NOT_DELETE&amp;quot;+&amp;quot;.dat&amp;quot;&lt;br /&gt;
FILEdata = {}&lt;br /&gt;
txt =1 #number of text items&lt;br /&gt;
website = &amp;quot;&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
def opensite(website):&lt;br /&gt;
	webbrowser.open(website)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# FILE I/O&lt;br /&gt;
####################################################&lt;br /&gt;
## FILEOPEN&lt;br /&gt;
def fileopen():&lt;br /&gt;
	global scriptname, filename&lt;br /&gt;
	#print scriptname,&amp;quot;:FILEOPEN&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	try:&lt;br /&gt;
		FILE = open(filename, &amp;quot;r&amp;quot;)&lt;br /&gt;
		print scriptname,&amp;quot;:previous data found&amp;quot;&lt;br /&gt;
		read(FILE)&lt;br /&gt;
	except IOError:&lt;br /&gt;
		print scriptname,&amp;quot;no previous data found:&amp;quot;,filename&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
## READ	- functions, first item is a text item.&lt;br /&gt;
def read(FILE):&lt;br /&gt;
	global scriptname, GUIdata, FILEdata, n, txt&lt;br /&gt;
	i=0	&lt;br /&gt;
	#FILE=open(filename,&amp;quot;r&amp;quot;)&lt;br /&gt;
	while i&amp;lt;=n:&lt;br /&gt;
			x = FILE.readline()&lt;br /&gt;
			if i&amp;lt;=n-txt: &lt;br /&gt;
					FILEdata[i] = float(x)&lt;br /&gt;
			else: &lt;br /&gt;
				x.strip('\n')&lt;br /&gt;
				#FILEdata[i]=str(x)&lt;br /&gt;
				FILEdata[i]=eval(x)&lt;br /&gt;
			GUIdata[i].val = FILEdata[i]&lt;br /&gt;
			i=i+1&lt;br /&gt;
			startup=1&lt;br /&gt;
	FILE.close()&lt;br /&gt;
	print scriptname,&amp;quot;:DATA READ&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
## WRITE&lt;br /&gt;
def write(warray):&lt;br /&gt;
	global scriptname, filename, n&lt;br /&gt;
	try:&lt;br /&gt;
		FILE = open(filename,&amp;quot;w&amp;quot;)&lt;br /&gt;
	except IOError:&lt;br /&gt;
		print scriptname,&amp;quot;:IOERROR&amp;quot;&lt;br /&gt;
	i=0&lt;br /&gt;
	while i&amp;lt;=n:&lt;br /&gt;
		FILE.write(str(warray[i])+'\n')&lt;br /&gt;
		i=i+1	&lt;br /&gt;
	FILE.close()&lt;br /&gt;
	print scriptname,&amp;quot;:WROTE DATA TO:&amp;quot;,filename&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
####################################################&lt;br /&gt;
# THE RESET&lt;br /&gt;
####################################################&lt;br /&gt;
def reset():&lt;br /&gt;
	global filename, GUIdata&lt;br /&gt;
	empty = Blender.Object.Get(GUIdata[9].val)&lt;br /&gt;
	empty.clearScriptLinks()&lt;br /&gt;
	empty.RotZ = 0&lt;br /&gt;
	empty.RotY = 0&lt;br /&gt;
	FILE = open(filename, &amp;quot;r&amp;quot;)&lt;br /&gt;
	FILE.close()&lt;br /&gt;
	#Exit()&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
def resetevenvalues():&lt;br /&gt;
	global scriptname, filename, GUIdata&lt;br /&gt;
	empty = Blender.Object.Get(GUIdata[9].val)&lt;br /&gt;
	empty.clearScriptLinks()&lt;br /&gt;
	empty.RotZ = 0&lt;br /&gt;
	empty.RotY = 0&lt;br /&gt;
	try:&lt;br /&gt;
		FILE = open(filename, &amp;quot;r&amp;quot;)&lt;br /&gt;
		FILE.close()&lt;br /&gt;
		os.remove(filename)&lt;br /&gt;
	except os.error:&lt;br /&gt;
		print scriptname,&amp;quot;:FILE NOT DELETED&amp;quot;&lt;br /&gt;
	#Exit()&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
####################################################&lt;br /&gt;
# script_apply&lt;br /&gt;
####################################################&lt;br /&gt;
# script shamelessly clipped from Mariano Hidalgo's :&lt;br /&gt;
# http://uselessdreamer.byethost32.com/scripts/object_jitter.py&lt;br /&gt;
# then HACKED!&lt;br /&gt;
&lt;br /&gt;
def script_apply(ascriptName,objct):&lt;br /&gt;
	#global actualScriptName&lt;br /&gt;
	&lt;br /&gt;
	try:&lt;br /&gt;
		print scriptname, &amp;quot;trying to Text.unlink&amp;quot;&lt;br /&gt;
		Blender.Text.unlink(&amp;quot;sun-D.py&amp;quot;)&lt;br /&gt;
		print scriptname, &amp;quot;try succeded&amp;quot;&lt;br /&gt;
	except:	&lt;br /&gt;
		pass	&lt;br /&gt;
	try:&lt;br /&gt;
		Blender.Text.Load(Blender.Get(&amp;quot;scriptsdir&amp;quot;) + os.sep + ascriptName)&lt;br /&gt;
	except:	&lt;br /&gt;
		Blender.Text.Load(Blender.Get(&amp;quot;uscriptsdir&amp;quot;) + os.sep + ascriptName)&lt;br /&gt;
	&lt;br /&gt;
	ob = Blender.Object.Get(objct) #$Object.GetSelected()&lt;br /&gt;
	try:&lt;br /&gt;
		ob.clearScriptLinks()&lt;br /&gt;
&lt;br /&gt;
	except:&lt;br /&gt;
		print scriptname, &amp;quot;:Nothing to remove&amp;quot;&lt;br /&gt;
	ob.addScriptLink(ascriptName, 'FrameChanged')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# RUN&lt;br /&gt;
####################################################&lt;br /&gt;
def runit ():&lt;br /&gt;
	global scriptname, GUIdata&lt;br /&gt;
	&lt;br /&gt;
	print scriptname,&amp;quot;:RUN&amp;quot;&lt;br /&gt;
	write(GUIdata)&lt;br /&gt;
	script_apply(actualScriptName, GUIdata[9].val)&lt;br /&gt;
	&lt;br /&gt;
		&lt;br /&gt;
####################################################&lt;br /&gt;
# THE START SEQUENCE&lt;br /&gt;
####################################################&lt;br /&gt;
print filename&lt;br /&gt;
fileopen()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# THE Graphical User Interface&lt;br /&gt;
####################################################&lt;br /&gt;
def gui():&lt;br /&gt;
	global Button11, Button12, Button13, Button14, GUIdata&lt;br /&gt;
	&lt;br /&gt;
	glClearColor(0.753, 0.753, 0.753, 0.0)&lt;br /&gt;
	glClear(GL_COLOR_BUFFER_BIT)&lt;br /&gt;
	glColor3f(0.533, 0.533, 0.533)&lt;br /&gt;
	glRecti(0, 1, 230, 475)&lt;br /&gt;
	glColor3f(0.400, 0.400, 0.400)&lt;br /&gt;
	glRecti(88, 116, 227, 180) #note rectangle&lt;br /&gt;
	glRecti(145, 85, 175, 125)&lt;br /&gt;
	glRecti(0, 47, 229, 0)&lt;br /&gt;
	glColor3f(0.000, 0.000, 0.000)&lt;br /&gt;
	glRecti(0, 102, 229, 100) #blender fixes&lt;br /&gt;
	glRecti(0, 195, 229, 193) #time definition&lt;br /&gt;
	glRecti(0, 255, 229, 253) #location definition&lt;br /&gt;
	glRecti(0, 445, 229, 443)&lt;br /&gt;
	glColor3f(0.000, 0.000, 1.000)&lt;br /&gt;
	glRecti(0, 461, 229, 459)&lt;br /&gt;
	#glRecti(25, 405, 224, 405)	&lt;br /&gt;
&lt;br /&gt;
	glColor3f(0.000, 0.000, 1.000)&lt;br /&gt;
	glRasterPos2i(2, 465)&lt;br /&gt;
	Draw.Text('Sun.py v:D (c) 20060903','large')&lt;br /&gt;
	glColor3f(0.000, 0.000, 0.000)&lt;br /&gt;
	glRasterPos2i(100, 165)&lt;br /&gt;
	Draw.Text('NOTE:    changing these','small')&lt;br /&gt;
	glRasterPos2i(102, 155)&lt;br /&gt;
	Draw.Text('values from zero (0) may','small')&lt;br /&gt;
	glRasterPos2i(102, 145)&lt;br /&gt;
	Draw.Text('effect the Orientation','small')&lt;br /&gt;
	glRasterPos2i(2, 104)&lt;br /&gt;
	Draw.Text('Blender Fixes')&lt;br /&gt;
	glRasterPos2i(2, 198)&lt;br /&gt;
	Draw.Text('Time Definition')&lt;br /&gt;
	glColor3f(0.251, 0.000, 0.251)&lt;br /&gt;
	glRasterPos2i(2, 446)&lt;br /&gt;
	Draw.Text('USAGE:')&lt;br /&gt;
	glRasterPos2i(2, 435)&lt;br /&gt;
	Draw.Text('0.Scene is oriented by top view [num7], North is','small')&lt;br /&gt;
	glRasterPos2i(2, 425)	&lt;br /&gt;
	Draw.Text('	up (+y), East is right (+x), if this default is','small')&lt;br /&gt;
	glRasterPos2i(2, 415)&lt;br /&gt;
	Draw.Text('	changed, then those used may not be the same','small')&lt;br /&gt;
	glRasterPos2i(2, 405)	&lt;br /&gt;
	Draw.Text('	NOTE: IF THE DEFAULT VALUES ARE ','small')&lt;br /&gt;
	glRasterPos2i(2, 395)&lt;br /&gt;
	Draw.Text('	CHANGED THIS APP SAVES A FILE (*.dat)','small')&lt;br /&gt;
	glRasterPos2i(2, 385)&lt;br /&gt;
	Draw.Text('	 IN THE WORKING DIRECTORY','small')	&lt;br /&gt;
	glRasterPos2i(2, 375)&lt;br /&gt;
	Draw.Text('1.In Top view, create a new Empty at the desired','small')&lt;br /&gt;
	glRasterPos2i(2, 365)&lt;br /&gt;
	Draw.Text('  sun rotation pivot position	','small')	&lt;br /&gt;
	glRasterPos2i(2, 355)&lt;br /&gt;
	Draw.Text('2.Along X-axis of Empty create lamp for Sun,','small')	&lt;br /&gt;
	glRasterPos2i(2, 345)&lt;br /&gt;
	Draw.Text('  position it so far out as needed','small')	&lt;br /&gt;
	glRasterPos2i(2, 335)&lt;br /&gt;
	Draw.Text('3.Select the sun then Empty and parent [ctrl-P]','small')	&lt;br /&gt;
	glRasterPos2i(2, 325)&lt;br /&gt;
	Draw.Text('4.Change location, time, etc definitions as needed','small')	&lt;br /&gt;
	glRasterPos2i(2, 315)&lt;br /&gt;
	Draw.Text('{Run} runs the script, linking it to the empty if','small')	&lt;br /&gt;
	glRasterPos2i(2, 305)&lt;br /&gt;
	Draw.Text('		script links are enabled.','small')	&lt;br /&gt;
	glRasterPos2i(2, 295)&lt;br /&gt;
	Draw.Text('  {reset} resets default position, clears link','small')			&lt;br /&gt;
	glRasterPos2i(2, 285)&lt;br /&gt;
	Draw.Text('  {rall} as reset plus it deletes the file','small')&lt;br /&gt;
	glRasterPos2i(2, 275)&lt;br /&gt;
	Draw.Text('	{exit}/[Qkey]/[ESCKEY] quits gui application','small')&lt;br /&gt;
&lt;br /&gt;
			&lt;br /&gt;
			&lt;br /&gt;
	glRasterPos2i(0, 258)&lt;br /&gt;
	Draw.Text('Location Definition')&lt;br /&gt;
&lt;br /&gt;
	Button('run',11,5,3,164,34, '')&lt;br /&gt;
	Button('reset',12,170,24,29,19,'reset positions and settings')&lt;br /&gt;
	Button('rstall',14,200,24,24,19,'reset positions settings AND DELETE default value file')&lt;br /&gt;
	Button('exit',13,170,3,54,19,'vamanos')&lt;br /&gt;
&lt;br /&gt;
	Button('www',15,5,210,34,19,'www look up latitude and longitude: http://www.heavens-above.com/countries.asp')&lt;br /&gt;
&lt;br /&gt;
	GUIdata[0] = Draw.Number('Longitude:', 0, 100, 206, 109, 19, GUIdata[0].val, -180, 180, 'Longitude [+180 to -180] (East is positive, zero(0) at the Greenwich Meridian')&lt;br /&gt;
	GUIdata[1] = Draw.Number('Latitude:', 1, 5, 231, 99, 19, GUIdata[1].val, -90, 90, 'Latitude [+90 to -90] (North is positive, Equator is zero(0)')&lt;br /&gt;
	GUIdata[2] = Number('Year:', 2, 5, 171, 79, 19, GUIdata[2].val, 1901, 2099, 'year [1901-2099]')		&lt;br /&gt;
	GUIdata[3] = Number('Month:', 3, 5, 146, 79, 19, GUIdata[3].val, 1, 12, 'month [1-12]')&lt;br /&gt;
	GUIdata[4] = Number('Day:', 4, 5, 121, 79, 19, GUIdata[4].val, 1, 31, 'day [1-31]')&lt;br /&gt;
	GUIdata[5] = Number('Hr:', 5, 92, 121, 64, 19, GUIdata[5].val, -23, 23, 'hour [0-23]')&lt;br /&gt;
	GUIdata[6] = Number('Mn:', 6, 159, 121, 64, 19, GUIdata[6].val, 0, 59, 'minute [0-59]')&lt;br /&gt;
	GUIdata[7] = Number('Orientation:', 7, 109, 78, 119, 19, GUIdata[7].val, -360, 360, 'orientation [-360 to 360] positive clockwise (topview [num7] N=+y East=+x at 0° orientation')&lt;br /&gt;
	GUIdata[8] = Number('Mn/Frame:', 8, 5, 78, 101, 19, GUIdata[8].val, 0, 1000, 'real life minutes per frame of animation (real time at 24fps is 0.000694) set to 0 for no movement')&lt;br /&gt;
&lt;br /&gt;
	GUIdata[9] = String('', 9, 5, 52, 109, 19, GUIdata[9].val, 399, 'name of the empty (case sensitive)')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# CHECK FOR THE ESCAPE KEY or Q (quit)&lt;br /&gt;
####################################################&lt;br /&gt;
def event(evt, val):&lt;br /&gt;
	if (evt== QKEY and not val): &lt;br /&gt;
		print scriptname,&amp;quot;:Exit&amp;quot;&lt;br /&gt;
		Exit()&lt;br /&gt;
	elif (evt==ESCKEY and not val): &lt;br /&gt;
		print scriptname,&amp;quot;:Exit&amp;quot;&lt;br /&gt;
		Exit()&lt;br /&gt;
	&lt;br /&gt;
####################################################&lt;br /&gt;
# ACTION AFTER THE BUTTON HAS BEEN PRESSED&lt;br /&gt;
####################################################	&lt;br /&gt;
def bevent(evt):&lt;br /&gt;
	if evt == 11: #run&lt;br /&gt;
		runit()&lt;br /&gt;
	elif evt == 12: #reset&lt;br /&gt;
		reset()&lt;br /&gt;
	elif evt == 13: #exit&lt;br /&gt;
		print scriptname,&amp;quot;:Exit&amp;quot;&lt;br /&gt;
		Exit()&lt;br /&gt;
	elif evt == 14: #reset even values&lt;br /&gt;
		resetevenvalues()		&lt;br /&gt;
	elif evt == 15: #reset even values&lt;br /&gt;
		opensite('http://www.heavens-above.com/countries.asp')&lt;br /&gt;
&lt;br /&gt;
	Blender.Redraw()&lt;br /&gt;
&lt;br /&gt;
Register(gui, event, bevent)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
=sun-D.py=&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!BPY&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Name: 'sun__py'&lt;br /&gt;
Blender: 242&lt;br /&gt;
Group: 'Animation'&lt;br /&gt;
Tooltip: 'calculated sun path for specific locales and times'&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# sun__py&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
# ***** BEGIN GPL LICENSE BLOCK *****&lt;br /&gt;
#&lt;br /&gt;
# Copyright (C) 2006 Patrick7&lt;br /&gt;
#&lt;br /&gt;
# This program is free software; you can redistribute it and/or&lt;br /&gt;
# modify it under the terms of the GNU General Public License&lt;br /&gt;
# as published by the Free Software Foundation; either version 2&lt;br /&gt;
# of the License, or (at your option) any later version.&lt;br /&gt;
#&lt;br /&gt;
# This program is distributed in the hope that it will be useful,&lt;br /&gt;
# but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
# GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
# You should have received a copy of the GNU General Public License&lt;br /&gt;
# along with this program; if not, write to the Free Software Foundation,&lt;br /&gt;
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.&lt;br /&gt;
#&lt;br /&gt;
# ***** END GPL LICENCE BLOCK *****&lt;br /&gt;
# --------------------------------------------------------------------------&lt;br /&gt;
__author__ = &amp;quot;Grzegorz Rakoczy &amp;amp; Patrick7&amp;quot;&lt;br /&gt;
__url__ = (&amp;quot;blender&amp;quot;, &amp;quot;elysiun&amp;quot;)&lt;br /&gt;
__version__ = &amp;quot;D&amp;quot;&lt;br /&gt;
__bpydoc__ = &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Description: calculates the sun position based on user input data from the script GUI.&lt;br /&gt;
Usage: run via the GUI following the instructions as written there -or- change the default values specifically in this script and run it alt-p. &lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
####################################################&lt;br /&gt;
# sun__py&lt;br /&gt;
#&lt;br /&gt;
# BACKGROUND&lt;br /&gt;
####################################################&lt;br /&gt;
'''&lt;br /&gt;
20060829&lt;br /&gt;
Most of the actual script that runs this comes from&lt;br /&gt;
a script originally found here:&lt;br /&gt;
	http://blenderartists.org/forum/showthread.php?s=604b30a11e14814c3ec800527ddaa699&amp;amp;t=59884&amp;amp;highlight=sun.py&lt;br /&gt;
that orginal script had the following header:&lt;br /&gt;
###################################################&lt;br /&gt;
#                                                 #&lt;br /&gt;
#            Calculating Sun position             #&lt;br /&gt;
#            by Grzegorz Rakoczy '2004            #&lt;br /&gt;
#                grzybu@obywatel.pl               #&lt;br /&gt;
#                                                 #&lt;br /&gt;
###################################################&lt;br /&gt;
#                                                 #&lt;br /&gt;
#       all calculation are based on page         #&lt;br /&gt;
#  http://www.stjarnhimlen.se/comp/tutorial.html  #&lt;br /&gt;
#                by Paul Schlyter                 #&lt;br /&gt;
#                                                 #&lt;br /&gt;
################################################### &lt;br /&gt;
&lt;br /&gt;
called aptly &amp;quot;sun.py&amp;quot;.. I was working on a script &lt;br /&gt;
like this when I found there was already one available&lt;br /&gt;
I checked the data it out put and compared it to  a &lt;br /&gt;
couple of sources and found this script to actually&lt;br /&gt;
be rather accurate (eg wihin about 1% of NOAA calcs&lt;br /&gt;
http://www.srrb.noaa.gov/&lt;br /&gt;
&lt;br /&gt;
so I (patrick7) have simply addded a GUI and &lt;br /&gt;
system for saving data while cleaning up some minor&lt;br /&gt;
bugs and orientation issues as I saw them.&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# CODE HISTORY&lt;br /&gt;
####################################################&lt;br /&gt;
'''&lt;br /&gt;
version - date - who - descriptions&lt;br /&gt;
Version ?? - Grzegorz Rakoczy '2004 - first release&lt;br /&gt;
pb1 - 060825 - patrick7 -Bugs fixed and features added:&lt;br /&gt;
		1. orientation, changed to radians for calculation&lt;br /&gt;
		2. orientation, automatic calculation based on transit approximation&lt;br /&gt;
		3. notes, included text explaining further the variables&lt;br /&gt;
		4. added blender stuff for running via script window	&lt;br /&gt;
pb1 - 060826 - script fixes&lt;br /&gt;
pb1a/b - 060827 - working in gui.. found out can't&lt;br /&gt;
have scriptlink and gui at the same time, need file&lt;br /&gt;
anyway for defaults, decide to seperate. &lt;br /&gt;
pc1 - 060828 - seperated out of sun-pc1.py&lt;br /&gt;
pc2 - 060828 - removed GUI, clean up&lt;br /&gt;
pc3 - 060829 - functional reading from file.&lt;br /&gt;
c - 060830 - almost release&lt;br /&gt;
0c - 060830 - fixing globals trying to fix bug&lt;br /&gt;
d - 060903 - release&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# OPEN ISSUES&lt;br /&gt;
####################################################&lt;br /&gt;
''' &lt;br /&gt;
0. fix DayOfTheYear to be exact&lt;br /&gt;
'''&lt;br /&gt;
####################################################&lt;br /&gt;
# THE INCLUDES&lt;br /&gt;
####################################################&lt;br /&gt;
import Blender&lt;br /&gt;
from Blender import *&lt;br /&gt;
from math import *&lt;br /&gt;
import os&lt;br /&gt;
import array&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
## COPIED FROM GUI FILE ############################&lt;br /&gt;
####################################################&lt;br /&gt;
DFLTdata= {&lt;br /&gt;
	0: 89.600,	#long&lt;br /&gt;
	1: 27.483 ,	#lat&lt;br /&gt;
	2: 2006,		#year&lt;br /&gt;
	3: 1,				#month&lt;br /&gt;
	4: 1,				#day&lt;br /&gt;
	5: 0,				#hour&lt;br /&gt;
	6: 0.00,		#minute&lt;br /&gt;
	7: 0.00,		#orientation&lt;br /&gt;
	8: 20.00,		#multiplier&lt;br /&gt;
	9: 'Empty'	#empty name&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
n=len(DFLTdata)-1&lt;br /&gt;
&lt;br /&gt;
## Set button variables (settings in the gui)&lt;br /&gt;
GUIdata = {&lt;br /&gt;
	0:Draw.Create(DFLTdata[0]),&lt;br /&gt;
	1:Draw.Create(DFLTdata[1]),&lt;br /&gt;
	2:Draw.Create(DFLTdata[2]),&lt;br /&gt;
	3:Draw.Create(DFLTdata[3]),&lt;br /&gt;
	4:Draw.Create(DFLTdata[4]),&lt;br /&gt;
	5:Draw.Create(DFLTdata[5]),&lt;br /&gt;
	6:Draw.Create(DFLTdata[6]),&lt;br /&gt;
	7:Draw.Create(DFLTdata[7]),&lt;br /&gt;
	8:Draw.Create(DFLTdata[8]),&lt;br /&gt;
	9:Draw.Create(DFLTdata[9])&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
scriptname = &amp;quot;sun__py&amp;quot;&lt;br /&gt;
FILE = None&lt;br /&gt;
fileblend = Blender.Get(&amp;quot;filename&amp;quot;)&lt;br /&gt;
filename = fileblend[:fileblend.rfind(&amp;quot;.&amp;quot;)] + &amp;quot;_blend-&amp;quot; + scriptname + &amp;quot;-control_data-DO_NOT_DELETE&amp;quot;+&amp;quot;.dat&amp;quot;&lt;br /&gt;
FILEdata = {}#DFLTdata&lt;br /&gt;
txt =1 #number of text items&lt;br /&gt;
NAME='sun-0C.py'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# FILE I/O&lt;br /&gt;
####################################################&lt;br /&gt;
## FILEOPEN&lt;br /&gt;
def fileopen():&lt;br /&gt;
	global scriptname, filename&lt;br /&gt;
	#print scriptname,&amp;quot;:FILEOPEN&amp;quot;&lt;br /&gt;
	try:&lt;br /&gt;
		FILE = open(filename, &amp;quot;r&amp;quot;)&lt;br /&gt;
		read()&lt;br /&gt;
	except IOError:&lt;br /&gt;
		pass&lt;br /&gt;
		&lt;br /&gt;
## READ	- functions, first item is a text item.&lt;br /&gt;
def read():&lt;br /&gt;
	global scriptname, GUIdata, FILEdata, n, txt&lt;br /&gt;
	i=0	&lt;br /&gt;
	FILE=open(filename,&amp;quot;r&amp;quot;)&lt;br /&gt;
	while i&amp;lt;=n:&lt;br /&gt;
			x = FILE.readline()&lt;br /&gt;
			if i&amp;lt;=n-txt: &lt;br /&gt;
					FILEdata[i] = float(x)&lt;br /&gt;
			else: &lt;br /&gt;
				x.strip('\n')&lt;br /&gt;
				FILEdata[i]=eval(x)&lt;br /&gt;
			GUIdata[i].val = FILEdata[i]&lt;br /&gt;
			i=i+1&lt;br /&gt;
			startup=1&lt;br /&gt;
	FILE.close()&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
####################################################&lt;br /&gt;
####################################################&lt;br /&gt;
'''&lt;br /&gt;
#write here start date&lt;br /&gt;
y = yNI.val #2006	#from 1901-2099&lt;br /&gt;
m = mNI.val #06    #from 1-12&lt;br /&gt;
day = dayNI.val #01  #from 0-31&lt;br /&gt;
&lt;br /&gt;
#write here your position, you can find your position here&lt;br /&gt;
# http://www.heavens-above.com/countries.asp&lt;br /&gt;
lat = latNI.val #33 #58 #33 #57.717 #North is positive&lt;br /&gt;
long = longNI.val #97 #12 #97 #11.967 #East is positive&lt;br /&gt;
&lt;br /&gt;
#how many minutes for one frame&lt;br /&gt;
multiplier = multiplierNI.val #20&lt;br /&gt;
&lt;br /&gt;
#Name of your Empty object&lt;br /&gt;
empty_name = empty_nameTI.val #&amp;quot;Empty&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#Scene orientation in degrees clockwise, &lt;br /&gt;
# an orientiation of 0degrees is due South when in top view (num7)&lt;br /&gt;
#&lt;br /&gt;
#topview [num7] with orientation at 0degrees:&lt;br /&gt;
#       N&lt;br /&gt;
#       |&lt;br /&gt;
#   W --+-- E&lt;br /&gt;
#       |&lt;br /&gt;
#       S&lt;br /&gt;
#&lt;br /&gt;
#topview [num7] with orientation at 90degrees:&lt;br /&gt;
#       W&lt;br /&gt;
#       |&lt;br /&gt;
#   S --+-- N&lt;br /&gt;
#       |&lt;br /&gt;
#       E&lt;br /&gt;
#&lt;br /&gt;
orientation = orientationNI.val #0&lt;br /&gt;
&lt;br /&gt;
#typically these should not need to be changed&lt;br /&gt;
#hr = 0     #UTC correction from 0-23&lt;br /&gt;
mins = minsNI.val #00  #from 0-59&lt;br /&gt;
#adjustment to hr to account for UTC&lt;br /&gt;
hr = -long/15 + hrNI.val&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
fileopen()&lt;br /&gt;
&lt;br /&gt;
long =GUIdata[0].val&lt;br /&gt;
lat =GUIdata[1].val&lt;br /&gt;
y =GUIdata[2].val&lt;br /&gt;
m =GUIdata[3].val&lt;br /&gt;
day =GUIdata[4].val&lt;br /&gt;
hr =GUIdata[5].val&lt;br /&gt;
mins =GUIdata[6].val&lt;br /&gt;
orientation =GUIdata[7].val&lt;br /&gt;
multiplier =GUIdata[8].val&lt;br /&gt;
empty_name =GUIdata[9].val&lt;br /&gt;
&lt;br /&gt;
hr = -long/15 + hr&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###################################################&lt;br /&gt;
#and now some calculations&lt;br /&gt;
###################################################&lt;br /&gt;
frame = float(Get('curframe')-1)&lt;br /&gt;
&lt;br /&gt;
minsp = mins+frame*multiplier&lt;br /&gt;
daysp = float(minsp)/1440&lt;br /&gt;
h = float(hr + mins/60 + minsp/60)&lt;br /&gt;
&lt;br /&gt;
tpi = 2* pi&lt;br /&gt;
twopi = tpi&lt;br /&gt;
degs = 180 / pi&lt;br /&gt;
rads = pi / 180&lt;br /&gt;
&lt;br /&gt;
#   Get the days to J2000&lt;br /&gt;
#   h is UT in decimal hours&lt;br /&gt;
#   FNday only works between 1901 to 2099 - see Meeus chapter 7&lt;br /&gt;
def FNday (y, m, d, h):&lt;br /&gt;
	days = 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d - 730531.5 + h / 24&lt;br /&gt;
	return float(days)&lt;br /&gt;
&lt;br /&gt;
#   the function below returns the true integer part,&lt;br /&gt;
#   even for negative numbers&lt;br /&gt;
def FNipart(x):&lt;br /&gt;
	return int(sqrt(x*x))&lt;br /&gt;
&lt;br /&gt;
#   the function below returns an angle in the range&lt;br /&gt;
#   0 to two pi&lt;br /&gt;
def FNrange(x):&lt;br /&gt;
    b = x / tpi&lt;br /&gt;
    a = tpi * (b - FNipart(b))&lt;br /&gt;
    if a &amp;lt; 0:  &lt;br /&gt;
			a = tpi + a&lt;br /&gt;
    return a&lt;br /&gt;
&lt;br /&gt;
#   Find the ecliptic longitude of the Sun&lt;br /&gt;
#&lt;br /&gt;
def FNsun(d):&lt;br /&gt;
	L = FNrange(280.461 * rads + 0.9856474 * rads * d)  #   mean longitude of the Sun&lt;br /&gt;
	g = FNrange(357.528 * rads + 0.9856003 * rads * d)  #   mean anomaly of the Sun&lt;br /&gt;
	return FNrange(L + 1.915 * rads * sin(g) + 0.02 * rads * sin(2 * g))  #   Ecliptic longitude of the Sun&lt;br /&gt;
&lt;br /&gt;
def rev(x):&lt;br /&gt;
	rv = x - int(x/360)*360&lt;br /&gt;
	if rv &amp;lt;0:&lt;br /&gt;
		rv = rv + 360&lt;br /&gt;
	return rv&lt;br /&gt;
&lt;br /&gt;
d = FNday(y, m, day, h)&lt;br /&gt;
&lt;br /&gt;
#&amp;gt;&amp;gt; &lt;br /&gt;
# Hack which fixes the orientation based on solar transit time&lt;br /&gt;
# http://ww.srrb.noaa.gov/highlights/sunrise/solareqns.PDF&lt;br /&gt;
# http://en.wikipedia.org/wiki/Equation_of_time&lt;br /&gt;
#DayOfTheYear = date(y,m,day)  #.strftime(&amp;quot;%j&amp;quot;) #this attempt at an exact function is not working&lt;br /&gt;
DayOfTheYear = (m-1)*30+day #approximate&lt;br /&gt;
Bb = 2 * pi * (DayOfTheYear-81)/364&lt;br /&gt;
EqOfTime = 9.87 * sin(2*Bb)-7.53*cos(Bb)-1.5*sin(Bb)&lt;br /&gt;
Transit = 720+4*long-EqOfTime&lt;br /&gt;
#preorientation = Transit/(60*24)*360&lt;br /&gt;
#print preorientation&lt;br /&gt;
orientation = Transit/(60*24)*360-orientation-long-90&lt;br /&gt;
#&amp;lt;&amp;lt;&lt;br /&gt;
&lt;br /&gt;
w = 282.9404 + 4.70935E-5 * d&lt;br /&gt;
a = 1.000000&lt;br /&gt;
e = 0.016709 - 1.151E-9 * d &lt;br /&gt;
M = 356.0470 + 0.9856002585 * d&lt;br /&gt;
M = rev(M)&lt;br /&gt;
&lt;br /&gt;
oblecl = 23.4393 - 3.563E-7 * d&lt;br /&gt;
L = rev(w + M)&lt;br /&gt;
&lt;br /&gt;
E = M + degs * e * sin(M*rads) * (1 + e * cos(M*rads))&lt;br /&gt;
&lt;br /&gt;
x = cos(E*rads) - e&lt;br /&gt;
y = sin(E*rads) * sqrt(1 - e*e)&lt;br /&gt;
r = sqrt(x*x + y*y)&lt;br /&gt;
v = atan2( y, x ) *degs&lt;br /&gt;
lon = rev(v + w)&lt;br /&gt;
&lt;br /&gt;
xequat = r * cos(lon*rads) &lt;br /&gt;
yequat = r * sin(lon*rads) * cos(oblecl*rads)&lt;br /&gt;
zequat = r * sin(lon*rads) * sin(oblecl*rads) &lt;br /&gt;
&lt;br /&gt;
RA = atan2(yequat, xequat)*degs / 15&lt;br /&gt;
Decl = asin(zequat / r) * degs&lt;br /&gt;
&lt;br /&gt;
GMST0 = (L*rads + 180*rads) / 15 * degs&lt;br /&gt;
SIDTIME = GMST0 + h + long/15&lt;br /&gt;
HA = rev((SIDTIME - RA))*15&lt;br /&gt;
&lt;br /&gt;
x = cos(HA*rads) * cos(Decl*rads)&lt;br /&gt;
y = sin(HA*rads) * cos(Decl*rads)&lt;br /&gt;
z = sin(Decl*rads)&lt;br /&gt;
&lt;br /&gt;
xhor = x * sin(lat*rads) - z * cos(lat*rads)&lt;br /&gt;
yhor = y&lt;br /&gt;
zhor = x * cos(lat*rads) + z * sin(lat*rads)&lt;br /&gt;
&lt;br /&gt;
azimuth = atan2(yhor, xhor)*degs + 180&lt;br /&gt;
altitude = atan2(zhor, sqrt(xhor*xhor+yhor*yhor))*degs&lt;br /&gt;
&lt;br /&gt;
empty = Blender.Object.Get(empty_name)&lt;br /&gt;
&lt;br /&gt;
x = 90&lt;br /&gt;
y = 90&lt;br /&gt;
z = 0&lt;br /&gt;
&lt;br /&gt;
ax = azimuth/degs&lt;br /&gt;
az = altitude/degs&lt;br /&gt;
&lt;br /&gt;
empty.RotZ = -ax+orientation/degs&lt;br /&gt;
empty.RotY = -az &lt;br /&gt;
&lt;br /&gt;
actualh = h % 24&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
####################################################&lt;br /&gt;
# DEBUG&lt;br /&gt;
####################################################&lt;br /&gt;
#print &amp;quot;azimuth= &amp;quot;, azimuth &lt;br /&gt;
#print &amp;quot;altitude= &amp;quot;, altitude &lt;br /&gt;
#print &amp;quot;actualh   = &amp;quot;,actualh-hr&lt;br /&gt;
#print &amp;quot;d         = &amp;quot;,d&lt;br /&gt;
#print &amp;quot;declination = &amp;quot;,Decl&lt;br /&gt;
#print &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
[[Category:Script Animation]]&lt;/div&gt;</summary>
		<author><name>wiki&gt;Mindrones</name></author>
		
	</entry>
</feed>