Libraryless. Click here for Pure Java version (15223L/108K).
1 | !7 |
2 | |
3 | module RecordGIFSpike > DynSingleFunctionWithPrintLog { |
4 | double sleepBefore = 5, recordForSeconds = 10, frameRate = 10; |
5 | Rect area; |
6 | |
7 | S switchableFields() { ret "sleepBefore recordForSeconds frameRate"; } |
8 | |
9 | void doIt { |
10 | // TODO: delete gif on interruption |
11 | |
12 | runInterruptibly(voidfunc(final Runnable interrupt) ctex { |
13 | temp AutoCloseable action = dm_currentAction("Will record GIF from screen in " + n2(sleepBefore, "second") + "...", |
14 | r { print("INTERRUPTED"); callF(interrupt) }); |
15 | print("Sleeping for " + sleepBefore + " before recording GIF..."); |
16 | sleepSeconds(sleepBefore); |
17 | call(action, 'setText, "Recording GIF"); |
18 | Rect r = or(area, rect(screenWidth()/2-100, 0, 200, 100)); |
19 | GifSequenceWriter writer = null; |
20 | long start = sysNow(); |
21 | File f = javaxDataDir("Recorded GIFs", ymd_minus_hms() + ".gif"); |
22 | temp ImageOutputStream out = fileImageOutputStream(f); |
23 | int delay = iround(1000/frameRate); |
24 | int i = 0; |
25 | while (elapsedMS(start) < toMS(recordForSeconds)) { |
26 | BufferedImage img = shootScreenArea_possiblyBroken(r); |
27 | if (writer == null) |
28 | writer = GifSequenceWriter(out, img.getType(), delay, true); |
29 | writer.writeToSequence(img); |
30 | ++i; |
31 | long slept = sleepUntilSys(start+delay*i); |
32 | print("Wrote image " + i + " (leeway: " + slept + " of " + delay + " ms" + ")"); |
33 | } |
34 | close(writer); |
35 | print("Done writing " + fileInfo(f)); |
36 | }); |
37 | } |
38 | |
39 | // API |
40 | |
41 | void useAreaOfModule(O module) { |
42 | setField(area := toRect(boundsOnScreen(dm_frame(module)))); |
43 | } |
44 | } |
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1019873 |
Snippet name: | Record GIF from Screen Spike [OK] |
Eternal ID of this version: | #1019873/29 |
Text MD5: | 4c93eb4ea90efd6574af7457a0375166 |
Transpilation MD5: | 303175c8402f7c0c0d000cb75d14c2f2 |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-12-02 00:24:53 |
Source code size: | 1651 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 792 / 1200 |
Version history: | 28 change(s) |
Referenced in: | [show references] |