You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
3.4 KiB
HTML
144 lines
3.4 KiB
HTML
5 years ago
|
<HTML>
|
||
|
<HEAD>
|
||
|
<meta charset="utf-8">
|
||
|
<TITLE>Eliza (elizabot.js)</TITLE>
|
||
|
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="elizabot.js"></SCRIPT>
|
||
|
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="elizadata.js"></SCRIPT>
|
||
|
<link rel="stylesheet" type="text/css" href="./clippy.js/build/clippy.css" media="all">
|
||
|
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
|
||
|
var eliza = new ElizaBot();
|
||
|
var elizaLines = new Array();
|
||
|
|
||
|
var displayCols = 60;
|
||
|
var displayRows = 20;
|
||
|
|
||
|
function elizaReset() {
|
||
|
eliza.reset();
|
||
|
elizaLines.length = 0;
|
||
|
elizaStep();
|
||
|
}
|
||
|
</SCRIPT>
|
||
|
<style type="text/css">
|
||
|
textarea {
|
||
|
display: none;
|
||
|
}
|
||
|
|
||
|
.clippy {
|
||
|
transform: scale(0.7, 0.7);
|
||
|
}
|
||
|
</style>
|
||
|
</HEAD>
|
||
|
|
||
|
<BODY TOPMARGIN="0" LEFTMARGIN="0" RIGHTMARGIN="0" BOTTOMMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0" STYLE="border:0" onload="window.setTimeout('elizaReset()',100)"><A NAME="top"></A>
|
||
|
|
||
|
<CENTER>
|
||
|
<TABLE BORDER="0" CELLSPACING="10" CELLPADDING="0">
|
||
|
<FORM NAME="e_form" onsubmit="elizaStep();return false">
|
||
|
<TR><TD COLSPAN="2"><TEXTAREA NAME="e_display" COLS="60" ROWS="20"></TEXTAREA></TD></TR>
|
||
|
<TR VALIGN="middle">
|
||
|
<TD><INPUT TYPE="text" NAME="e_input" SIZE="50"></TD>
|
||
|
<TD ALIGN="right"><INPUT TYPE="submit" VALUE=" Talk "></TD>
|
||
|
</TR>
|
||
|
</FORM>
|
||
|
|
||
|
<script src="./jquery.1.7.min.js"></script>
|
||
|
<script src="./clippy.js/build/clippy.js"></script>
|
||
|
<script type="text/javascript">
|
||
|
var rpl;
|
||
|
|
||
|
function getRandomInt(max) {
|
||
|
return Math.floor(Math.random() * Math.floor(max));
|
||
|
};
|
||
|
|
||
|
|
||
|
function elizaStep() {
|
||
|
var f = document.forms.e_form;
|
||
|
var userinput = f.e_input.value;
|
||
|
if (eliza.quit) {
|
||
|
f.e_input.value = '';
|
||
|
if (confirm("This session is over.\nStart over?")) elizaReset();
|
||
|
f.e_input.focus();
|
||
|
return;
|
||
|
}
|
||
|
else if (userinput != '') {
|
||
|
var usr = 'YOU: ' + userinput;
|
||
|
rpl = eliza.transform(userinput);
|
||
|
elizaLines.push(usr);
|
||
|
elizaLines.push(rpl);
|
||
|
|
||
|
clippy.load('Clippy', function(agent){
|
||
|
agent.show();
|
||
|
|
||
|
//agent.play('Searching');
|
||
|
|
||
|
//agent.animate();
|
||
|
|
||
|
//agent.animations();
|
||
|
|
||
|
//agent.moveTo();
|
||
|
|
||
|
//agent.play();
|
||
|
|
||
|
|
||
|
agent.moveTo( getRandomInt(screen.width-100), getRandomInt(screen.height-200) );
|
||
|
agent.speak(rpl);
|
||
|
agent.animate();
|
||
|
|
||
|
|
||
|
//agent.gestureAt(200,200);
|
||
|
|
||
|
//agent.stopCurrent();
|
||
|
|
||
|
//agent.stop();
|
||
|
|
||
|
});
|
||
|
// display nicely
|
||
|
// (fit to textarea with last line free - reserved for extra line caused by word wrap)
|
||
|
var temp = new Array();
|
||
|
var l = 0;
|
||
|
for (var i=elizaLines.length-1; i>=0; i--) {
|
||
|
l += 1 + Math.floor(elizaLines[i].length/displayCols);
|
||
|
if (l >= displayRows) break
|
||
|
else temp.push(elizaLines[i]);
|
||
|
}
|
||
|
elizaLines = temp.reverse();
|
||
|
f.e_display.value = elizaLines.join('\n');
|
||
|
}
|
||
|
else if (elizaLines.length == 0) {
|
||
|
// no input and no saved lines -> output initial
|
||
|
var initial = 'ELIZA: ' + eliza.getInitial();
|
||
|
elizaLines.push(initial);
|
||
|
f.e_display.value = initial + '\n';
|
||
|
clippy.load('Clippy', function(agent){
|
||
|
agent.show();
|
||
|
|
||
|
//agent.play('Searching');
|
||
|
|
||
|
//agent.animate();
|
||
|
|
||
|
//agent.animations();
|
||
|
|
||
|
//agent.moveTo();
|
||
|
|
||
|
//agent.play();
|
||
|
agent.animate();
|
||
|
agent.speak('Hi Im Clippy');
|
||
|
setTimeout(function(){ agent.speak('How do you do? Please tell me your problem.') }, 1000);
|
||
|
|
||
|
//agent.gestureAt(200,200);
|
||
|
|
||
|
//agent.stopCurrent();
|
||
|
|
||
|
//agent.stop();
|
||
|
|
||
|
});
|
||
|
}
|
||
|
f.e_input.value = '';
|
||
|
f.e_input.focus();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
</script>
|
||
|
</BODY>
|
||
|
</HTML>
|