Uses 911K of libraries. Click here for Pure Java version (11035L/58K).
!7 cmodule TalkingSmiley { transient JLabel lbl; transient int interval = 100; transient F0<S> nextTalkingEmotion; transient S code; transient volatile bool talking; transient S baseBaseEmotion = "07"; transient LS idleEmotions = splitAtSpace("01 02 06 09 14 15 17 18 21"); transient S baseEmotion = baseBaseEmotion; transient long idleSince; int size = 200; // width enhanceFrame { dm_intFieldMenuItem(f, 'size, onSet := r refreshImage); if (!dm_hasPreviousBounds()) setLocation(f, getWidth(dm_desktopPane())-getWidth(f)-20, 20); // top right corner } start { nextTalkingEmotion = f0_randomLL_differentEveryTime("01", "02", "03", "05"); dm_vmBus_onMessage('talking, r { talking = true; print("Talking"); }); dm_vmBus_onMessage('doneTalking, r { talking = false; print("Done talking"); }); } visualize { lbl = setOpaqueBackground(Color.white, jimage(keriyo_resized_cached(code = baseEmotion, size))); componentPopupMenuItems(lbl, "Say something...", rThread { inputText("What should I say", f dm_say) }, "Select voice...", rThread { dm_showModule(dm_voiceOutputModule()) }, "Change size...", rEnter { dm_setIntFieldDialog('size, onSet := r refreshImage) }); awtCalcEvery(lbl, interval, r { if (talking) idleSince = 0; else if (idleSince == 0) { idleSince = sysNow(); baseEmotion = baseBaseEmotion; } if (!talking && elapsedSeconds(idleSince) >= 10.0) { baseEmotion = tossCoin() ? baseBaseEmotion : random(idleEmotions); idleSince = sysNow(); } S newCode = talking ? nextTalkingEmotion! : baseEmotion; if (neq(newCode, code)) setImage(lbl, keriyo_resized_cached(code = newCode, size)); }); ret lbl; } void refreshImage enter { if (code != null && lbl != null) setImage(lbl, keriyo_resized_cached(code, size)); } }
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, iveijnkanddl, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1020234 |
Snippet name: | Emotion Module [Smiley with different emotions] |
Eternal ID of this version: | #1020234/26 |
Text MD5: | 4613b60956407ff2cdad9527245f2327 |
Transpilation MD5: | 9df6680af64b009bafd931dde3c8e74b |
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: | 2020-04-13 20:56:46 |
Source code size: | 1950 bytes / 52 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 337 / 15666 |
Version history: | 25 change(s) |
Referenced in: | #1020300 - dm_showTalkingSmiley |