MCPcopy
hub / github.com/processing/p5.js / _animateGif

Method _animateGif

src/image/p5.Image.js:79–105  ·  view source on GitHub ↗

* Helper function for animating GIF-based images with time

(pInst)

Source from the content-addressed store, hash-verified

77 * Helper function for animating GIF-based images with time
78 */
79 _animateGif(pInst) {
80 const props = this.gifProperties;
81 const curTime = pInst._lastRealFrameTime || window.performance.now();
82 if (props.lastChangeTime === 0) {
83 props.lastChangeTime = curTime;
84 }
85 if (props.playing) {
86 props.timeDisplayed = curTime - props.lastChangeTime;
87 const curDelay = props.frames[props.displayIndex].delay;
88 if (props.timeDisplayed >= curDelay) {
89 //GIF is bound to 'realtime' so can skip frames
90 const skips = Math.floor(props.timeDisplayed / curDelay);
91 props.timeDisplayed = 0;
92 props.lastChangeTime = curTime;
93 props.displayIndex += skips;
94 props.loopCount = Math.floor(props.displayIndex / props.numFrames);
95 if (props.loopLimit !== null && props.loopCount >= props.loopLimit) {
96 props.playing = false;
97 } else {
98 const ind = props.displayIndex % props.numFrames;
99 this.drawingContext.putImageData(props.frames[ind].image, 0, 0);
100 props.displayIndex = ind;
101 this.setModified(true);
102 }
103 }
104 }
105 }
106
107 /**
108 * Loads the current value of each pixel in the image into the `img.pixels`

Callers 3

imageMethod · 0.80
materialFunction · 0.80
_shouldUpdateMethod · 0.80

Calls 1

setModifiedMethod · 0.95

Tested by

no test coverage detected