1
+ function main ( ) {
2
+ // gifOpen - Returns a handle for the GIF. If it returns 0, it means there was an error opening the file.
3
+ const patrick = gifOpen ( 'littlefs' , '/gifs/half_patrick.gif' ) ;
4
+ const spongebob = gifOpen ( 'littlefs' , '/gifs/half_spongebob.gif' ) ;
5
+ const rick = gifOpen ( 'littlefs' , '/gifs/half_rick.gif' ) ;
6
+ const rainbow = gifOpen ( 'littlefs' , '/gifs/half_rainbow.gif' ) ;
7
+
8
+ // Check if all GIFs failed to load
9
+ if ( ! patrick && ! spongebob && ! rick && ! rainbow ) {
10
+ println ( "Cannot load gifs" ) ;
11
+ println ( "Make sure that they are in /gifs folder" ) ;
12
+ delay ( 3000 ) ;
13
+ throw new Error ( "Cannot load gifs" ) ;
14
+ }
15
+
16
+ while ( true ) {
17
+ gifPlayFrame ( patrick , 0 , 0 ) ; // Plays a frame of the GIF at the specified position.
18
+ gifPlayFrame ( spongebob , 60 , 0 ) ;
19
+ gifPlayFrame ( rick , 120 , 0 ) ;
20
+ gifPlayFrame ( rainbow , 180 , 0 ) ;
21
+
22
+ // To remove gif you can use:
23
+ // const dimensions = gifDimensions(rainbow); // Retrieves the dimensions of the Rainbow GIF.
24
+ // drawFillRect(x + 120, y, dimensions.width, dimensions.height, color(0, 0, 0)); // Clears the previous frame.
25
+ // gifClose(rainbow, x + 120, y); // Closes the Rainbow GIF to release resources.
26
+
27
+ // gifPlayFrame(patrick, x, y);
28
+ // You can move GIFs by changing x and y. Ensure you clear the old position
29
+ // with drawFillRect(x, y, dimensions.width, dimensions.height, color(0, 0, 0))
30
+ // and gifReset(patrick) it because GIFs are often optimized to draw only the pixels that change between frames.
31
+
32
+ if ( getAnyPress ( ) ) {
33
+ break ; // Exits the loop when a button is pressed.
34
+ }
35
+ }
36
+ }
37
+
38
+ main ( ) ;
0 commit comments