JSFiddle - React, Tailwind, and code Playground
by manecocomph
HTML
<canvas id="fakeImg"></canvas>
<h5>About author: <a target='_blank' href='https://blog.tianxiaohui.com'>Tian Xiaohui</a></h5>
JavaScript
function drawTextAlongArc(context, str, centerX, centerY, radius, angle) {
var len = str.length, s;
context.save();
context.translate(centerX, centerY);
context.rotate(-1 * angle / 2);
context.rotate(-1 * (angle / len) / 2);
for (var n = 0; n < len; n++) {
context.rotate(angle / len);
context.save();
context.translate(0, -1 * radius);
s = str[n];
context.fillText(s, -14, 0);
context.restore();
}
context.restore();
}
// init score
var score = 849;
var screenWidth = 640;
var screenHeight = 1080;
var generalWordColor = 'gray';
var halfScreenWidth = screenWidth / 2;
// calculate angle & desc
var scoreDesc = "信用极好";
var angle = 1.8;
if (score <= 350) {
angle = 0.9;
scoreDesc = "信用极差";
} else if (score > 350 && score <= 550) {
angle = 0.9 + ((score - 350) / 200) * ((2.1 - 0.9) / 5);
scoreDesc = "信用较差";
} else if (score > 550 && score <= 700) {
angle = 0.9 + (2.1 - 0.9) / 5 + ((score - 550) / 150) * ((2.1 - 0.9) / 5 * 3);
if (score > 550 && score <= 600) {
scoreDesc = "信用中等";
} else if (score > 600 && score <= 650) {
scoreDesc = "信用良好";
} else {
scoreDesc = "信用优秀";
}
} else if (score > 700 && score <= 950) {
angle = 0.9 + (2.1 - 0.9) / 5 * 4 + ((score - 700) / 250) * ((2.1 - 0.9) / 5);
scoreDesc = "信用极好";
} else {
angle = 2.1;
scoreDesc = "信用爆棚";
}
// get canvas and set width & height
var canvas = document.getElementById("fakeImg");
canvas.setAttribute("width", screenWidth);
canvas.setAttribute("height", screenHeight);
var ctx = canvas.getContext("2d");
///// 开始画顶端 ////////
//header
ctx.fillStyle = '#000000';
ctx.fillRect(0, 0, screenWidth, 90);
//手机顶端
ctx.fillStyle = '#FFFFFF';
ctx.font = '10px Arial';
ctx.fillText("中国移动 4G", 5, 12);
ctx.fillText("13:59", halfScreenWidth - 22, 12);
ctx.fillRect(screenWidth - 50, 3, 10, 9);
ctx.strokeStyle = '#FFFFFF';
ctx.strokeRect(screenWidth - 50, 3, 30, 9);
ctx.font = '4px...