//thymic chemistry fear and sadness are the predators that have the tendency to decrease over time and delight and desire are the preys that have the tendency to increase over time, as well as fear reacts with desire and sadness reacts with delight. In the reaction of fear and desire, the prey converts to predator, desire converts to fear, and in the reaction of delight and sadness, delight converts to sadness. Also, there are four more reactions, which produce new emotions. One reaction is that of desire and delight, which is a catalytic reaction that produces two new preys, where desire converts to friendliness, and delight converts to excitement. Moreover, there is the reaction of sadness and fear, which produce two new predators, sadness converts to cowardice (δειλία) and fear converts to aggressiveness. Last, there is the reaction of desire and sadness, where desire converts to melancholy, and the reaction of delight and fear, where delight converts to ambivalence. /* ------------Elements::10------------- //increase over time RatePreys: 1.0f Preys: Desire, Delight, friendliness, excitement //decrease over time RatePredators: 0.5f Predators: Fear, Sadness, Cowardice, Aggressiveness, Melancholy, Ambivalence -----Reactions of the Elements:------- RatePredator:0.5; Reaction1:Desire+Fear= 2Fear RatePredator:0.5; Reaction2:Delight+Sadness= 2Sadness RatePrey:1.0; Reaction3:Desire+Delight= Friendliness + Excitement RatePredator:0.5; Reaction4:Sadness+Fear= Cowrdice + Aggressiveness RatePredator:0.5; Reaction5:Desire+Sadness= Melancholy+Sadness RatePredator:0.5; Reaction6:Delight+Fear= Ambivalence+Fear -----------Characters::5-------------- Ambivalent: Rate: 1.0; Reaction6:Delight+Fear= Ambivalence+Fear Melancholic: Rate:1.0; Reaction5:Desire+Sadness= Melancholy+Sadness Cowrdice: RatePredatorSadness: 1.0; Reaction4:Sadness+Fear= Cowrdice + Aggressiveness Aggressive: RatePredatorFear: 1.0; Reaction4:Sadness+Fear= Cowrdice + Aggressiveness Friendly: RatePreyDesire: 1.5; Reaction3:Desire+Delight= Friendliness + Excitement -----Reactions of Characters---------- ------Valence:------ |Desire+Friendliness|+Ambivalance-|Melancholy+Fear| ------Arousal:------ |Delight+Excitement+Aggressiveness|-|Sadness+Cowardice| Search(looking at) & Talk(looking at looked at) & Initiate Conversation(higher valence, higher arousal) & Response(lower valence, lower arousal) & End Conversation(30% when v<0, 70% when a<0) Melancholic + Cowardcice: ValenceM + ArousalC if (|VM|>|VC|) {Talk Mel talks first, MSynth trigger talks for 3 seconds then Cow responds to Mel, by leaving the conversation first} else {search} if (|AC|>|AM|) { Talk Cow talks first, for 3 seconds then Mel responds to Cow, for 3 seconds, Cow and Mel go into silence and after 5 seconds they both leave the conversation. } Else {search} Melancholic + Friendly: ValenceM +ValenceF if (|VF|>|VM|){ Fre talks first to Mel, FreSynth trigger for 10 seconds, then Mel talks for 3 seconds and leaves conversation first }else if (|VM|>|VF|){ stay and look at each other for 3 seconds or both keep the Search } Melancholic + Aggressive: ValenceM+ArousalAg if (|VAg|>|VM|){ Aggr talks to Mel first for 3 seconds, and Mel } Talk Melancholic + Ambivalent: ValenceM+ValenceAm if VM>VA, VA talks for 5 seconds with Va, VM talks first for 2 seconds, VA talks second for 3 seconds, Conversation ends after 10 seconds if VA>VM, VA talks first for 3 seconds with VM, VM doesn't talk just looks at Am for 2 seconds and they both end leave the conversation after 5 seconds Cowardice + Friendly: ValenceF+ArousalC Cowardice + Aggressive: ArousalC+ArousalAg Cowardice + Ambivalent: Valence + Arousal Friendly + Aggressive: ValenceF+ArousalAg Friendly + Ambivalent: ValenceF+ValenceAm */
let dim = 10;
let art_world = new field2D(dim);
let past = new field2D(dim);

