Libraryless. Click here for Pure Java version (21966L/138K).
sclass AnimatedImageSurface > ImageSurface { double fps = 20; // We start & stop the timer by setting its frequency // to the actual frequency or 0, respectively. // (Don't want to close the timer as that is permanent.) FlexibleRateTimer animationTimer = new(0, l0 renderFrame).pileUp(false); void renderFrame { var img = makeImage(); if (img != null) setImage(img); } selfType fps aka setFPS(double fps) { this.fps = fps; swing { updateTimer(isShowing()); } this; } swappable BufferedImage makeImage() { ret whiteImage(10, 10); } *() { init(); } *(IF0<BufferedImage> *makeImage) { init(); } *(double fps, IF0<BufferedImage> *makeImage) { setFPS(fps); init(); } *(Freq freq, IF0<BufferedImage> *makeImage) { setFPS(freq!); init(); } void updateTimer(bool showing) { animationTimer.setFrequencyImmediately(showing ? fps : 0.0); } void init { setDoubleBuffered(true); bindToComponent(this, -> { animationTimer.start(); updateTimer(true); }, -> updateTimer(false)); } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035260 |
Snippet name: | AnimatedImageSurface |
Eternal ID of this version: | #1035260/10 |
Text MD5: | 8556053a4c8d7bedb826c7faa0ffe8e3 |
Transpilation MD5: | ed8258aac119d079a52bc732884b4a39 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-11-26 23:46:49 |
Source code size: | 1118 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 189 / 301 |
Version history: | 9 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) |