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

Method setFrame

src/image/p5.Image.js:1599–1614  ·  view source on GitHub ↗

* Sets the current frame in an animated GIF. * * @param {Number} index index of the frame to display. * * @example * let gif; * let frameSlider; * * async function setup() { * // Load the image. * gif = await loadImage('assets/arnott-wallace-eye-loop-forever.gif');

(index)

Source from the content-addressed store, hash-verified

1597 * }
1598 */
1599 setFrame(index) {
1600 if (this.gifProperties) {
1601 const props = this.gifProperties;
1602 if (index < props.numFrames && index >= 0) {
1603 props.timeDisplayed = 0;
1604 props.lastChangeTime = 0;
1605 props.displayIndex = index;
1606 this.drawingContext.putImageData(props.frames[index].image, 0, 0);
1607 } else {
1608 this._friendlyError(
1609 'Cannot set GIF to a frame number that is higher than total number of frames or below zero.',
1610 'setFrame'
1611 );
1612 }
1613 }
1614 }
1615
1616 /**
1617 * Returns the number of frames in an animated GIF.

Callers 1

loading.jsFile · 0.80

Calls 1

_friendlyErrorMethod · 0.95

Tested by

no test coverage detected