!7 cmodule TalkingSmiley { transient JLabel lbl; transient int interval = 100; transient F0 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)); } }