MCPcopy Create free account
hub / github.com/melonjs/melonJS / _buildGradient

Method _buildGradient

packages/melonjs/src/renderable/trail.js:209–238  ·  view source on GitHub ↗

* Build a Gradient from trail constructor options. * @param {object} options - trail constructor options * @returns {Gradient} * @ignore

(options)

Source from the content-addressed store, hash-verified

207 * @ignore
208 */
209 _buildGradient(options) {
210 const gradient = new Gradient("linear", [0, 0, 1, 0]);
211
212 if (options.gradient) {
213 const entries = options.gradient;
214 for (let i = 0; i < entries.length; i++) {
215 const entry = entries[i];
216 if (typeof entry === "string" || (entry && entry.toRGBA)) {
217 // plain color: evenly distribute
218 const offset = entries.length > 1 ? i / (entries.length - 1) : 0;
219 gradient.addColorStop(offset, entry);
220 } else {
221 // positioned stop: { pos, color }
222 gradient.addColorStop(entry.pos, entry.color);
223 }
224 }
225 } else if (options.color) {
226 // parse into a Color to handle CSS names, rgba(), hex, or Color objects
227 const parsed = colorPool.get(options.color);
228 const hex = parsed.toHex();
229 colorPool.release(parsed);
230 gradient.addColorStop(0, `${hex}ff`);
231 gradient.addColorStop(1, `${hex}00`);
232 } else {
233 gradient.addColorStop(0, "#ffffffff");
234 gradient.addColorStop(1, "#ffffff00");
235 }
236
237 return gradient;
238 }
239
240 /** @ignore */
241 destroy() {

Callers 1

constructorMethod · 0.95

Calls 4

addColorStopMethod · 0.95
toHexMethod · 0.80
getMethod · 0.65
releaseMethod · 0.65

Tested by

no test coverage detected