/************************************************************** * Program: Basic State Machine * * Author: Kenneth J. Stojevich * * Date: September 10, 2005 * * Version: 0.01 * * Version History: * * Version 0.01 - 09/10/2005: Setup the basic scene and * * laid out all the necessary structure for future * * work of this State Machine/Fuzzy Logic System. * * Version 0.10 - 09/11/2005: Basic movement and random * * decisions are setup for sphere A, added a basic * * fuzzy logic system for the talking and decision * * making process for any spheres in this setup. * * Description: The basic idea is to have a ball by the name * * A who wakes up and must decide where he is to go now, * * and these decisions are made initially off of three * * random numbers, he will either go to the kitchen, the * * bathroom, or outside to meetup with some more friends. * * Whom are also spheres and have a conversation which * * happen according to sphere B's attitude (randomly * * choosen also) and A's attitude, and any other friends * * that may come into the scene. * * This is a rather large and I'm sure will end up being a * * confusing expression. I will do my best to keep it as * * commented as possible as I'm trying to see if its * * possible to do this all in Maya Expressions. * * Special Thanks: * * Mike Morasky - for being an awsome teacher, being an * * incredibly insightful person, and for the * * defuzzification code I based mine off of [^_^] * **************************************************************/ vector $normalizeMe; float $epsilon = 0.25; // epsilon for a multiplier to lessen some values // $influence will be an always altering variable for our conversation // the goal is to have this be the deciding factor where the conversation // goes next... float $influence; string $AName, $Name; float $BFirst, $CFirst; // who's gonna talk first, B or C...oooooo float $talkCounter, $yellCounter, $listenCounter, $scaredCounter; float $talking, $yelling, $listening, $scared, $leaving; float $rotSphere, $sphereTalk; float $newSphere; int $counter; int $respond, $conversing, $secondSphere; float $stateChange; // will be a random variable to determine if state is to change // if we are at frame 0 (the start) we set all default values if ( initiator.setInitialValues ) { $AName = "A"; $talkCounter = 0.0; $yellCounter = 0.0; $listenCounter = 0.0; $scaredCounter = 0.0; $respond = 0; $stateChange = 0; $sphereTalk = 0; $conversing = 0; $secondSphere = 0; A.translateX = -10.0; A.translateY = 0.0; A.translateZ = -10.0; A.scaleX = 1.0; A.scaleY = 1.0; A.scaleZ = 1.0; A.rotateY = 0; AShader.colorR = 0.5; AShader.colorG = 0.5; AShader.colorB = 0.5; A_top.rotateX = 180.00; A_top.rotateY = 0.0; A_top.rotateZ = 0.0; A_bottom.rotateX = 0.0; A_bottom.rotateY = 0.0; A_bottom.rotateZ = 0.0; A.bathroom = 1; A.hungary = 1; A.outside = 0; A.moving = 0; A.leaveBathroom = 0; A.leaveKitchen = 0; A.leaveBedroom = 1; A.changeState = 0; A.introduction = 1; A.leave = 0; B.translateX = 50.0; B.translateY = 0.0; B.translateZ = 22.5; B_top.rotateX = 180; B.rotateY = 270.0; B.talking = 0; B.introduction = 0; BShader.colorR = 0.5; BShader.colorG = 0.5; BShader.colorB = 0.5; C.translateX = 0.0; C.translateY = 0.0; C.translateZ = 50.0; C_top.rotateX = 180; C.rotateY = 180.0; C.talking = 0; C.introduction = 0; CShader.colorR = 0.5; CShader.colorG = 0.5; CShader.colorB = 0.5; $BFirst = rand(0,1); $CFirst = rand(0,1); $newSphere = 0.0; } proc moving() { A.useBathroom = rand(0,1); A.gotoKitchen = rand(0,1); A.goOutside = rand(0,1) * $epsilon; if ( !A.bathroom ) A.useBathroom = 0.0; if ( !A.hungary ) A.gotoKitchen = 0.0; if ( !A.bathroom && !A.hungary ) A.goOutside = 1.0; } proc gotoBathroom() { print("I am going to go use the bathroom" + "\n"); A.moving = 1; if ( A.leaveBedroom ) { if ( A.translateZ > -5.0 ) A.translateZ -= .25; else if ( A.translateZ < -5.0 ) A.translateZ += .25; if ( A.translateZ == -5.0 ) { if ( A.translateX < 5.0 ) A.translateX += .25; else if ( A.translateX > 5.0 ) A.translateX -= .25; } if ( A.translateX == 5.0 && A.translateZ == -5 ) A.leaveBedroom = 0; } if ( A.leaveKitchen ) { if ( A.translateX > -4.5 && A.translateZ == 5.0 ) A.translateX -= 0.25; if ( A.translateX == -4.5 && A.translateZ > -5.0 ) A.translateZ -= 0.25; if ( A.translateZ == -5.0 && A.translateX < 5 ) A.translateX += 0.25; if ( A.translateX == 5.0 && A.translateZ == -5 ) A.leaveKitchen = 0; } if ( A.translateX == 5.0 && A.translateZ == -5 ) { A.bathroom = 0; A.moving = 0; A.leaveBathroom = 1; print("Well, I'm done using the bathroom, where to now?"); } } proc gotoKitchen() { print("I am going to go to the kitchen and get something to eat." + "\n"); A.moving = 1; if ( A.leaveBedroom ) { if ( A.translateX < -5 ) A.translateX += 0.25; if ( A.translateZ < 5.0 && A.translateX == -5 ) A.translateZ += 0.25; else if ( A.translateZ > 5.0 ) A.translateZ -= 0.25; if ( A.translateZ == 5.0 ) { if ( A.translateX < 7.5 ) A.translateX += 0.25; else if ( A.translateX > 7.5 ) A.translateX -= 0.25; } if ( A.translateZ == 5.0 && A.translateX == 7.5 ) A.leaveBedroom = 0; } if ( A.leaveBathroom ) { if ( A.translateX > -5.0 && A.translateZ == -5 ) A.translateX -= 0.25; else if ( A.translateX == -5.0 ) if ( A.translateZ < 5.0 ) A.translateZ += 0.25; if ( A.translateZ == 5.0 && A.translateX == -5 ) if ( A.translateX < 7.5 ) A.translateX += 0.25; if ( A.translateZ == 5.0 ) if ( A.translateX < 7.5 ) A.translateX += 0.25; if ( A.translateZ == 5.0 && A.translateX == 7.5 ) A.leaveBathroom = 0; } if ( A.translateZ == 5.0 && A.translateX == 7.5 ) { A.hungary = 0.0; A.moving = 0; A.leaveKitchen = 1; print("So full, well now lets see what should I do next?"); } } proc goOutside() { A.moving = 1; A.useBathroom = 0.0; A.gotoKitchen = 0.0; print("I am going to go outside and see what's going on." + "\n"); if ( A.leaveBathroom || A.leaveBedroom ) { if ( A.translateX > -5.0 && A.translateZ < 5.0 ) A.translateX -= 0.25; else if ( A.translateX < -5.0 && A.translateZ < 5.0 ) A.translateX += 0.25; if ( A.translateX == -5.0 && A.translateZ < 5.0 ) A.translateZ += 0.25; if ( A.translateX < 0.0 && A.translateZ == 5.0 ) A.translateX += 0.25; if ( A.translateX == 0.0 ) { if ( A.translateZ > 20.0 ) A.translateZ -= 0.25; else if ( A.translateZ < 20.0 ) A.translateZ += 0.25; } } else { if ( A.translateX < 0.0 ) A.translateX += 0.25; else if ( A.translateX > 0.0 ) A.translateX -= 0.25; if ( A.translateX == 0.0 ) { if ( A.translateZ > 20.0 ) A.translateZ -= 0.25; else if ( A.translateZ < 20.0 ) A.translateZ += 0.25; } } if ( A.translateX == 0.0 && A.translateZ == 20.0 ) { A.outside = 1; A.moving = 0; print("I'm outside now lets see what's going on" + "\n"); } } proc changeTheState() { print("Changing the State" + "\n"); $talking = 10 * ( rand(0,1) * $epsilon ); $yelling = 5 * ( rand(0,1) * $epsilon ); //$yelling = 1000000; $listening = 5 * ( rand(0,1) * $epsilon ); $scared = 5 * ( rand(0,1) * $epsilon ); A.changeState = 0; } proc talk() { A.talking = 1; A.changeState = 0; A_top.rotateX = 140; A.rotateX = 0; if (A.scaleX > 1.0) { A.scaleX -= 0.005; A.scaleY -= 0.005; A.scaleZ -= 0.005; } if (A.scaleX < 1.0) { A.scaleX += 0.005; A.scaleY += 0.005; A.scaleZ += 0.005; } if (AShader.colorR > 0.5) // listening, let's turn back to grey AShader.colorR -= 0.1; if (AShader.colorG > 0.5) AShader.colorG -= 0.1; if (AShader.colorB > 0.5) AShader.colorB -= 0.1; if (AShader.colorR < 0.5) // listening, let's turn back to grey AShader.colorR += 0.1; if (AShader.colorG < 0.5) AShader.colorG += 0.1; if (AShader.colorB < 0.5) AShader.colorB += 0.1; if ( $talkCounter >= 0.00 && $talkCounter <= 0.10 ) print("My it sure is a nice day out today " + $Name + "." + "\n"); if ( $talkCounter >= 0.10 && $talkCounter <= 0.20 ) print("Probably gonna be one of the last nice days we have this year, yea think?" + "\n"); if ( $talkCounter >= 0.20 && $talkCounter <= 0.30 ) print("Sooooooooo...what's new with you?" + "\n"); $talkCounter += 0.001; $stateChange += 0.001; $newSphere += (rand(0,1) * 0.001); if ( $Name == "B" ) { B_top.rotateX = 180; B.rotateX = $rotSphere * 30; if (B.scaleX > 1.0) { B.scaleX -= 0.005; B.scaleY -= 0.005; B.scaleZ -= 0.005; } if (B.scaleX < 1.0) { B.scaleX += 0.005; B.scaleY += 0.005; B.scaleZ += 0.005; } if (BShader.colorR > 0.0) // listening, let's turn blue BShader.colorR -= 0.1; if (BShader.colorG > 0.0) BShader.colorG -= 0.1; if (BShader.colorB < 1.0) BShader.colorB += 0.1; } if ( $Name == "C" ) { C_top.rotateX = 180; C.rotateX = $rotSphere * 30; if (C.scaleX > 1.0) { C.scaleX -= 0.005; C.scaleY -= 0.005; C.scaleZ -= 0.005; } if (C.scaleX < 1.0) { C.scaleX += 0.005; C.scaleY += 0.005; C.scaleZ += 0.005; } if (CShader.colorR > 0.0) // listening, let's turn blue CShader.colorR -= 0.1; if (CShader.colorG > 0.0) CShader.colorG -= 0.1; if (CShader.colorB < 1.0) CShader.colorB += 0.1; } if ( $secondSphere && !C.moving && !B.moving ) { B_top.rotateX = 180; B.rotateX = $rotSphere * 30; if (B.scaleX > 1.0) { B.scaleX -= 0.005; B.scaleY -= 0.005; B.scaleZ -= 0.005; } if (B.scaleX < 1.0) { B.scaleX += 0.005; B.scaleY += 0.005; B.scaleZ += 0.005; } if (BShader.colorR > 0.0) // listening, let's turn blue BShader.colorR -= 0.1; if (BShader.colorG > 0.0) BShader.colorG -= 0.1; if (BShader.colorB < 1.0) BShader.colorB += 0.1; C_top.rotateX = 180; C.rotateX = $rotSphere * 30; if (C.scaleX > 1.0) { C.scaleX -= 0.005; C.scaleY -= 0.005; C.scaleZ -= 0.005; } if (C.scaleX < 1.0) { C.scaleX += 0.005; C.scaleY += 0.005; C.scaleZ += 0.005; } if (CShader.colorR > 0.0) // listening, let's turn blue CShader.colorR -= 0.1; if (CShader.colorG > 0.0) CShader.colorG -= 0.1; if (CShader.colorB < 1.0) CShader.colorB += 0.1; } if ( $talkCounter <= 0.10 ) print("Why, yes " + $AName + " it sure is a fine day out here today." + "\n"); else if ( $talkCounter <= 0.20 ) print("Hard to tell " + $AName + ", but I sure hope it isn't. The summer's been so short." + "\n"); else if ( $talkCounter <= 0.30 ) print("Same old, same old...you?" + "\n"); } proc yell() { A.yelling = 1; A.changeState = 0; $newSphere += (rand(0,1) * 0.001); if ( $sphereTalk ) { A_top.rotateX = 140; $sphereTalk = 0; } else { A_top.rotateX = 180; $sphereTalk = 1; } if ( $yellCounter <= 0.05 ) print("I am so mad at you right now, grrrr." + "\n"); else if ( $yellCounter <= 0.10 ) print("GRRRRRR, I hate you I hope you go flat!!!!" + "\n"); else if ( $yellCounter <= 0.15 ) print("You are not on my good side" + "\n"); if (AShader.colorR < 1.0) // we are pissed off and red AShader.colorR += 0.1; if (AShader.colorG > 0.0) AShader.colorG -= 0.1; if (AShader.colorB > 0.0) AShader.colorB -= 0.1; if (A.scaleX <= 2.5) // scale head up we are mad { A.scaleX += 0.005; A.scaleY += 0.005; A.scaleZ += 0.005; } $yellCounter += 0.001; $stateChange += 0.001; $newSphere += (rand(0,1) * 0.01); if ( $Name == "B" ) { B_top.rotateX = 180; B.rotateX = 0.0; if (B.scaleX > 0.5) // we are scared, shrink in fear { B.scaleX -= 0.005; B.scaleY -= 0.005; B.scaleZ -= 0.005; } if (BShader.colorR < 1.0) // we're scared and yellow BShader.colorR += 0.1; if (BShader.colorG < 1.0) BShader.colorG += 0.1; if (BShader.colorB > 0.0) BShader.colorB -= 0.1; } else if ( $Name == "C" ) { C_top.rotateX = 180; C.rotateX = 0.0; if (C.scaleX > 0.5) // we are scared, shrink in fear { C.scaleX -= 0.005; C.scaleY -= 0.005; C.scaleZ -= 0.005; } if (CShader.colorR < 1.0) // we're scared and yellow CShader.colorR += 0.1; if (CShader.colorG < 1.0) CShader.colorG += 0.1; if (CShader.colorB > 0.0) CShader.colorB -= 0.1; } if ( $secondSphere && !C.moving && !B.moving ) { B_top.rotateX = 180; B.rotateX = 0.0; if (B.scaleX > 0.5) // we are scared, shrink in fear { B.scaleX -= 0.005; B.scaleY -= 0.005; B.scaleZ -= 0.005; } if (BShader.colorR < 1.0) // we're scared and yellow BShader.colorR += 0.1; if (BShader.colorG < 1.0) BShader.colorG += 0.1; if (BShader.colorB > 0.0) BShader.colorB -= 0.1; C_top.rotateX = 180; C.rotateX = 0.0; if (C.scaleX > 0.5) // we are scared, shrink in fear { C.scaleX -= 0.005; C.scaleY -= 0.005; C.scaleZ -= 0.005; } if (CShader.colorR < 1.0) // we're scared and yellow CShader.colorR += 0.1; if (CShader.colorG < 1.0) CShader.colorG += 0.1; if (CShader.colorB > 0.0) CShader.colorB -= 0.1; } } proc listen() { A.listening = 1; A.changeState = 0; $newSphere += (rand(0,1) * 0.001); A_top.rotateX = 180; A.rotateX = $rotSphere * 30; if (A.scaleX > 1.0) { A.scaleX -= 0.005; A.scaleY -= 0.005; A.scaleZ -= 0.005; } if (A.scaleX < 1.0) { A.scaleX += 0.005; A.scaleY += 0.005; A.scaleZ += 0.005; } if (AShader.colorR > 0.0) // listening, let's turn blue AShader.colorR -= 0.1; if (AShader.colorG > 0.0) AShader.colorG -= 0.1; if (AShader.colorB < 1.0) AShader.colorB += 0.1; if ( $listenCounter <= 0.05 ) print("Wow, interesting, you don't say." + "\n"); else if ( $listenCounter <= 0.1 ) print("Uh, huh, ok yea sure." + "\n"); $listenCounter += 0.001; $stateChange += 0.001; if ( $Name == "B" ) { B_top.rotateX = 140; if (B.scaleX > 1.0) { B.scaleX -= 0.005; B.scaleY -= 0.005; B.scaleZ -= 0.005; } if (B.scaleX < 1.0) { B.scaleX += 0.005; B.scaleY += 0.005; B.scaleZ += 0.005; } if (BShader.colorR > 0.5) // listening, let's turn back to grey BShader.colorR -= 0.1; if (BShader.colorG > 0.5) BShader.colorG -= 0.1; if (BShader.colorB > 0.5) BShader.colorB -= 0.1; if (BShader.colorR < 0.5) // listening, let's turn back to grey BShader.colorR += 0.1; if (BShader.colorG < 0.5) BShader.colorG += 0.1; if (BShader.colorB < 0.5) BShader.colorB += 0.1; } else if ( $Name == "C" ) { C_top.rotateX = 140; if (C.scaleX > 1.0) { C.scaleX -= 0.005; C.scaleY -= 0.005; C.scaleZ -= 0.005; } if (C.scaleX < 1.0) { C.scaleX += 0.005; C.scaleY += 0.005; C.scaleZ += 0.005; } if (CShader.colorR > 0.5) // listening, let's turn back to grey CShader.colorR -= 0.1; if (CShader.colorG > 0.5) CShader.colorG -= 0.1; if (CShader.colorB > 0.5) CShader.colorB -= 0.1; if (CShader.colorR < 0.5) // listening, let's turn back to grey CShader.colorR += 0.1; if (CShader.colorG < 0.5) CShader.colorG += 0.1; if (CShader.colorB < 0.5) CShader.colorB += 0.1; } if ( $secondSphere && !C.moving && !B.moving ) { B_top.rotateX = 140; if (B.scaleX > 1.0) { B.scaleX -= 0.005; B.scaleY -= 0.005; B.scaleZ -= 0.005; } if (B.scaleX < 1.0) { B.scaleX += 0.005; B.scaleY += 0.005; B.scaleZ += 0.005; } if (BShader.colorR > 0.5) // listening, let's turn back to grey BShader.colorR -= 0.1; if (BShader.colorG > 0.5) BShader.colorG -= 0.1; if (BShader.colorB > 0.5) BShader.colorB -= 0.1; if (BShader.colorR < 0.5) // listening, let's turn back to grey BShader.colorR += 0.1; if (BShader.colorG < 0.5) BShader.colorG += 0.1; if (BShader.colorB < 0.5) BShader.colorB += 0.1; C_top.rotateX = 140; if (C.scaleX > 1.0) { C.scaleX -= 0.005; C.scaleY -= 0.005; C.scaleZ -= 0.005; } if (C.scaleX < 1.0) { C.scaleX += 0.005; C.scaleY += 0.005; C.scaleZ += 0.005; } if (CShader.colorR > 0.5) // listening, let's turn back to grey CShader.colorR -= 0.1; if (CShader.colorG > 0.5) CShader.colorG -= 0.1; if (CShader.colorB > 0.5) CShader.colorB -= 0.1; if (CShader.colorR < 0.5) // listening, let's turn back to grey CShader.colorR += 0.1; if (CShader.colorG < 0.5) CShader.colorG += 0.1; if (CShader.colorB < 0.5) CShader.colorB += 0.1; } } proc scared() { A.scared = 1; A.changeState = 0; $newSphere += (rand(0,1) * 0.001); A_top.rotateX = 180; if (A.scaleX > 0.5) // we are scared, shrink in fear { A.scaleX -= 0.005; A.scaleY -= 0.005; A.scaleZ -= 0.005; } if (AShader.colorR < 1.0) // we're scared and yellow AShader.colorR += 0.1; if (AShader.colorG < 1.0) AShader.colorG += 0.1; if (AShader.colorB > 0.0) AShader.colorB -= 0.1; if ( $scaredCounter <= 0.05 ) print("I'm sorry, please tell me what did I do wrong?" + "\n"); else if ( $scaredCounter <= 0.1 ) print("Whatever you say, I won't do it again, sorrrrrry." + "\n"); $scaredCounter += 0.001; $stateChange += 0.001; if ( $Name == "B" ) { if ( $sphereTalk ) { B_top.rotateX = 140; $sphereTalk = 0; } else { B_top.rotateX = 180; $sphereTalk = 1; } if (BShader.colorR < 1.0) // we are pissed off and red BShader.colorR += 0.1; if (BShader.colorG > 0.0) BShader.colorG -= 0.1; if (BShader.colorB > 0.0) BShader.colorB -= 0.1; if (B.scaleX <= 2.5) // scale head up we are mad { B.scaleX += 0.005; B.scaleY += 0.005; B.scaleZ += 0.005; } } else if ( $Name == "C" ) { if ( $sphereTalk ) { C_top.rotateX = 140; $sphereTalk = 0; } else { C_top.rotateX = 180; $sphereTalk = 1; } if (CShader.colorR < 1.0) // we are pissed off and red CShader.colorR += 0.1; if (CShader.colorG > 0.0) CShader.colorG -= 0.1; if (CShader.colorB > 0.0) CShader.colorB -= 0.1; if (C.scaleX <= 2.5) // scale head up we are mad { C.scaleX += 0.005; C.scaleY += 0.005; C.scaleZ += 0.005; } } if ( $scaredCounter <= 0.05 ) print("MWAHAHA!!! Look who's in charge NOW!!!" + "\n" ); else if ( $scaredCounter <= 0.10 ) print("YOU SUCK!!! you pansy what's your problem" + "\n" ); if ( $secondSphere && !C.moving && !B.moving ) { if ( $sphereTalk ) { B_top.rotateX = 140; $sphereTalk = 0; } else { B_top.rotateX = 180; $sphereTalk = 1; } if (BShader.colorR < 1.0) // we are pissed off and red BShader.colorR += 0.1; if (BShader.colorG > 0.0) BShader.colorG -= 0.1; if (BShader.colorB > 0.0) BShader.colorB -= 0.1; if (B.scaleX <= 3.0) // scale head up we are mad { B.scaleX += 0.005; B.scaleY += 0.005; B.scaleZ += 0.005; } if ( $sphereTalk ) { C_top.rotateX = 140; $sphereTalk = 0; } else { C_top.rotateX = 180; $sphereTalk = 1; } if (CShader.colorR < 1.0) // we are pissed off and red CShader.colorR += 0.1; if (CShader.colorG > 0.0) CShader.colorG -= 0.1; if (CShader.colorB > 0.0) CShader.colorB -= 0.1; if (C.scaleX <= 3.0) // scale head up we are mad { C.scaleX += 0.005; C.scaleY += 0.005; C.scaleZ += 0.005; } } } proc leave() { // everybody is mad here so we are all red and huffy puffy if (AShader.colorR < 1.0) AShader.colorR += 0.1; if (AShader.colorG > 0.0) AShader.colorG -= 0.1; if (AShader.colorB > 0.0) AShader.colorB -= 0.1; BShader.colorR = 1.0; BShader.colorG = 0; BShader.colorB = 0; CShader.colorR = 1.0; CShader.colorG = 0; CShader.colorB = 0; // scale everyone to around 1.0 but it enlarges and deflates like REALLY mad if (A.scaleX > 1.0) { A.scaleX -= 0.15; A.scaleY -= 0.15; A.scaleZ -= 0.15; } if (A.scaleX < 1.0) { A.scaleX += 0.15; A.scaleY += 0.15; A.scaleZ += 0.15; } if (B.scaleX > 1.0) { B.scaleX -= 0.15; B.scaleY -= 0.15; B.scaleZ -= 0.15; } if (B.scaleX < 1.0) { B.scaleX += 0.15; B.scaleY += 0.15; B.scaleZ += 0.15; } if (C.scaleX > 1.0) { C.scaleX -= 0.15; C.scaleY -= 0.15; C.scaleZ -= 0.15; } if (C.scaleX < 1.0) { C.scaleX += 0.15; C.scaleY += 0.15; C.scaleZ += 0.15; } A.rotateY = 180; A_top.rotateX = 180; B_top.rotateX = 180; C_top.rotateX = 180; if ( A.translateZ > 2.50 ) A.translateZ -= 0.20; } /****************************************************** * If its frame 1 we will set the inital random values * * for sphere A's desire to go to the bathroom, * * kitchen, or outside to talk to friends. * ******************************************************/ if ( frame == 1 ) { // get a random value between 0 and 1 for our to do next values if ( !A.moving ) moving(); //print(A.useBathroom + " " + A.gotoKitchen + " " + A.goOutside + "\n"); float $testA = A.useBathroom; float $testB = A.gotoKitchen; float $testC = A.goOutside; $normalizeMe = <<$testA, $testB, $testC>>; // normalize the random values so they are all no larger than 1 total $normalizeMe = unit($normalizeMe); A.useBathroom = $normalizeMe.x; // get value for going to the bathroom A.gotoKitchen = $normalizeMe.y; // get value for going to the kitchen to eat A.goOutside = $normalizeMe.z; // get value for going outside } /****************************************************** * Now we dive into the nitty gritty of the expression * * here we check to see which state sphere A is in * * then call that states process to execute the * * actions to represent that state visually. * ******************************************************/ else { $rotSphere = -1 * rand(0,1); // rotation value for mouth if ( A.useBathroom > A.gotoKitchen && A.useBathroom > A.goOutside ) gotoBathroom(); else if ( A.gotoKitchen > A.useBathroom && A.gotoKitchen > A.goOutside ) gotoKitchen(); else if ( A.goOutside > A.useBathroom && A.goOutside > A.gotoKitchen ) goOutside(); if ( A.outside ) { A.useBathroom = 0; A.gotoKitchen = 0; A.goOutside = 0; $influence = 0.75; if ( A.changeState ) changeTheState(); if ( $BFirst > $CFirst ) { B.moving = 1; if ( B.translateX > 3 ) B.translateX -= 0.25; if ( B.translateX == 3 ) { B.talking = 1; B.introduction = 1; B.moving = 0; } $CFirst = 0; } else { C.moving = 1; if ( C.translateZ > 23 ) C.translateZ -= 0.25; if ( C.translateZ == 23 ) { C.talking = 1; C.introduction = 1; C.moving = 0; } } /************************************************ * Here I begin the talking and state change * * portion of this expression. The first half * * will be used to determine wether sphere A * * should be talking, listening, yelling, or * * scared, while sphere A's current state will * * determine what sphere B or C is doing at * * that time. * ************************************************/ if ( B.introduction && A.introduction ) { if ( !B.moving && !A.moving ) A.changeState = 1; $Name = "B"; if ( A.rotateY < 25 ) { A.rotateY = 25.0; B.rotateY = 245.0; } print("Hi, my name is " + $Name + "\n"); print("Hi " + $Name + " my name is " + $AName + "\n"); B.introduction = 0; A.introduction = 0; $conversing = 1; } else if ( C.introduction && A.introduction ) { if ( !B.moving && !A.moving ) A.changeState = 1; $Name = "C"; print("Hi, my name is " + $Name + "\n"); print("Hi " + $Name + " my name is " + $AName + "\n"); C.introduction = 0; A.introduction = 0; $conversing = 1; } /************************** * Begin the talking stuff * **************************/ // I feel like talking now, so I shall if ( $talking > $yelling && $talking > $listening && $talking > $scared && $conversing ) talk(); // DAMMIT I AM PISSED now I am going to yell at him/her/it and teache him/her/it a lesson if ( $yelling > $talking && $yelling > $listening && $yelling > $scared && $conversing ) yell(); // Uh huh, sounds like he/she/it has something to say so I shall listen if ( $listening > $talking && $listening > $yelling && $listening > $scared && $conversing ) listen(); // What did I do wrong??? I'm sorry I'm so scared look at me cower if ( $scared > $talking && $scared > $yelling && $scared > $listening && $conversing ) scared(); if ( A.leave ) leave(); if ( $secondSphere && !C.moving && !B.moving ) { A.rotateY = 12.5; B.rotateY = 245.0; } // check if there is to be a state change if ( $stateChange >= 0.1 ) { if ( $newSphere > 0.55 ) { if ( $BFirst > $CFirst ) { $CFirst = $BFirst; $Bfirst = 0.0; } else { $BFirst = $CFirst; $CFirst = 0.0; } $secondSphere = 1; } $newSphere *= $newSphere; if ( $yellCounter > 0.250 ) A.leave = 1; else { $stateChange = 0.0; A.changeState = 1; } } } }