let emotions = [];

// the names of these chemicals:
let names = "delightdesiresadnessfearambivalence aggressivenessfriendlinessexcitementcowardicemelancholy".split
let mouseX=0.5, mouseY=0.5;




const lower_limit = 0.01;
const upper_limit = 50.0;

/*delight, sadness, fear, desire, thumos*/

// reaction constants:

let kdelight = 0.5;
let kdelightfear = 0.5;

let ksadness = 0.5;
let ksadelight = 0.5;
let ksadfear = 1.0;

let kfear = 1.0;
let kfeardesire = 1.0;

let kdesire = 0.5;
let ksaddesire = 0.5;
let kdesiredelight = 1.0;
let kambivalence=0.5, kaggressiveness=0.5, kfriendliness=1.0, kexcitement=1.0, kcowardice=0.5, kmelancholy=0.5;

function reset() {
  // initial concentrations for the set of chemicals:

  emotions = [0.5, 0.5, 0.5, 0.5,0.5, 0.5, 0.5, 0.5,0.5,0.5];
  
  art_world.set(0);
    past.set(0);
}

function react() {
 //emotions[delight, desire, sadness, fear,ambivalence, aggressiveness, friendliness, excitement, cowardice, melancholy]
  let [delight, desire, sadness, fear,ambivalence, aggressiveness, friendliness, excitement, cowardice, melancholy] = emotions;
  
  // delta changes of each chemical:
  let ddelight = 0,
    dsadness = 0,
    dfear = 0,
    ddesire = 0,
    dambivalence= 0,
    daggressiveness= 0, 
    dfriendliness= 0,
    dexcitement= 0,
    dcowardice= 0,
    dmelancholy= 0;
  // dthumos = 0;
  // timestep -- needs to be small, or else the dynamics can break:
  let dt = 0.00001;

  
 let x= mouseX;
 let y =mouseY;
   x = Math.min(Math.max(x, 0.5), 1.0);
 
  y =Math.min(Math.max(y, 0.5), 1.0);
 
  // apply reaction rules:

  // sadness => 2sadness         @rate ksadness (ksadness<kdelight)
  
  //sadness+delight=>2Delight
  
  dsadness += -ksadness * sadness;
 
  dsadness += ksadelight * sadness * delight;
  ddelight += -ksadelight * sadness * delight;
  //delight=>2Delight
  ddelight += kdelight * delight;
  
  //Desire+Fear=>2Fear;
  dfear += -kfear * fear;
  dfear += kfeardesire * desire * fear;
  ddesire += -kfeardesire * desire * fear;
 
  //desire=>2Desire
  ddesire += kdesire * desire;
 
  //Sadness=>2Sadness && Delight=>2Delight
  //Ambivalence=>.
  dambivalence += (ksadelight* 1) *sadness *delight;
  dambivalence+=  -kambivalence* ambivalence;
    
   //Fear=>2Fear && Desire=>2Desire
  //Aggressiveness
  daggressiveness += (kfeardesire*1*mouseX) *fear*desire;
  daggressiveness += -kaggressiveness *aggressiveness;
   
  //Fear=>2Fear
  //Cowardice
  dcowardice += (kfear * 1)*fear;
  dcowardice += -kcowardice * cowardice/x;


   
   //Sadness=>2Sadness && Excitement=>. 
   //Melancholy
    dmelancholy += (ksadelight *1)*sadness;
    dmelancholy += -kmelancholy* melancholy/x;
    
    
    //Desire=>2Desire &&Aggressiveness=>.
    //Friendliness
    dfriendliness   += (kfeardesire *1 )*desire/aggressiveness;
    dfriendliness   += -kfriendliness * friendliness/y;

  //Delight=>2Delight && Aggressiveness=>2Aggressiveness
    //Excitement
    dexcitement     += (kdelight*1) *delight*aggressiveness;
    dexcitement     += -kexcitement * excitement/y;

    // apply changes:
    delight += ddelight * dt;
    sadness += dsadness * dt;
    fear += dfear * dt;
    desire += ddesire * dt;
    ambivalence += dambivalence *dt;
    melancholy += dmelancholy *dt;
    excitement+= dexcitement * dt;
    friendliness += dfriendliness *dt;
    aggressiveness += daggressiveness *dt;
    cowardice += dcowardice *dt;
 
 
  ambivalence = Math.min(Math.max(ambivalence, lower_limit), upper_limit);


  melancholy = Math.min(Math.max(melancholy, lower_limit), upper_limit);


  excitement = Math.min(Math.max(excitement, lower_limit), upper_limit);


  friendliness= Math.min(Math.max(friendliness, lower_limit), upper_limit);


  aggressiveness = Math.min(Math.max(aggressiveness, lower_limit), upper_limit);


  cowardice = Math.min(Math.max(cowardice, lower_limit), upper_limit);


  
  
  
  
  //thumos += dthumos * dt;
  emotions = [delight, desire, sadness, fear,ambivalence,melancholy,excitement,friendliness,aggressiveness,cowardice];
}

