盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

怎么绘制圆角环形图形

时间:2024/7/12作者:未知来源:盾怪网教程人气:

[摘要]在很多进度条的形状上面的选择,大家都会选择环形图。那么今天就来教大家怎么用canvas怎么绘制圆角环形图,以及进度条模糊的解决方案,希望对你有所帮助* @param {type} radius 圆环...
在很多进度条的形状上面的选择,大家都会选择环形图。那么今天就来教大家怎么用canvas怎么绘制圆角环形图,以及进度条模糊的解决方案,希望对你有所帮助

* @param {type} radius 圆环半径
* @param {type} lineWidth 圆环宽度
* @param {type} strokeStyle 默认背景
* @param {type} fillStyleArray 数组,圆环色块颜色
* @param {type} capType 类型:round是圆角,square正方形顶帽,butt是正常
* @param {type} percentArray ,数字,每个占据的百分比
* @param {type} startAngle 开始的角度
*  @param {type} criclex,cricley 圆心坐标,一般是canvas的一半,例如:canvas给的宽度是250,高度是250,那么criclex是125

使用方法

           var canvas = document.getElementById('canvas');
           var ctx = canvas.getContext('2d');
           var ring = new Ring("80", "25", "#ccc", ["#a1b91d", "#e9636a", "#e7ba21"], "round");
           ring.drawRing(ctx, 2 * Math.PI / 3, [20, 50, 30],125,125);//占据的百分比分别是20%,50%,30%


源代码


源代码很简单,欢迎大家扩展!

 function Circle(radius, lineWidth, strokeStyle, fillStyleArray, capType) {
   this.radius = radius;    // 圆环半径
   this.lineWidth = lineWidth;  // 圆环边的宽度
   this.strokeStyle = strokeStyle; //边的颜色
   this.fillStyle = fillStyleArray;  //填充色
   this.lineCap = capType;}Circle.prototype.draw = function (ctx,criclex,cricley) {
   ctx.beginPath();
   ctx.arc(criclex, cricley, this.radius, 0, Math.PI * 2, true);  // 坐标为90的圆,这里起始角度是0,结束角度是Math.PI*2
   ctx.lineWidth = this.lineWidth;
   ctx.strokeStyle = this.strokeStyle;
   ctx.stroke();  // 这里用stroke画一个空心圆,想填充颜色的童鞋可以用fill方法};function Ring(radius, lineWidth, strokeStyle, fillStyleArray, capType) {
   Circle.call(this, radius, lineWidth, strokeStyle, fillStyleArray, capType);}Ring.prototype = Object.create(Circle.prototype);Ring.prototype.drawRing = function (ctx, startAngle, percentArray ,criclex,cricley) {
   startAngle = startAngle 

关键词:怎样绘制圆角环形图形




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版