-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrandomize.js
147 lines (125 loc) · 5.27 KB
/
randomize.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
const deepClone = require('./deep-clone.js');
const {
RENDER_MODES,
BLEND_FUNCS,
BLEND_FACTORS,
BLEND_SETS,
BLEND_FUNCS_IDS,
BLEND_FACTORS_IDS,
funcKeys,
factorKeys,
setsKeys
} = require('./constants.js');
const is = require('./check-layer-type.js');
const randomize = (applyRandomizer, model, constants, updateGui) => (config) => () => {
const toSend = deepClone(model);
const mode = model.mode;
const omega = Math.random() * 2 - 1;
const products = constants.products;
const productIdx = Math.floor(Math.random() * products);
const product = products[productIdx].id;
config.product = product;
config.omega = omega;
toSend.product = product;
toSend.omega = omega;
toSend.layers.forEach((layerDef, index) => {
// .visible
if (is.fss(layerDef)) {
const mirror = Math.random() > 0.5 ? true : false;
layerDef.model.mirror = mirror;
config['mirror' + index] = mirror;
const lightSpeed = Math.floor(Math.random() * 1040 + 100);
layerDef.model.lightSpeed = lightSpeed;
config['lightSpeed' + index] = lightSpeed;
const renderModeIdx = Math.floor(Math.random() * RENDER_MODES.length);
const renderMode = RENDER_MODES[renderModeIdx];
layerDef.model.renderMode = renderMode;
config['renderMode' + index] = renderMode;
const facesMax = (mode !== 'prod') ? 100 : 50;
const [ facesX, facesY ] =
[ Math.floor(Math.random() * facesMax)
, Math.floor(Math.random() * facesMax)
];
layerDef.model.faces = [ facesX, facesY ];
config['facesX' + index] = facesX;
config['facesY' + index] = facesY;
const iris = Math.random();
layerDef.model.iris = iris;
config['iris' + index] = iris;
const vignette = Math.random();
layerDef.model.vignette = vignette;
config['vignette' + index] = vignette;
const [ amplitudeX, amplitudeY, amplitudeZ ] =
[ Math.random(), Math.random(), Math.random() ];
layerDef.model.amplitude = [ amplitudeX, amplitudeY, amplitudeZ ];
config['amplitudeX' + index] = amplitudeX;
config['amplitudeY' + index] = amplitudeY;
config['amplitudeZ' + index] = amplitudeZ;
const opacity = (mode !== 'prod') ? Math.random() : 1.0;
layerDef.model.opacity = opacity;
config['opacity' + index] = opacity;
const [ hue, saturation, brightness ] =
[ (mode !== 'prod') ? Math.random() * 2.0 - 1.0 : 0.0,
Math.random() * 2.0 - 1.0,
Math.random() * 2.0 - 1.0 ];
layerDef.model.colorShift = [ hue, saturation, brightness ];
config['hue' + index] = hue;
config['saturation' + index] = saturation;
config['brightness' + index] = brightness;
}
// comment this out to not randomize blends
if (layerDef.kind == 'webgl') {
if (mode !== 'prod') {
const blendFuncsCount = Object.values(BLEND_FUNCS_IDS).length;
const blendFactorsCount = Object.values(BLEND_FACTORS_IDS).length;
const colorEq =
[ Math.floor(Math.random() * blendFuncsCount)
, Math.floor(Math.random() * blendFactorsCount)
, Math.floor(Math.random() * blendFactorsCount)
];
const alphaEq =
[ Math.floor(Math.random() * blendFuncsCount)
, Math.floor(Math.random() * blendFactorsCount)
, Math.floor(Math.random() * blendFactorsCount)
];
//config['blendColor' + index] = [ 0, 0, 0, 0 ];
config['blendColorEqFn' + index] = BLEND_FUNCS[funcKeys[colorEq[0]]];
config['blendColorEqFactor0' + index] = BLEND_FACTORS[factorKeys[colorEq[0]]];
config['blendColorEqFactor1' + index] = BLEND_FACTORS[factorKeys[colorEq[1]]];
config['blendAlphaEqFn' + index] = BLEND_FUNCS[funcKeys[alphaEq[0]]];;
config['blendAlphaEqFactor0' + index] = BLEND_FACTORS[factorKeys[alphaEq[0]]];
config['blendAlphaEqFactor1' + index] = BLEND_FACTORS[factorKeys[alphaEq[1]]];
// TODO: color { r: color[0], g: color[1], b: color[2], a: color[3] }
layerDef.blend =
[ { color: null
, colorEq: colorEq
, alphaEq: alphaEq
}
, null
];
} else {
const blendSetIndex = [ Math.floor(Math.random() * Object.values(BLEND_SETS).length) ];
const blendSet = BLEND_SETS[setsKeys[blendSetIndex]];
//console.log(config['blendSet' + index], blendSet);
config['blendSet' + index] = blendSet;
// TODO:
// layerDef.blend =
// [ { color: null
// , colorEq: []
// , alphaEq: alphaEq
// }
// , null
// ];
}
} else {
}
});
// console.log(toSend);
// toSend.layers = model.layers.concat([]).reverse().map((layerDef, index) => {
// return layerDef;
// });
if (updateGui) updateGui();
// });
applyRandomizer(toSend);
}
module.exports = randomize;