Factory
let myWorld = scrawl.makeWorld({
name: 'demo-world',
tickMultiplier: 2,
userAttributes: [
{
key: 'particleColor',
defaultValue: '#F0F8FF',
},
{
key: 'alphaDecay',
defaultValue: 6,
},
],
});
scrawl.makeEmitter({
name: 'use-raw-2d-context',
world: myWorld,
start: ['center', 'center'],
generationRate: 60,
killAfterTime: 5,
historyLength: 50,
rangeX: 40,
rangeFromX: -20,
rangeY: 40,
rangeFromY: -20,
rangeZ: -1,
rangeFromZ: -0.2,
stampAction: function (artefact, particle, host) {
let engine = host.engine,
history = particle.history,
remaining, radius, alpha, x, y, z,
endRad = Math.PI * 2;
engine.save();
engine.fillStyle = myWorld.get('particleColor');
engine.beginPath();
history.forEach((p, index) => {
[remaining, z, x, y] = p;
radius = 6 * (1 + (z / 3));
alpha = remaining / myWorld.alphaDecay;
if (radius > 0 && alpha > 0) {
engine.moveTo(x, y);
engine.arc(x, y, radius, 0, endRad);
}
});
engine.globalAlpha = alpha;
engine.fill();
engine.restore();
},
});
const makeEmitter = function (items) {
return new Emitter(items);
};
constructors.Emitter = Emitter;