briochemc

brioche SM texture script

Sep 17th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          Borgen_tiles_script
  3. // @namespace     http://www.reddit.com/user/NewCompte
  4. // @description   ask Borgen and brioche
  5. // @include       http://*.koalabeast.com:*
  6. // @license       GPL
  7. // @author        NewCompte, modified by brioche
  8. // @version       1
  9. // ==/UserScript==
  10.  
  11. function myRotatingBallsScript() {
  12.     tagpro.ready(function(){
  13.         //This is important.
  14.         if(tagpro.events.drawPlayer)
  15.             return;
  16.        
  17.         // Test for oltp
  18.         var BorgenBallsInside = new Image();
  19.         BorgenBallsInside.src = "http://i.imgur.com/foW9vMF.png";
  20.         var BorgenBallsLighting = new Image();
  21.         BorgenBallsLighting.src = "http://i.imgur.com/TChUSRB.png";
  22.         var BorgenBallsBorders = new Image();
  23.         BorgenBallsBorders.src = "http://i.imgur.com/FQbe57J.png";
  24.        
  25.         // Borgen texture pack:
  26.         document.getElementById("tiles").src = "http://i.imgur.com/j9dgpUQ.png";
  27.         document.getElementById("splats").src = "http://i.imgur.com/3m8yX7z.png";
  28.         document.getElementById("speedpad").src = "http://i.imgur.com/q1Jylmv.png";
  29.         document.getElementById("speedpadred").src = "http://i.imgur.com/IoAJ7Tj.png";
  30.         document.getElementById("speedpadblue").src = "http://i.imgur.com/Ycxcudc.png";
  31.         document.getElementById("portal").src = "http://i.imgur.com/qDUaiqD.png";
  32.  
  33.         //Wait 1 second then redraw textures
  34.         setTimeout(tagpro.api.redrawBackground,1000);
  35.        
  36.         function componentToHex(c) {
  37.             var hex = c.toString(16);
  38.             return hex.length == 1 ? "0" + hex : hex;
  39.         }
  40.  
  41.         function rgbToHex(r, g, b) {
  42.             return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
  43.         }
  44.        
  45. /**
  46.  * HSV to RGB color conversion
  47.  *
  48.  * H runs from 0 to 360 degrees
  49.  * S and V run from 0 to 100
  50.  *
  51.  * Ported from the excellent java algorithm by Eugene Vishnevsky at:
  52.  * http://www.cs.rit.edu/~ncs/color/t_convert.html
  53.  */
  54. function hsvToRgb(h, s, v) {
  55.     var r, g, b;
  56.     var i;
  57.     var f, p, q, t;
  58.    
  59.     // Make sure our arguments stay in-range
  60.     h = Math.max(0, Math.min(360, h));
  61.     s = Math.max(0, Math.min(100, s));
  62.     v = Math.max(0, Math.min(100, v));
  63.    
  64.     // We accept saturation and value arguments from 0 to 100 because that's
  65.     // how Photoshop represents those values. Internally, however, the
  66.     // saturation and value are calculated from a range of 0 to 1. We make
  67.     // That conversion here.
  68.     s /= 100;
  69.     v /= 100;
  70.    
  71.     if(s == 0) {
  72.         // Achromatic (grey)
  73.         r = g = b = v;
  74.         return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
  75.     }
  76.    
  77.     h /= 60; // sector 0 to 5
  78.     i = Math.floor(h);
  79.     f = h - i; // factorial part of h
  80.     p = v * (1 - s);
  81.     q = v * (1 - s * f);
  82.     t = v * (1 - s * (1 - f));
  83.  
  84.     switch(i) {
  85.         case 0:
  86.             r = v;
  87.             g = t;
  88.             b = p;
  89.             break;
  90.            
  91.         case 1:
  92.             r = q;
  93.             g = v;
  94.             b = p;
  95.             break;
  96.            
  97.         case 2:
  98.             r = p;
  99.             g = v;
  100.             b = t;
  101.             break;
  102.            
  103.         case 3:
  104.             r = p;
  105.             g = q;
  106.             b = v;
  107.             break;
  108.            
  109.         case 4:
  110.             r = t;
  111.             g = p;
  112.             b = v;
  113.             break;
  114.            
  115.         default: // case 5:
  116.             r = v;
  117.             g = p;
  118.             b = q;
  119.     }
  120.    
  121.     return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
  122. }
  123.            
  124.         if (tagpro.events.drawPlayer) {return;}
  125.            
  126.         tagpro.events.register({
  127.             drawPlayer: function(player, context, drawPos, TILESIZE) {
  128.                
  129.                 // Draw rotating inside
  130.                 context.save();
  131.                 context.globalAlpha = 0.7; // Here is transparency
  132.                 context.translate(drawPos.x + (TILESIZE / 2) * (1 / tagpro.zoom), drawPos.y + (TILESIZE / 2) * (1 / tagpro.zoom));
  133.                 context.rotate(player.angle);
  134.                 context.translate(-drawPos.x - (TILESIZE / 2) * (1 / tagpro.zoom), -drawPos.y - (TILESIZE / 2) * (1 / tagpro.zoom));
  135.                 if (player.team == 1)
  136.                 context.drawImage(BorgenBallsInside, 40, 0, 40, 40, drawPos.x, drawPos.y, 40 / tagpro.zoom, 40 / tagpro.zoom);
  137.                 if (player.team == 2)
  138.                 context.drawImage(BorgenBallsInside, 0, 0, 40, 40, drawPos.x, drawPos.y, 40 / tagpro.zoom, 40 / tagpro.zoom);
  139.                 context.restore();
  140.                
  141.                 // Draw muscle cup lighting
  142.                 context.save();
  143.                 context.globalAlpha = 0.7; // Here is transparency
  144.                 context.drawImage(BorgenBallsLighting, 0, 0, 40, 40, drawPos.x, drawPos.y, 40 / tagpro.zoom, 40 / tagpro.zoom);
  145.                 context.restore();
  146.                
  147.                 // Draw rotating border
  148.                 context.save();
  149.                 context.globalAlpha = 1; // Here is transparency
  150.                 context.translate(drawPos.x + (TILESIZE / 2) * (1 / tagpro.zoom), drawPos.y + (TILESIZE / 2) * (1 / tagpro.zoom));
  151.                 context.rotate(player.angle);
  152.                 context.translate(-drawPos.x - (TILESIZE / 2) * (1 / tagpro.zoom), -drawPos.y - (TILESIZE / 2) * (1 / tagpro.zoom));
  153.                 context.drawImage(BorgenBallsBorders, 40, 0, 40, 40, drawPos.x, drawPos.y, 40 / tagpro.zoom, 40 / tagpro.zoom);
  154.                 context.restore();
  155.                
  156.                 // Draw pixel perfect rolling bomb
  157.                 if (player.bomb && Math.round(Math.random() * 4) == 1) {
  158.                     context.fillStyle = "rgba(255, 255, 0, .60)";
  159.                     context.beginPath();
  160.                     context.arc(drawPos.x + (TILESIZE / 2) * (1 / tagpro.zoom), drawPos.y + (TILESIZE / 2) * (1 / tagpro.zoom), 17  * (1 / tagpro.zoom), 0, Math.PI*2, true);
  161.                     context.closePath();
  162.                     context.fill();
  163.                 };
  164.  
  165.                 // Draw pixel perfect tagpro
  166.                 if (player.tagpro) {
  167.                     var curr = new Date();
  168.                     var tagpro360 = Math.round((new Date).getTime()/1000*360*3) % 360 ;
  169.                     var tagproRGB = hsvToRgb(tagpro360, 100, 100) ;
  170.                     var tagproHex = rgbToHex(tagproRGB[0],tagproRGB[1],tagproRGB[2]) ;
  171.                     context.strokeStyle = tagproHex ;
  172.                     var tagproString = tagproRGB.toString() ;
  173.                     context.fillStyle = "rgba(" + tagproString + ", .00)";
  174.                     context.lineWidth = 2 * (1 / tagpro.zoom);
  175.                     context.beginPath();
  176.                     context.arc(drawPos.x + (TILESIZE / 2) * (1 / tagpro.zoom), drawPos.y + (TILESIZE / 2) * (1 / tagpro.zoom), 16  * (1 / tagpro.zoom), 0, Math.PI*2, true);
  177.                     context.closePath();
  178.                     if (!player.bomb)
  179.                         context.fill();
  180.                     context.stroke();
  181.                 }
  182.  
  183.             }
  184.         });
  185.     });
  186. }
  187.  
  188. var source = "("+ myRotatingBallsScript + ")()";
  189. var script = document.createElement('script');
  190. script.setAttribute("type", "application/javascript");
  191. script.textContent = source;
  192.  
  193. document.body.appendChild(script);
Add Comment
Please, Sign In to add comment