torben | 2017-04-24 15:13
Sunlight Script
A script to control day and night cycle.

The script was made by Paul Wendtland.
- define pitch and colour of sunlight
- control fogcolour and its density
We used it in Lamiae.
https://github.com/Hirato/lamiae

Error message in sauerbraten:
unknown alias lookingup:lastmillis

I don't know, if it's compatible.
But inspiring all the time. :D

https://vimeo.com/214227539

mapstart = $lastmillis
daylength = 50000
x = $daylength
red = 0
green = 0
blue = 0

//Uhrzeit    6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23   0   1   2   3   4   5  extra*\\
//timescale  0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20  21  22  23  extra*\\
redval   = [ 200 250 230 230 200 180 140 180 230 170 200 180 130 130 140 140 100  50  20  20  20  40  80 150 200 ]
greenval = [ 115 160 150 150 150 150 140 180 230 170 200 180 130 120  90  90  30  20  10  20  10  20  90 105 115 ]
blueval  = [ 110 130 150 150 170 200 210 190 230 200 190 180 170 160 80 100  70  50  50  50  50  70  90 100 110 ]

fogredval   = [ 20 140 150 160 170 150 150 110 100 100 190 100 120 150 160  80  30  30  30  30  10  0  0  10  20 ]
foggreenval = [ 0 100 110 120 130 140 140 140 110 100 190 100 100 100 140  70  30  30  30  30  0  0  0  0  0 ]
fogblueval  = [ 25 100 150 150 150 180 200 190 190 250 190 180 140 150 130 100  80  70  50  30 10  10  0  15 25 ]

fogdensityval = [ 40 50 90 100 130 150 200 230 250 150 50 150 230 180 140 100  90  70  80  30  10  10 20 30 40 ]

//*the extra value has to contain the same as the first value and enables easier looping at the end of the day

redst = []; redsh = []; greenst = []; greensh = []; bluest = []; bluesh = []
fogredst = []; fogredsh = []; foggreenst = []; foggreensh = []; fogbluest = []; fogbluesh = []
fogdenst = []; fogdensh = []

loop i ((- (listlen $redval) 1)) [
 redst = (concat $redst (* (- (at $redval (+ $i 1)) (at $redval $i)) 24 ) ) //red-steigung
 redsh = (concat $redsh (+ (* (*f (at $redst $i) (divf $i 24)) -1) (at $redval $i)))
 greenst = (concat $greenst (* (- (at $greenval (+ $i 1)) (at $greenval $i)) 24 ) ) //green-steigung
 greensh = (concat $greensh (+ (* (*f (at $greenst $i) (divf $i 24)) -1) (at $greenval $i)))
 bluest = (concat $bluest (* (- (at $blueval (+ $i 1)) (at $blueval $i)) 24 ) ) //blue-steigung
 bluesh = (concat $bluesh (+ (* (*f (at $bluest $i) (divf $i 24) ) -1) (at $blueval $i)))
 
 fogredst = (concat $fogredst (* (- (at $fogredval (+ $i 1)) (at $fogredval $i)) 24 ) ) //fogred-steigung
 fogredsh = (concat $fogredsh (+ (* (*f (at $fogredst $i) (divf $i 24)) -1) (at $fogredval $i)))
 foggreenst = (concat $foggreenst (* (- (at $foggreenval (+ $i 1)) (at $foggreenval $i)) 24 ) ) //foggreen-steigung
 foggreensh = (concat $foggreensh (+ (* (*f (at $foggreenst $i) (divf $i 24)) -1) (at $foggreenval $i)))
 fogbluest = (concat $fogbluest (* (- (at $fogblueval (+ $i 1)) (at $fogblueval $i)) 24 ) ) //fogblue-steigung
 fogbluesh = (concat $fogbluesh (+ (* (*f (at $fogbluest $i) (divf $i 24) ) -1) (at $fogblueval $i)))
 
 fogdenst = (concat $fogdenst (* (- (at $fogdensityval (+ $i 1)) (at $fogdensityval $i)) 24 ) ) //fogblue-steigung
 fogdensh = (concat $fogdensh (+ (* (*f (at $fogdenst $i) (divf $i 24) ) -1) (at $fogdensityval $i)))
]


// CYCLE STARTS ------------------------------------------------------------------------------
cycle = [

time = (mod (- $lastmillis $mapstart) $daylength)
hour = (div (* (- $time 1) 24) $x) //Ganzzahl zwischen 0 und 23

red = (+ (div (* (at $redst $hour) $time) $x) (at $redsh $hour))
green = (+ (div (* (at $greenst $hour) $time) $x) (at $greensh $hour))
blue = (+ (div (* (at $bluest $hour) $time) $x) (at $bluesh $hour))

fogred = (+ (div (* (at $fogredst $hour) $time) $x) (at $fogredsh $hour))
foggreen = (+ (div (* (at $foggreenst $hour) $time) $x) (at $foggreensh $hour))
fogblue = (+ (div (* (at $fogbluest $hour) $time) $x) (at $fogbluesh $hour))

fogdensity = (+ (div (* (at $fogdenst $hour) $time) $x) (at $fogdensh $hour))

 
ambient (+ 30 (div $red 10)) (+ 20 (div $green 10)) (+ 15 (div $blue 10))
sunlight $red $green $blue
fogcolour $fogred $foggreen $fogblue
fog (* $fogdensity 30)
cloudcolour $red $green $blue
skyboxcolour $red $green $blue
sunlightyaw (divf (* 360 $time) $x )

//--------Kommentar entfernen, um die jeweiligen Werte anzuzeigen------|
sunlight
//sunlightyaw
//sunlightpitch

sunlightpitch (-f 45 (*f 40 (cos (divf (* 360 $time) $x)))) 
//---------andere Pitchvarianten-------|
//sunlightpitch (-f 45 (*f 40 (cos (*f 2 (*f 360 (*f (divf $time $x) (divf $time $x) ))) )))
//sunlightpitch (-f 45 (*f 40 (cos (*f 2 (*f 360 (*f (divf (+ $time (div $x 12) ) $x) (divf (+ $time (div $x 12) ) $x) ))) )))
//-------------------------------------|

 sleep 50 cycle
]
cycle
0
points
 (0 votes)
User login
Users on Quadropolis
1 guest & no users online
7YearBitch
28
points ]
 (3 votes)
Created 2020-06-02 09:43
2 days 10 hours ago
10
points ]
 (1 vote)
Created 2020-06-01 20:40
2 days 23 hours ago
18
points ]
 (2 votes)
Created 2020-05-31 16:27
4 days 3 hours ago
LURKing
33
points ]
 (4 votes)
Created 2020-05-09 17:56
3 weeks 5 days ago
20
points ]
 (2 votes)
Created 2020-05-16 23:15
2 weeks 4 days ago
Created 2020-05-14 12:56
3 weeks 7 hours ago
224
points ]
 (23 votes)
Created 2012-10-20 09:56
7 years 32 weeks ago
Gangler
10
points ]
 (1 vote)
Created 2020-05-12 22:59
3 weeks 1 day ago
afroninja
46
points ]
 (5 votes)
Created 2020-01-15 07:47
20 weeks 1 day ago
20
points ]
 (2 votes)
Created 2020-04-29 18:35
5 weeks 1 day ago
140
points ]
 (15 votes)
Created 2013-06-09 21:05
6 years 51 weeks ago
20
points ]
 (2 votes)
Created 2020-05-02 19:58
4 weeks 5 days ago
20
points ]
 (2 votes)
Created 2016-07-28 12:06
3 years 44 weeks ago
7YearBitch
20
points ]
 (2 votes)
Created 2020-03-16 20:09
11 weeks 2 days ago
70
points ]
 (7 votes)
Created 2020-01-24 22:26
18 weeks 5 days ago
40
points ]
 (4 votes)
Created 2020-01-23 12:57
19 weeks 7 hours ago
30
points ]
 (4 votes)
Created 2020-01-26 14:10
18 weeks 4 days ago
180
points ]
 (18 votes)
Created 2011-09-05 14:13
8 years 39 weeks ago
Sauce
71
points ]
 (8 votes)
Created 2018-08-22 19:15
1 year 41 weeks ago
Lord Kv
160
points ]
 (16 votes)
Created 2015-03-12 14:45
5 years 12 weeks ago
Who's new
  • Spr1te
  • Akari
  • LURKing
  • Antknee55
  • gmiz