1 |
- function initTb(id,FENSHU,ftext,btext){var bs=3;var canvas=document.getElementById(id);var ctx=canvas.getContext("2d");var s1=170,s2=170;canvas.width=s1*bs;canvas.height=s2*bs;var W=canvas.width;var H=canvas.height;var cpt=canvas.parentNode;cpt.style.width=s1+"px";cpt.style.height=s2+"px";canvas.style["transform"]=canvas.style["-webkit-transform"]=canvas.style["-moz-transform"]="scale("+1/bs+") translate(-510px,-510px)";var degrees=0;var new_degrees=0;var difference=0;var color=FENSHU>=50?"#00bc8c":"#00bc8c";var bgcolor="#cce9e2";var text;var animation_loop,redraw_loop;var new_fs=FENSHU;if(new_fs==0){new_fs=.5}function init(){ctx.clearRect(0,0,W,H);var r=50;ctx.beginPath();ctx.strokeStyle=bgcolor;ctx.lineJoin="round";ctx.lineWidth=4*bs;ctx.arc(W/2,H/2,r*bs,0,Math.PI*2,false);ctx.stroke();ctx.beginPath();var radians=degrees*Math.PI/180;ctx.beginPath();ctx.strokeStyle=color;ctx.lineWidth=8*bs;ctx.arc(W/2,H/2,r*bs,0-90*Math.PI/180,radians-90*Math.PI/180,false);if(new_fs>.5)ctx.stroke();ctx.fillStyle="#00bc8c";var fm='"Lantinghei SC","Microsoft Yahei","Hiragino Sans GB","Helvetica Neue",Helvetica,Arial,sans-serif';ctx.font=18*bs+"px "+fm;text_width=ctx.measureText(ftext).width;ctx.fillText(ftext,W/2-text_width/2,H/2+10*bs);text=btext;ctx.font=16*bs+"px "+fm;text_width=ctx.measureText(text).width;ctx.fillText(text,W/2-text_width/2,H/2+80*bs)}function draw(){if(typeof animation_loop!=undefined)clearInterval(animation_loop);new_degrees=new_degrees+1;difference=new_degrees-degrees;animate_to()}function animate_to(){var fs=parseInt(new_fs/100*360);if(degrees==fs)clearInterval(animation_loop);if(degrees==fs)return;if(degrees<new_degrees)degrees++;else degrees--;degrees=fs;init()}draw()}function initTbOrange(id,FENSHU,ftext,btext){var bs=3;var canvas=document.getElementById(id);var ctx=canvas.getContext("2d");var s1=170,s2=170;canvas.width=s1*bs;canvas.height=s2*bs;var W=canvas.width;var H=canvas.height;var cpt=canvas.parentNode;cpt.style.width=s1+"px";cpt.style.height=s2+"px";canvas.style["transform"]=canvas.style["-webkit-transform"]=canvas.style["-moz-transform"]="scale("+1/bs+") translate(-510px,-510px)";var degrees=0;var new_degrees=0;var difference=0;var color=FENSHU>=50?"#00bc8c":"#ff6938";var bgcolor="#cce9e2";var text;var animation_loop,redraw_loop;var new_fs=FENSHU;function init(){ctx.clearRect(0,0,W,H);var r=50;ctx.beginPath();ctx.strokeStyle=bgcolor;ctx.lineJoin=ctx.lineCap="round";ctx.lineWidth=4*bs;ctx.arc(W/2,H/2,r*bs,0,Math.PI*2,false);ctx.stroke();ctx.beginPath();var radians=degrees*Math.PI/180;ctx.beginPath();ctx.strokeStyle=color;ctx.lineWidth=8*bs;ctx.arc(W/2,H/2,r*bs,0-90*Math.PI/180,radians-90*Math.PI/180,false);ctx.stroke();ctx.fillStyle="#00bc8c";var fm='"Lantinghei SC","Microsoft Yahei","Hiragino Sans GB","Helvetica Neue",Helvetica,Arial,sans-serif';ctx.font=18*bs+"px "+fm;text_width=ctx.measureText(ftext).width;ctx.fillText(ftext,W/2-text_width/2,H/2+10*bs);text=btext;ctx.font=16*bs+"px "+fm;ctx.fillStyle="#b8542e";text_width=ctx.measureText(text).width;ctx.fillText(text,W/2-text_width/2,H/2+80*bs)}function draw(){if(typeof animation_loop!=undefined)clearInterval(animation_loop);new_degrees=new_degrees+1;difference=new_degrees-degrees;animate_to()}function animate_to(){var fs=parseInt(new_fs/100*360);if(degrees==fs)clearInterval(animation_loop);if(degrees==fs)return;if(degrees<new_degrees)degrees++;else degrees--;degrees=fs;init()}draw()}
|