<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<canvas id="canvas"></canvas>
</body>
</html>
body{
background: #555;
}
draw();
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
var W = canvas.width = 120; //设置 Canvas 宽度
var H = canvas.height = 120;
var per = 0.8
// 使图形在画布中居中
ctx.translate(W / 2, H / 2)
// 绘制文字
ctx.fillStyle = 'yellow';
ctx.font="60px Arial";
ctx.textAlign="center";
ctx.fillText(`${per * 100}`, 0, 20)
// 保存当前画布状态
ctx.save()
// 旋转-90度
ctx.rotate(-90*(Math.PI/180))
// 圆边的宽度
var lineWidth = ctx.lineWidth = 10
// 底圆的颜色
ctx.strokeStyle = "#ddd"
// 开始绘制
ctx.beginPath();
// 创建圆(中心点x轴,中心点y轴,半径,起始角度,结束角度,顺时针true/逆时针false)
ctx.arc(0, 0, (W / 2) - lineWidth, 0, 2 * Math.PI)
// 结束绘制
ctx.closePath();
// 在画布上显示绘制好的圆
ctx.stroke();
ctx.lineCap = "round"
ctx.strokeStyle = "#41C0E4"
ctx.beginPath();
ctx.arc(0, 0, (W / 2) - lineWidth, 0, 2 * Math.PI * per)
ctx.stroke();
// 销毁画布状态
ctx.restore()
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |