sclass Smiley { double zoom = 0.5; S imageID = #1007256; 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)] ]]; Map names = littreemap( 1, "happy", 2, "sad", 3, "extremely happy", 4, "happy with tongue", 5, "whaaat", 6, "crying", 7, "shocked", 8, "worried", 9, "winking", 10, "closed eyes", 11, "uuuhm", 12, "super-lol", 13, "oooh", 14, "angry", 15, "disappointed" ); ImageSurface is; BufferedImage bi; Pt size; L theRects; int currentEmotion; *() { bi = loadImage2(imageID); theRects = (L) unstructure(rectsDef); size = ceilScalePt(rectsMaxSize(theRects), zoom); } int emotionToIndex(S s) { if "random" ret random(l(theRects))+1; for (int i : keys(names)) if (match(names.get(i), s)) ret i; ret 0; } JFrame show() { emotion(currentEmotion != 0 ? currentEmotion : 1); ret getFrame(is); } bool showing() { ret getFrame(is) != null; } void hide { disposeFrame(is); is = null; } void emotion(S s) { emotion(emotionToIndex(s)); } void emotion(int _i) { final int i = max(1, min(l(theRects), _i)); swing { if (i != currentEmotion) { bool first = is == null; currentEmotion = i; Rect r = theRects.get(i-1); is = showZoomedImage_centered(is, clipBufferedImage(bi, r), zoom); setFrameTitle(is, names.get(i)); if (first) moveToTopRightCorner(frameInnerSize(size, getFrame(is))); } } } }