-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopt.js
187 lines (161 loc) · 5.02 KB
/
opt.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
************************
** By **
** Nicola Klemenc **
** github.com/nicklem **
************************
*/
var OPT = ( function() {
var YES = 1 , NO = 0 ;
var colors = {
"White" : [ 255 , 255 , 255 ] ,
"Gray 1" : [ 127 , 127 , 127 ] ,
"Gray 2" : [ 63 , 63 , 63 ] ,
"Gray 3" : [ 31 , 31 , 31 ] ,
"Black" : [ 0 , 0 , 0 ] ,
"Red" : [ 255 , 0 , 0 ] ,
"Green" : [ 0 , 255 , 0 ] ,
"Blue" : [ 0 , 0 , 255 ] ,
"Cyan" : [ 0 , 255 , 255 ] ,
"Magenta" : [ 255 , 0 , 255 ] ,
"Yellow" : [ 255 , 255 , 0 ]
} ;
var multiThread = { "Two" : 2 , "Four" : 4 , "Eight" : 8 } ;
var optionData = {
"max" : { // max before algo can assume it diverges
"value" : 2 ,
"labelText" : "Max" ,
"type" : "text" ,
"recalcNeeded": YES
} ,
"iter" : {
"value" : 25 ,
"labelText" : "Iterations" ,
"type" : "text" ,
"recalcNeeded": YES
} ,
"deltaIter" : {
"value" : 0 ,
"labelText" : "Delta iter" ,
"type" : "text" ,
"recalcNeeded": NO
} ,
"zoom" : {
"value" : 1 ,
"labelText" : "Zoom factor" ,
"type" : "text" ,
"recalcNeeded": NO
} ,
"rot" : {
"value" : 0 ,
"labelText" : "Rotation" ,
"type" : "text" ,
"recalcNeeded": YES
} ,
"multiThread" : {
"value" : "Four" ,
"labelText" : "Threads" ,
"type" : "select" ,
"options": multiThread ,
"recalcNeeded": NO
} ,
"brightness" : {
"value" : 1 ,
"labelText" : "Brightness" ,
"type" : "text" ,
"recalcNeeded": NO
} ,
"haloDecay" : {
"value" : 7 ,
"labelText" : "Halo decay" ,
"type" : "text" ,
"recalcNeeded": NO
} ,
"innerColor" : {
"value" : "White" ,
"labelText" : "Inner color" ,
"type" : "select" ,
"options": colors ,
"recalcNeeded": NO
} ,
"rimColor" : {
"value" : "Red" ,
"labelText" : "Rim color" ,
"type" : "select" ,
"options": colors ,
"recalcNeeded": NO
} ,
"haloColor" : {
"value" : "Blue" ,
"labelText" : "Halo color" ,
"type" : "select" ,
"options": colors ,
"recalcNeeded": NO
} ,
"outerColor" : {
"value" : "Black" ,
"labelText" : "Outer color" ,
"type" : "select" ,
"options": colors ,
"recalcNeeded": NO
} ,
} ;
var getOptionData = function() { return optionData ; } ;
// TODO: temporary solution. Needs proper setters w input checking
var setOption = function( opt , val ) {
if( typeof( optionData[ opt ].value ) !== "undefined") {
optionData[ opt ].value = val ;
} else throw new Error( { "message" : "Setting non-existent option" } ) ;
} ;
var optFromGET = function() {
var res = {}, tmp = [] , hasTrailingSlash = false ;
location.search.substr( 1 )
.split( "&" )
.forEach( function( item ) {
tmp = item.split( "=" ) ;
tmp[ 1 ] = decodeURIComponent( tmp[ 1 ] ) ;
hasTrailingSlash = !! tmp[ 1 ].match(/\/$/) ;
if( hasTrailingSlash ) {
tmp[ 1 ] = tmp[ 1 ].substring( 0 , tmp[ 1 ].length - 1 ) ;
}
res[ tmp[ 0 ] ] = { "value" : tmp[ 1 ] } ;
} ) ;
} ;
var autoThread = function() {
if( !! navigator.hardwareConcurrency ) {
// optionData.multiThread.value = navigator.hardwareConcurrency ;
// console.log( optionData.multiThread.options.indexOf ) ;
}
} ;
var getColors = function() {
return colors ;
} ;
var getInnerColor = function() { return colors[ optionData.innerColor.value ] ; } ;
var getRimColor = function() { return colors[ optionData.rimColor.value ] ; } ;
var getHaloColor = function() { return colors[ optionData.haloColor.value ] ; } ;
var getOuterColor = function() { return colors[ optionData.outerColor.value ] ; } ;
var getMaxSq = function() { return optionData.max.value * optionData.max.value } ;
var getZoom = function() { return optionData.zoom.value } ;
var getRot = function() { return optionData.rot.value } ;
var isPolar = function() { return true } ;
var updateIterOnClick = function() { optionData.iter.value += optionData.deltaIter.value ; } ;
var getNumThreads = function() { return optionData.multiThread.options[ optionData.multiThread.value ]; } ;
var API = {
"getOptionData" : getOptionData ,
"setOption" : setOption ,
"getColors" : getColors ,
"getMaxSq" : getMaxSq ,
"getZoom" : getZoom ,
"getNumThreads" : getNumThreads ,
"isPolar" : isPolar ,
"getRot" : getRot ,
"getInnerColor" : getInnerColor ,
"getRimColor" : getRimColor ,
"getHaloColor" : getHaloColor ,
"getOuterColor" : getOuterColor ,
"updateIterOnClick" : updateIterOnClick ,
"optFromGET" : optFromGET ,
"autoThread" : autoThread
} ;
return API ;
} () ) ; // END opt