-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #687 from Tawank/animated_gif_fix
Add Animated Gifs support
- Loading branch information
Showing
11 changed files
with
477 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function main() { | ||
// gifOpen - Returns a handle for the GIF. If it returns 0, it means there was an error opening the file. | ||
const patrick = gifOpen('littlefs', '/gifs/half_patrick.gif'); | ||
const spongebob = gifOpen('littlefs', '/gifs/half_spongebob.gif'); | ||
const rick = gifOpen('littlefs', '/gifs/half_rick.gif'); | ||
const rainbow = gifOpen('littlefs', '/gifs/half_rainbow.gif'); | ||
|
||
// Check if all GIFs failed to load | ||
if (!patrick && !spongebob && !rick && !rainbow) { | ||
println("Cannot load gifs"); | ||
println("Make sure that they are in /gifs folder"); | ||
delay(3000); | ||
throw new Error("Cannot load gifs"); | ||
} | ||
|
||
while(true) { | ||
gifPlayFrame(patrick, 0, 0); // Plays a frame of the GIF at the specified position. | ||
gifPlayFrame(spongebob, 60, 0); | ||
gifPlayFrame(rick, 120, 0); | ||
gifPlayFrame(rainbow, 180, 0); | ||
|
||
// To remove gif you can use: | ||
// const dimensions = gifDimensions(rainbow); // Retrieves the dimensions of the Rainbow GIF. | ||
// drawFillRect(x + 120, y, dimensions.width, dimensions.height, color(0, 0, 0)); // Clears the previous frame. | ||
// gifClose(rainbow, x + 120, y); // Closes the Rainbow GIF to release resources. | ||
|
||
// gifPlayFrame(patrick, x, y); | ||
// You can move GIFs by changing x and y. Ensure you clear the old position | ||
// with drawFillRect(x, y, dimensions.width, dimensions.height, color(0, 0, 0)) | ||
// and gifReset(patrick) it because GIFs are often optimized to draw only the pixels that change between frames. | ||
|
||
if (getAnyPress()) { | ||
break; // Exits the loop when a button is pressed. | ||
} | ||
} | ||
} | ||
|
||
main(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.