-
Notifications
You must be signed in to change notification settings - Fork 0
/
flicker.php
127 lines (105 loc) · 3.61 KB
/
flicker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
$home = exec( 'echo $HOME' );
$data = "$home/Library/Application Support/Alfred 2/Workflow Data/com.spr.f.lux";
$levels = array( 'dark' => array( 'lower' => 1,
'upper' => 200000
),
'dim' => array( 'lower' => 1000,
'upper' => 400000
),
'normal' => array( 'lower' => 500000,
'upper' => 850000
),
'bright' => array( 'lower' => 750000,
'upper' => 1000000
),
);
$speeds = array( 'calm' => array( 'lower' => 5000000,
'upper' => 100000000
),
'breeze' => array( 'lower' => 4000000,
'upper' => 7000000
),
'windy' => array( 'lower' => 3000000,
'upper' => 6000000
),
'hurricane' => array( 'lower' => 1,
'upper' => 2000000
)
);
if ( isset( $argv[1] ) && in_array( $argv[1], $levels ) )
$level = $argv[1];
else
$level = 'normal';
if ( isset( $argv[2] ) && in_array( $argv[2], $speeds ) )
$speed = $argv[2];
else
$speed = 'breeze';
if ( isset( $argv[3] ) ) {
if ( is_numeric( $argv[3] ) )
// So this means we'll go for a certain number of seconds.
$duration = $argv[3];
else if ( file_exists( $argv[3] ) ) {
$duration = $argv[3];
}
} else {
$duration = 250;
}
$preset = array( $level , $speed );
// Open a nice blank canvas.
`open background.html`;
time_nanosleep( 0, 5000000 );
// Send the web browser into full screen
`osascript "open-canvas.scpt"`;
// `defaults write $HOME/Library/Preferences/org.herf.Flux.plist nightColorTemp -integer 2300`;
// Wait for the transition
time_nanosleep( 0, 1000000 );
// Flicker!
flicker( $levels[$preset[0]], $speeds[$preset[1]], $duration );
// Take it out of full screen.
`osascript "close-canvas.scpt"`;
function flicker( $levels = array( 'lower' => 0 , 'upper' => 1000000 ),
$speed = array( 'lower' => 0, 'upper' => 1000000000 ) , $duration = 250 ) {
$brightness = explode( "\n" , `./screenbrightness -l` );
$brightness = str_replace( "display 0: brightness " , '' , $brightness[1] );
$continue = TRUE;
$start = mktime();
while ( $continue == TRUE ) {
if ( is_numeric( $duration ) ) {
if ( ( mktime() - $start ) > $duration )
$continue = FALSE;
} else {
if ( ! file_exists( $duration ) )
$continue = FALSE;
}
if ( mt_rand( 0, 100 ) > 85 )
$sleep = mt_rand( 5000, 10000 );
else
$sleep = mt_rand( $speed[ 'lower' ], $speed[ 'upper' ] );
if ( mt_rand( 0, 100) > 90 ) {
$lower = mt_rand( 1, 10000 );
$upper = mt_rand( 1, 100000 );
if ( $lower > $upper ) {
$upper = $lower + mt_rand( 100, 10000 );
$level = mt_rand( $lower, $upper );
} else {
$level = mt_rand( $lower, $upper );
}
}
else {
$level = mt_rand( $levels[ 'lower' ], $levels[ 'upper' ] ) / 1000000;
if ( $level <= 0 ) {
$level = $levels[ 'lower' ] + mt_rand( $levels['lower'], $levels[ 'upper'] );
}
}
if ( $level > 1 )
$level = 1;
if ( $level == 0 ) {
$level = .01;
}
`./screenbrightness $level`;
time_nanosleep( 0 , $sleep );
}
// Set the screen brightness back to normal.
`./screenbrightness $brightness`;
}