Recent Posts
None | 1 sec ago
PHP | 26 sec ago
Bash | 56 sec ago
None | 59 sec ago
None | 1 min ago
None | 1 min ago
PHP | 1 min ago
XML | 1 min ago
None | 1 min ago
PHP | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By mrtin on the 25th of Nov 2009 03:59:34 PM Download | Raw | Embed | Report
  1. /**
  2.  * Hi-ReS! Stats / MooTools Port
  3.  *
  4.  * Released under MIT license:
  5.  * http://www.opensource.org/licenses/mit-license.php
  6.  *
  7.  * How to use:
  8.  *
  9.  * new Stats(
  10.  *              fps(int),
  11.  *              destination(dom-node)
  12.  *              [,
  13.  *                      left(int),
  14.  *                      top(int),
  15.  *                      position:fixed(bool)
  16.  *              ]
  17.  *              ).go();
  18.  *
  19.  *
  20.  * //element.appendChild( Stats.init(60) );
  21.  *
  22.  * version log:
  23.  *
  24.  *      09.06.18                1.1             Mr.doob                 + Firefox support
  25.  *      09.06.10                1.0             Mr.doob                 + First version
  26.  **/
  27.  
  28. var Stats = new Class({
  29.         baseFps: null,
  30.        
  31.         timer: null,
  32.         timerStart: null,
  33.         timerLast: null,
  34.         fps: null,
  35.         ms: null,
  36.        
  37.         container: null,
  38.         fpsText: null,
  39.         msText: null,
  40.         memText: null,
  41.         memMaxText: null,
  42.        
  43.         graph: null,
  44.         graphData: null,
  45.        
  46.         initialize: function(userfps,destination,$left,$top,$fixed)
  47.         {
  48.                 this.baseFps = userfps;
  49.                
  50.                 this.timer = 0;
  51.                 this.timerStart = new Date() - 0;
  52.                 this.timerLast = 0;
  53.                 this.fps = 0;
  54.                 this.ms = 0;
  55.                
  56.                 var container = new Element('div',{
  57.                         id : '__stats_container',
  58.                         styles : {
  59.                                 fontFamily:'arial',
  60.                                 fontSize:'10px',
  61.                                 backgroundColor:'#000033',
  62.                                 width:70,
  63.                                 paddingTop:2,
  64.                                 position:$fixed?'fixed':'absolute',
  65.                                 zIndex:9999,
  66.                                 left : $left || 0,
  67.                                 top : $top || 0
  68.                         }
  69.                 });
  70.                
  71.                 new Element('div',{
  72.                         id : '__stats_fpsText',
  73.                         text : 'FPS:',
  74.                         styles : {
  75.                                 color : '#ffff00',
  76.                                 marginLeft : 3,
  77.                                 marginBottom : -3,
  78.                         }
  79.                 }).inject(container);
  80.  
  81.                 new Element('div',{
  82.                         id : '__stats_msText',
  83.                         text : 'MS:',
  84.                         styles : {
  85.                                 color : '#ffff00',
  86.                                 marginLeft : 3,
  87.                                 marginBottom : -3,
  88.                         }
  89.                 }).inject(container);
  90.  
  91.                 new Element('div',{
  92.                         id : '__stats_memText',
  93.                         text : 'MEM:',
  94.                         styles : {
  95.                                 color : '#ffff00',
  96.                                 marginLeft : 3,
  97.                                 marginBottom : -3,
  98.                         }
  99.                 }).inject(container);
  100.  
  101.                 new Element('div',{
  102.                         id : '__stats_maxText',
  103.                         text : 'MAX:',
  104.                         styles : {
  105.                                 color : '#ffff00',
  106.                                 marginLeft : 3,
  107.                                 marginBottom : 3,
  108.                         }
  109.                 }).inject(container);
  110.        
  111.                 var canvas = new Element('canvas',{
  112.                         id : '__stats_canvas',
  113.                         height : 50,
  114.                         width : 70
  115.                 }).inject(container);  
  116.                
  117.                 this.graph = canvas.getContext("2d");
  118.                 this.graph.fillStyle = '#000033';
  119.                 this.graph.fillRect(0, 0, canvas.width, canvas.height );
  120.                
  121.                 this.graphData = this.graph.getImageData(0, 0, canvas.width, canvas.height);
  122.                
  123.                 container.inject(destination);
  124.         },
  125.        
  126.         go : function()
  127.         {
  128.                 this.update.periodical( 1000/ this.baseFps, this);             
  129.         },
  130.        
  131.         update: function()
  132.         {
  133.                 this.timer = new Date() - this.timerStart;
  134.  
  135.                 if ((this.timer - 1000) > this.timerLast)
  136.                 {
  137.                         $('__stats_fpsText').set('text',"FPS: " + this.fps + " / " + this.baseFps);
  138.                         this.timerLast = this.timer;
  139.                
  140.                         this.graphData = this.graph.getImageData(0, 0, 69, 50);        
  141.                         this.graph.putImageData(this.graphData, 1, 0);
  142.                        
  143.                         this.graph.fillRect(0,0,1,50);
  144.                         this.graphData = this.graph.getImageData(0, 0, 1, 50);
  145.                        
  146.                         var index = ( Math.floor(50 - Math.min(50, (this.fps / this.baseFps) * 50)) * 4 );
  147.                         this.graphData.data[index] = this.graphData.data[index + 1] = 255;
  148.                        
  149.                         index = ( Math.floor(50 - Math.min(50, (this.timer - this.ms) * .5)) * 4 );
  150.                         this.graphData.data[index + 1] = 255;                  
  151.                        
  152.                         this.graph.putImageData (this.graphData, 0, 0);
  153.                        
  154.                         this.fps = 0;
  155.                 }
  156.                
  157.                 ++this.fps;
  158.                
  159.                 $('__stats_msText').set('text',"MS: " + (this.timer - this.ms));
  160.                 this.ms = this.timer;
  161.         }
  162.        
  163. });
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: