Skip to content

Instantly share code, notes, and snippets.

@deleteme
Created December 3, 2008 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deleteme/31423 to your computer and use it in GitHub Desktop.
Save deleteme/31423 to your computer and use it in GitHub Desktop.
undefined
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>All work and no play makes Jack a dull boy.</title>
<style type="text/css" media="screen">
body {
position: relative;
}
#paper {
bottom: 0;
font-family: Courier, monospace;
font-size: 24px;
font-weight: bold;
left: 80px;
line-height: 24px;
min-height: 24px;
position: absolute;
width: 630px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.2/effects.js"></script>
<script type="text/javascript">
var DyingProgrammer = new Class.create({
initialize: function(phrase){
this.phrase = phrase.split('');
this.delayRange = [0, 1];
this.i = this.lines = 0;
document.observe('dom:loaded', this.work.bind(this));
},
alignPage: function(){
document.body.setStyle({ height: document.viewport.getHeight() - 24 + 'px' });
this.paper.setStyle({ bottom: '0px' });
},
work: function(){
this.paper = $('paper');
this.type();
},
type: function(){
this.alignPage();
if (this.atEndOfPhrase()) {
this.insertNewLine();
} else {
this.insertCharacter();
}
},
queueType: function(){
this.type.bind(this).delay(Math.ceil(this.delayRange.length * Math.random()) / 10);
},
atEndOfPhrase: function(){
return (this.i > this.phrase.length);
},
insertNewLine: function(){
this.paper.morph({ bottom: 24 + 'px' },
{
afterFinish: function(){
this.paper.insert(new Element('br'));
this.queueType();
}.bind(this),
duration: .2,
transition: Effect.Transitions.sinoidal
}
);
this.i = 0;
this.lines++;
},
insertCharacter: function(){
this.paper.insert(this.phrase[this.i]);
this.i++;
this.queueType();
}
});
var matt = new DyingProgrammer('All work and no play makes Jack a dull boy.');
</script>
</head>
<body>
<p id="paper"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment