Libraryless. Click here for Pure Java version (21966L/138K).
1 | sclass AnimatedImageSurface > ImageSurface { |
2 | double fps = 20; |
3 | |
4 | // We start & stop the timer by setting its frequency |
5 | // to the actual frequency or 0, respectively. |
6 | // (Don't want to close the timer as that is permanent.) |
7 | FlexibleRateTimer animationTimer = new(0, l0 renderFrame).pileUp(false); |
8 | |
9 | void renderFrame { |
10 | var img = makeImage(); |
11 | if (img != null) |
12 | setImage(img); |
13 | } |
14 | |
15 | selfType fps aka setFPS(double fps) { |
16 | this.fps = fps; |
17 | swing { updateTimer(isShowing()); } |
18 | this; |
19 | } |
20 | |
21 | swappable BufferedImage makeImage() { |
22 | ret whiteImage(10, 10); |
23 | } |
24 | |
25 | *() { init(); } |
26 | *(IF0<BufferedImage> *makeImage) { init(); } |
27 | *(double fps, IF0<BufferedImage> *makeImage) { setFPS(fps); init(); } |
28 | *(Freq freq, IF0<BufferedImage> *makeImage) { setFPS(freq!); init(); } |
29 | |
30 | void updateTimer(bool showing) { |
31 | animationTimer.setFrequencyImmediately(showing ? fps : 0.0); |
32 | } |
33 | |
34 | void init { |
35 | setDoubleBuffered(true); |
36 | bindToComponent(this, |
37 | -> { animationTimer.start(); updateTimer(true); }, |
38 | -> updateTimer(false)); |
39 | } |
40 | } |
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: | 190 / 302 |
Version history: | 9 change(s) |
Referenced in: | [show references] |