1 | sclass Smiley { |
2 | double zoom = 0.5; |
3 | S imageID = #1007256; |
4 | S rectsDef = [[ [Rect(h=415, w=392, x=104, y=168), Rect(h=420, w=393, x=552, y=168), Rect(h=414, w=392, x=1008, y=168), Rect(h=416, w=392, x=1448, y=168), Rect(h=416, w=400, x=112, y=640), Rect(h=416, w=392, x=560, y=640), Rect(h=424, w=400, x=1000, y=632), Rect(h=421, w=393, x=1447, y=632), Rect(h=419, w=400, x=112, y=1112), Rect(h=416, w=392, x=560, y=1112), Rect(h=416, w=392, x=1000, y=1112), Rect(h=424, w=394, x=1446, y=1104), /* the gray one: Rect(h=422, w=393, x=1447, y=1576),*/ Rect(h=420, w=400, x=96, y=1584), Rect(h=420, w=400, x=552, y=1583), Rect(h=416, w=392, x=1000, y=1584)] ]]; |
5 | |
6 | Map<Int, S> names = littreemap( |
7 | 1, "happy", |
8 | 2, "sad", |
9 | 3, "extremely happy", |
10 | 4, "happy with tongue", |
11 | 5, "whaaat", |
12 | 6, "crying", |
13 | 7, "shocked", |
14 | 8, "worried", |
15 | 9, "winking", |
16 | 10, "closed eyes", |
17 | 11, "uuuhm", |
18 | 12, "super-lol", |
19 | 13, "oooh", |
20 | 14, "angry", |
21 | 15, "disappointed" |
22 | ); |
23 | |
24 | ImageSurface is; |
25 | BufferedImage bi; |
26 | Pt size; |
27 | L<Rect> theRects; |
28 | int currentEmotion; |
29 | |
30 | *() { |
31 | bi = loadImage2(imageID); |
32 | theRects = (L<Rect>) unstructure(rectsDef); |
33 | size = ceilScalePt(rectsMaxSize(theRects), zoom); |
34 | } |
35 | |
36 | int emotionToIndex(S s) { |
37 | if "random" ret random(l(theRects))+1; |
38 | for (int i : keys(names)) |
39 | if (match(names.get(i), s)) |
40 | ret i; |
41 | ret 0; |
42 | } |
43 | |
44 | JFrame show() { |
45 | emotion(currentEmotion != 0 ? currentEmotion : 1); |
46 | ret getFrame(is); |
47 | } |
48 | |
49 | bool showing() { ret getFrame(is) != null; } |
50 | |
51 | void hide { |
52 | disposeFrame(is); |
53 | is = null; |
54 | } |
55 | |
56 | void emotion(S s) { |
57 | emotion(emotionToIndex(s)); |
58 | } |
59 | |
60 | void emotion(int _i) { |
61 | final int i = max(1, min(l(theRects), _i)); |
62 | swing { |
63 | if (i != currentEmotion) { |
64 | bool first = is == null; |
65 | currentEmotion = i; |
66 | Rect r = theRects.get(i-1); |
67 | is = showZoomedImage_centered(is, clipBufferedImage(bi, r), zoom); |
68 | setFrameTitle(is, names.get(i)); |
69 | if (first) |
70 | moveToTopRightCorner(frameInnerSize(size, getFrame(is))); |
71 | } |
72 | } |
73 | } |
74 | } |
Began life as a copy of #1007266
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1007338 |
Snippet name: | class Smiley - AWT smiley |
Eternal ID of this version: | #1007338/16 |
Text MD5: | 7627af7ab4d34d44ea0eae559e10f710 |
Author: | stefan |
Category: | javax / a.i. / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-07-24 18:11:07 |
Source code size: | 2183 bytes / 74 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 539 / 1169 |
Version history: | 15 change(s) |
Referenced in: | [show references] |