• Jump To … +
    ./source/core/animationloop.js ./source/core/component.js ./source/core/document.js ./source/core/events.js ./source/core/init.js ./source/core/library.js ./source/core/userInteraction.js ./source/core/utilities.js ./source/factory/action.js ./source/factory/anchor.js ./source/factory/animation.js ./source/factory/bezier.js ./source/factory/block.js ./source/factory/canvas.js ./source/factory/cell.js ./source/factory/cog.js ./source/factory/color.js ./source/factory/coordinate.js ./source/factory/element.js ./source/factory/emitter.js ./source/factory/filter.js ./source/factory/fontAttributes.js ./source/factory/gradient.js ./source/factory/grid.js ./source/factory/group.js ./source/factory/imageAsset.js ./source/factory/line.js ./source/factory/loom.js ./source/factory/mesh.js ./source/factory/net.js ./source/factory/noise.js ./source/factory/oval.js ./source/factory/palette.js ./source/factory/particle.js ./source/factory/particleForce.js ./source/factory/particleHistory.js ./source/factory/particleSpring.js ./source/factory/particleWorld.js ./source/factory/pattern.js ./source/factory/phrase.js ./source/factory/picture.js ./source/factory/polygon.js ./source/factory/polyline.js ./source/factory/quadratic.js ./source/factory/quaternion.js ./source/factory/radialGradient.js ./source/factory/rectangle.js ./source/factory/renderAnimation.js ./source/factory/shape.js ./source/factory/spiral.js ./source/factory/spriteAsset.js ./source/factory/stack.js ./source/factory/star.js ./source/factory/state.js ./source/factory/tetragon.js ./source/factory/ticker.js ./source/factory/tracer.js ./source/factory/tween.js ./source/factory/unstackedElement.js ./source/factory/vector.js ./source/factory/videoAsset.js ./source/factory/wheel.js ./source/mixin/anchor.js ./source/mixin/asset.js ./source/mixin/assetConsumer.js ./source/mixin/base.js ./source/mixin/cascade.js ./source/mixin/delta.js ./source/mixin/displayShape.js ./source/mixin/dom.js ./source/mixin/entity.js ./source/mixin/filter.js ./source/mixin/mimic.js ./source/mixin/path.js ./source/mixin/pattern.js ./source/mixin/pivot.js ./source/mixin/position.js ./source/mixin/shapeBasic.js ./source/mixin/shapeCurve.js ./source/mixin/shapePathCalculation.js ./source/mixin/styles.js ./source/mixin/tween.js ./source/worker/filter-string.js ./source/worker/filter.js
  • ¶

    Delta mixin

    This mixin defines additional attributes and functions for an artefact that uses delta functionality

  • ¶

    Imports

    import { mergeOver, mergeDiscard, xt } from '../core/utilities.js';
  • ¶

    Export function

    export default function (P = {}) {
  • ¶

    Shared attributes

        let defaultAttributes = {
  • ¶

    delta - a Javascript object containing {key:value, key:value, etc} attributes.

    • As part of the Display cycle, delta values get added to artefact attribute values - this is a very simple form of animation.
    • noDeltaUpdates - Boolean flag to switch off the automatic application of delta attribute values as part of each iteration of the Display cycle.
    • Delta updates can be invoked independently from the Display cycle by invoking artefact.updateByDelta, artefact.reverseByDelta.
    • In addition to using artefact.set, we can also update the delta object values using artefact.setDeltaValues.
    // This Block artefact will animate itself across the <canvas> element
    // - it will move to the right and upwards until the `delta` values are updated
    // - animation will stop when the `noDeltaUpdates` flag is set
    let myBlock = scrawl.makeBlock({
        start: ['left', 500],
        delta: {
            startX: 0.5,
            startY: '-0.3',
        },
        noDeltaUpdates: false,
    });
            delta: null,
            noDeltaUpdates: false,
        };
        P.defs = mergeOver(P.defs, defaultAttributes);
        mergeOver(P, defaultAttributes);
  • ¶

    Packet management

    No additional packet management functionality defined here

  • ¶

    Clone management

    No additional clone functionality defined here

  • ¶

    Kill management

    No additional kill functionality defined here

  • ¶

    Get, Set, deltaSet

        let S = P.setters,
            D = P.deltaSetters;
  • ¶

    delta

        S.delta = function (items = {}) {
    
            if (items) this.delta = mergeDiscard(this.delta, items);
        };
  • ¶

    Prototype functions

  • ¶

    updateByDelta - this function gets called as part of every display cycle iteration, meaning that if an attribute is set to a non-zero value in the delta attribute object then those delta animations will start playing immediately.

        P.updateByDelta = function () {
    
    if (this.name == 'kaliedoscope-clock-background') console.log(this.name, 'updateByDelta')
            this.setDelta(this.delta);
    
            return this;
        };
  • ¶

    reverseByDelta - The opposite action to ‘updateByDelta’; values in the delta attribute object will be subtracted from the current value for that Scrawl-canvas object.

        P.reverseByDelta = function () {
    
            let temp = {};
            
            Object.entries(this.delta).forEach(([key, val]) => {
    
                if (val.substring) val = -(parseFloat(val)) + '%';
                else val = -val;
    
                temp[key] = val;
            });
    
            this.setDelta(temp);
    
            return this;
        };
  • ¶

    setDeltaValues

    • TODO - the idea is that we can do things like ‘add:1’, ‘subtract:5’, ‘multiply:6’, ‘divide:3.4’, etc
    • for this to work, we need to do do work here to split the val string on the ‘:’
    • for now, just do reverse and zero numbers
        P.setDeltaValues = function (items = {}) {
    
            let delta = this.delta, 
                oldVal, action;
    
            Object.entries(items).forEach(([key, requirement]) => {
    
                if (xt(delta[key])) {
    
                    action = requirement;
    
                    oldVal = delta[key];
    
                    switch (action) {
    
                        case 'reverse' :
                            if (oldVal.toFixed) delta[key] = -oldVal;
  • ¶

    TODO: reverse String% (and em, etc) values

                            break;
    
                        case 'zero' :
                            if (oldVal.toFixed) delta[key] = 0;
  • ¶

    TODO: zero String% (and em, etc) values

                            break;
    
                        case 'add' :
                            break;
    
                        case 'subtract' :
                            break;
    
                        case 'multiply' :
                            break;
    
                        case 'divide' :
                            break;
                    }
                }
            })
            return this;
        };
  • ¶

    Return the prototype

        return P;
    };