function update(dt) {
  // run 100,000 reactions per second

  for (let i = 0; i < dt * 500000; i++) {
    react();
  }
   var tmp = art_world;
  art_world = past;
  past = tmp;
  
  art_world.diffuse(past, 0.2);
  art_world.set(function(x, y) {
    if (
      y < (random() * 0.2 + 0.4) * art_world.height &&
      y > (random() * 0.2 + 0.4) * art_world.height
    ) {
      if (
        x < (random() * 0.2 + 0.05) * art_world.width &&
        x > (random() * 0.2 + 0.05) * art_world.width
      )
        return 0;
      // Middle Pole
      if (
        x < (random() * 0.2 + 0.4) * art_world.width &&
        x > (random() * 0.2 + 0.4) * art_world.width
      ) {
        return 0.2;
      } else if (
        x < (random() * 0.2 + 0.75) * art_world.width &&
        x > (random() * 0.2 + 0.75) * art_world.width
      ) {
        // Right Pole
        return 0;
      }
    }
    return art_world.get(x, y);
  });
  art_world.map(function(v) {
    return clamp(v, 0, 1);
  });
}

function key(kind, key) {
  if (key == "r" && kind == "down") {
    reset();
  }
  // if (key == "s" && kind == "down") {
  //   react(c);
  // }
}

function mouse(e, pt) {
  mouseX = pt[0] + 0.5;
  mouseY = pt[1] + 0.5;
  art_world.deposit(1, pt);
}

function draw(ctx) {
  // display the current concentrations

  // unpack chemical array into local variables:
  let [delight, desire, sadness, fear,ambivalence, aggressiveness, friendliness, excitement, cowardice, melancholy] = emotions;
  let emotionLabel = ["delight", "desire", "sadness", "fear","ambivalence", "aggressiveness", "friendliness", "excitement", "cowardice", "melancholy"];
  //  Let ["desire", "delight", "sadness", "fear"]
  let numemotions = emotions.length;

  // for each chemical:
  for (let i = 0; i < emotions.length; i++) {
    let c = emotions[i];
    let t = i / numemotions;
    let x = Math.sin(Math.PI * 2 * t);
    let y = Math.cos(Math.PI * 2 * t);
   // x+=c*mouseX;
    x+=c*mouseY/2*mouseX;
    //c-=y;
    //y+=c;
    // human-readable information:
    let name = String.fromCharCode(65 + i);
    let label = i;

    // area = pi * radius*radius
    // radius = sqrt(area/pi)
    // clamp c between 0 and 10 to prevent blowups in renderer:
    let radius = Math.sqrt(Math.min(5, Math.max(0, c/2)) / Math.PI);
    //let area = Math.PI * radius * radius;

    draw2D.push().translate(0.5,0.5).scale(0.25).translate(x, y);
    {
      draw2D.color("lightgrey");
      draw2D.hsl(t, 1);
      ctx.font = "0.1px sans";
      //

      draw2D.hsl(-t*mouseY/2*mouseX , 0.9);
      draw2D.circle(radius);
      ctx.fillText(emotionLabel[label],-0.175*c, -0.2*c);
     
      //
    }
   
  
    draw2D.pop();


    write(emotionLabel[i], c);
  }
}
/*

*/

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://alicelab.world/code/al2019.js
  2. https://cdnjs.cloudflare.com/ajax/libs/tone/14.7.3/Tone.js