How to draw a rounded circular shape
Among the choices among many progress bar shapes, everyone will choose the donut chart. So today I will teach you how to use canvas to draw a rounded ring chart and the solution to the blurred progress bar. I hope it will be helpful to you
* @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
How to use
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%
Source code
The source code is very simple, everyone is welcome to expand!
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 || 3 * Math.PI / 2; percentArray = percentArray || []; this.draw(ctx,criclex,cricley); // 调用Circle的draw方法画圈圈 var _this = this; // angle percentArray.forEach(function (item, index) { ctx.beginPath(); var anglePerSec = 2 * Math.PI / (100 / item); // 蓝色的弧度 ctx.arc(criclex, cricley, _this.radius, startAngle, startAngle + anglePerSec, false); //这里的圆心坐标要和cirle的保持一致 startAngle = startAngle + anglePerSec; ctx.strokeStyle = _this.fillStyle[index]; ctx.lineCap = _this.lineCap; ctx.stroke(); ctx.closePath(); }) //小圆圈覆盖 ctx.beginPath(); ctx.arc(criclex, cricley, _this.radius, startAngle, startAngle, false); //这里的圆心坐标要和cirle的保持一致 ctx.strokeStyle = _this.fillStyle[0]; ctx.lineCap = _this.lineCap; ctx.stroke(); ctx.closePath();}
I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
How to make flying butterflies in CSS3 Animation
How to realize the animation of picture cover display in css3
The above is the detailed content of How to draw a rounded circular shape. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



After updating the win11 system, many friends found that the win11 interface window adopts a new rounded corner design. But some people don’t like this rounded corner design and want to modify it to the previous interface, but they don’t know how to modify it. Let’s take a look below. How to modify rounded corners in win11 1. The rounded corner design of win11 is a built-in system setting that cannot be modified at present. 2. So if you don’t like using the rounded corner design of win11, you can wait for Microsoft to provide a modification method. 3. If you are really not used to it, you can also choose to return to the previous win10 system. 4. If you don’t know how to roll back, you can check out the tutorials provided on this site. 5. If you cannot go back using the tutorial above, you can still

There has been news about the rounded corners of the win10 search box for a long time, but it has never been implemented. We can generally use the registry to experience the rounded corners of the win10 search box. So let's take a look at the tutorial on the rounded corners of the win10 search box. Bar. Win10 search box variable rounded corners: 1. Open the search box, enter regedit, and enter the registry. 2. Find this path in Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search. 3. In the blank space, select New - DWORD (32-bit) value - Name the new key ImmersiveSearch - Number

This chip may be equipped with up to 80 GPU cores, making it the most powerful product in the M3 series. Max has twice the number of cores. Judging from the development model of the M1 and M2 series, Apple's "Ultra" version of the chip basically has twice the number of cores of the "Max" version. This is because Apple actually uses two Max chips internally. The connection technologies are combined to form M1Ultra and M2Ultra. 80 GPU cores M3Ultra may have "up to 80 graphics processing cores." This prediction is based on the development path of Apple's chips: from the basic version to the "Pro" version, to the "Max" version with twice the number of graphics cores, and the "Ultra" version with double the number of CPU and GPU cores. For example

Hello everyone, today I will share with my friends the specific steps of how to combine two graphics in PPT. If you follow these steps, you will learn the operation step by step, and you can draw inferences in the future. The details of the steps are below. Friends, come and take a serious look! 1. First, open a PPT document on your computer, and then create a new PPT slide (as shown in the picture below). 2. Next, find [Shape] in the upper menu bar item [Insert], and select the shape to be imported in the drop-down box of the shape (as shown in the red circle in the figure below). 3. Use the insert function of PPT to insert the triangle and circle shapes into the PPT in sequence, and adjust the size and position of the shapes (as shown by the red arrow in the picture below). 4

CSS Drawing: Implementing Simple Gradient Graphic Effects In web design, gradient graphic effects are a common visual element that can add an attractive look and experience to a website. In CSS, we can use gradient effects to easily achieve gradient effects on various graphics, including rectangles, circles, text, etc. This article will introduce how to use CSS to achieve a simple gradient graphic effect, and provide specific code examples. 1. Linear gradient Linear gradient refers to the effect of gradual change from one point to another point. In CSS we can use l

amd graphics card ranking 1. What needs to be rewritten for Radeon is: RX. What needs to be rewritten for Radeon is: 6950XT2. What needs to be rewritten for Radeon is: RX. What needs to be rewritten is: 6900XT. 3. Radeon What needs to be rewritten is: RX What needs to be rewritten is: 6800XT4, Radeon What needs to be rewritten is: RX What needs to be rewritten is: 6800 What needs to be rewritten is: 5. Radeon needs to be rewritten: What needs to be rewritten for RX is: 6750XT6, what needs to be rewritten for Radeon is: what needs to be rewritten for RX is: 6700XT7

After updating to win11, I found that the original notifications on the win10 system were missing, and there was no rounded corners function, which made many users feel uncomfortable with it. So today I brought you a solution to the problem of no rounded corners and no notifications in win11. Quick Let’s see how it works. What to do if there are no rounded corners or notifications in win11: 1. First enter the desktop of the win11 system. 2. Then click the "!" option in the lower right corner of the desktop. 3. A rounded corner notification will pop up at this time. 4. The fact that the calendar must pop up every time it is used has been complained by many users. However, since the win11 system is still in its early stages, it will definitely be improved in the future.

CSS Layout Tips: Best Practices for Implementing Rounded Card Effects Introduction: With the continuous development of web design, rounded card effects have become one of the common elements in modern web design. By using CSS layout techniques, we can easily add beautiful rounded corner cards to web pages. This article will introduce the best practices for achieving rounded card effects and provide specific code examples for reference. 1. Use the border-radius property of CSS to create a rounded corner effect. In CSS, we can use border-r
