Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

52
LINES

< > BotCompany Repo | #1020234 // Emotion Module [Smiley with different emotions]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (11035L/58K).

1  
!7
2  
3  
cmodule TalkingSmiley {
4  
  transient JLabel lbl;
5  
  transient int interval = 100;
6  
  transient F0<S> nextTalkingEmotion;
7  
  transient S code;
8  
  transient volatile bool talking;
9  
  transient S baseBaseEmotion = "07";
10  
  transient LS idleEmotions = splitAtSpace("01 02 06 09 14 15 17 18 21");
11  
  transient S baseEmotion = baseBaseEmotion;
12  
  transient long idleSince;
13  
  
14  
  int size = 200; // width
15  
  
16  
  enhanceFrame {
17  
    dm_intFieldMenuItem(f, 'size, onSet := r refreshImage);
18  
    if (!dm_hasPreviousBounds())
19  
      setLocation(f, getWidth(dm_desktopPane())-getWidth(f)-20, 20); // top right corner
20  
  } 
21  
  
22  
  start {
23  
    nextTalkingEmotion = f0_randomLL_differentEveryTime("01", "02", "03", "05");
24  
    dm_vmBus_onMessage('talking, r { talking = true; print("Talking"); });
25  
    dm_vmBus_onMessage('doneTalking, r { talking = false; print("Done talking"); });
26  
  }
27  
  
28  
  visualize {
29  
    lbl = setOpaqueBackground(Color.white, jimage(keriyo_resized_cached(code = baseEmotion, size)));
30  
    componentPopupMenuItems(lbl,
31  
      "Say something...", rThread { inputText("What should I say", f dm_say) },
32  
      "Select voice...", rThread { dm_showModule(dm_voiceOutputModule()) },
33  
      "Change size...", rEnter { dm_setIntFieldDialog('size, onSet := r refreshImage) });
34  
    awtCalcEvery(lbl, interval, r {
35  
      if (talking) idleSince = 0;
36  
      else if (idleSince == 0) { idleSince = sysNow(); baseEmotion = baseBaseEmotion; }
37  
      if (!talking && elapsedSeconds(idleSince) >= 10.0) {
38  
        baseEmotion = tossCoin() ? baseBaseEmotion : random(idleEmotions);
39  
        idleSince = sysNow();
40  
      }
41  
      S newCode = talking ? nextTalkingEmotion! : baseEmotion;
42  
      if (neq(newCode, code))
43  
        setImage(lbl, keriyo_resized_cached(code = newCode, size));
44  
    });
45  
    ret lbl;
46  
  }
47  
  
48  
  void refreshImage enter {
49  
    if (code != null && lbl != null)
50  
      setImage(lbl, keriyo_resized_cached(code, size));
51  
  }
52  
}

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: 269 / 15577
Version history: 25 change(s)
Referenced in: [show references]