From 9d3c8c0e6e1a7ba43bf3dc19350d1dca68b657a3 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 10 Feb 2019 11:16:07 +0800 Subject: Initial commit. --- codeforces-rating-cmp/index.html | 80 +++++++++++++++++++ codeforces-rating-cmp/main.js | 168 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 codeforces-rating-cmp/index.html create mode 100755 codeforces-rating-cmp/main.js (limited to 'codeforces-rating-cmp') diff --git a/codeforces-rating-cmp/index.html b/codeforces-rating-cmp/index.html new file mode 100644 index 0000000..b13de8f --- /dev/null +++ b/codeforces-rating-cmp/index.html @@ -0,0 +1,80 @@ + + + + +Chrisoft::CodeForces Rating Comparator + + + + + + + + + + + +
+ Chrisoft::CodeForces Rating Comparator +
+ +
+
+ + + +
+
+ +
+ + diff --git a/codeforces-rating-cmp/main.js b/codeforces-rating-cmp/main.js new file mode 100755 index 0000000..fe3bd5d --- /dev/null +++ b/codeforces-rating-cmp/main.js @@ -0,0 +1,168 @@ +var users=new Array; +var animating=false; +var curTsL=0,curTsR=0; +var tarTsL=4294967296,tarTsR=0; +var curRtL=0,curRtR=0; +var tarRtL=9999,tarRtR=0; +var ctx; +var w,h; +var ratings=[0,1200,1400,1600,1900,2200,2300,2400,2600,2900,9999]; +var ratingbg=["rgba(128,128,128,0.6)","rgba(0,255,0,0.6)","rgba(3,168,158,0.6)","rgba(0,0,255,0.6)","rgba(160,0,160,0.6)","rgba(255,140,0,0.6)","rgba(255,140,0,0.6)","rgba(255,0,0,0.6)","rgba(224,0,0,0.6)","rgba(204,0,0,0.6)"]; +function init() +{ + ctx=document.getElementById("cvs").getContext("2d"); + w=document.getElementById("cvs").width; + h=document.getElementById("cvs").height; +} +function min(a,b){return ab?a:b;} +function randomColor(a) +{ + var h=Math.floor(Math.random()*30)*12; + return "hsla("+h+",90%,45%,"+a+")"; +} +function add() +{ + if(animating)return; + var req=new XMLHttpRequest(); + req.onload=function(){ + var r=JSON.parse(req.responseText); + if(r.status!=="OK")return; + if(!Array.isArray(r.result)||r.result.length==0)return; + r.maxr=0;r.minr=9999;r.maxt=0;r.mint=4294967296;r.selected=false; + r.color=randomColor(0.8);r.pendingremove=false;r.bold=false; + if(tarTsL==0)tarTsL=4294967296; + for(var i=0;itarRtR)tarRtR=1900,tarRtL=1000; + if(tarTsL>tarTsR)tarTsL=tarTsR=0; + animating=true; + window.requestAnimationFrame(update); +} +function morph(a,b,s) +{ + var ret=a;if(Math.abs(a-b)>s) + ret+=s*(b-a)/Math.abs(a-b); + else ret=b;return ret; +} +function interpolate(a,b,c,d,x) +{ + var A=(d-c)/(b-a),B=c-a*A; + return A*x+B; +} +function highlight(n,s) +{ + users[n].bold=s;window.requestAnimationFrame(update); +} +function update() +{ + var f=false; + if(curTsL===0&&curTsR===0) + {curTsL=tarTsL;curTsR=tarTsR;f=(tarTsL||tarTsR);} + else + { + f|=Math.abs(curTsL-tarTsL)>432000; + f|=Math.abs(curTsR-tarTsR)>432000; + curTsL=morph(curTsL,tarTsL,max(Math.abs(curTsL-tarTsL)/5,432000)); + curTsR=morph(curTsR,tarTsR,max(Math.abs(curTsR-tarTsR)/5,432000)); + } + if(curRtL===0&&curRtR===0) + {curRtL=tarRtL;curRtR=tarRtR;f=true;} + else + { + f|=Math.abs(curRtL-tarRtL)>10; + f|=Math.abs(curRtR-tarRtR)>10; + curRtL=morph(curRtL,tarRtL,max(Math.abs(curRtL-tarRtL)/5,10)); + curRtR=morph(curRtR,tarRtR,max(Math.abs(curRtR-tarRtR)/5,10)); + } + ctx.clearRect(0,0,w,h); + for(var i=0;i=0;--j) + { + if(users[i].result[j].drawRatingtarRtL){users[i].result[j].drawRating-=(max(tarRtR,users[i].result[j].newRating)-tarRtL)/20;f=true;} + else{users[i].result[j].drawRating=0;} + if(users[i].result[j].drawRating>users[i].result[j].newRating*0.8)break; + } + if(j==-1){users.splice(i,1);--i;continue;} + for(j=users[i].result.length-1;j>=0;--j) + if(users[i].result[j].ratingUpdateTimeSeconds