当前位置:网站首页>canvas - 圆形
canvas - 圆形
2022-07-24 05:18:00 【梅花三】
使用 arc() 或 arcTo() 方法画圆形
效果图:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#cvs {
background-color: #ccc;
}
</style>
</head>
<body>
<div id='container'>
<canvas id='cvs'>
sorry, your browser doesn't support canvas API.
</canvas>
</div>
</body>
<script>
window.onload = function() {
// 获取画布
const cvs = document.querySelector('#cvs')
cvs.width = 800
cvs.height = 800
// 获取画笔
const ctx = cvs.getContext('2d')
const PI = Math.PI
drawCircle(350, 350, 50, PI, PI * 2)
drawCircle(400, 400, 50, PI * 3 / 2, PI * 1 / 2)
drawCircle(350, 450, 50, 0, PI)
drawCircle(300, 400, 50, PI * 1 / 2, PI * 3 / 2)
drawCircle(350, 400, 100, 0, PI * 2)
drawCircle(350, 400, 50, 0, PI * 2)
ctx.strokeStyle = '0f0'
ctx.strokeRect(300, 350, 100, 100)
function drawCircle(x, y, r, startAngle, endAngle) {
ctx.moveTo(x, y)
ctx.beginPath()
ctx.arc(x, y, r, startAngle, endAngle)
ctx.strokeStyle = 'lime'
ctx.stroke()
}
}
</script>
</html>
效果图:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#cvs {
background-color: #ccc;
}
</style>
</head>
<body>
<div id='container'>
<canvas id='cvs'>
sorry, your browser doesn't support canvas API.
</canvas>
</div>
</body>
<script>
window.onload = function() {
// 获取画布
const cvs = document.querySelector('#cvs')
cvs.width = 800
cvs.height = 600
// 获取画笔
const ctx = cvs.getContext('2d')
ctx.globalAlpha = 0.5
for(let i = 0; i < 50; i++) {
ctx.beginPath()
ctx.arc(Math.random() * 800, Math.random() * 600, Math.random() * 50, 0, Math.PI * 2)
const fillStyle = 'rgb(' + randomRGB() + ',' + randomRGB() + ',' + randomRGB() + ')'
ctx.fillStyle = fillStyle
ctx.fill()
}
function randomRGB() {
return Math.floor(Math.random() * 256)
}
}
</script>
</html>
边栏推荐
- C语言入门篇 一.分支和循环语句
- 数组_01forEach中的return
- 4. 在屏幕上绘制一个红色三角形,一个黄色正方形。三角形在后,小;正方形在前,大。使用融合技术,使得可以透过正方形看到三角形,源和目标融合因子分别为GL_SRC_ALPHA和GL_ONE_MINUS
- Find the flops of the network
- T 11-20
- 【dp】数字三角形
- 用双向链表实现栈(C)
- 随意写写 cookie,sessionStorage,localStorage和session
- C2 random generation function seed, numpy. Random. Seed(), TF. Random. Set_ Seed Learning + reprint and sorting
- 再次聊聊浏览器缓存
猜你喜欢
随机推荐
scikit-learn笔记
C语言进阶篇 二. 指针
输入若干数据,找出最大值输出。(键盘和文件读取)
统计学之样本和总体的关系: 样本成功比例+中心极限定理(样本均值)
special effects - 星空宇宙背景特效
C语言入门篇 五.初识指针 六.初识结构体
Find the flops of the network
修改jupyter保存路径
Introduction to threads
anaconda常用命令的整理
一步一步带你学C(其一)
【常用技巧】
8.使用二次几何体技术,在屏幕上绘制一个上小下大的柱体。
一步一步带你学C(其二)
C语言入门篇 概述
程序员工具合集!(转载)
C语言进阶篇 五.动态内存管理
Generics and annotations
SSM integration
AttributeError: ‘NoneType‘ object has no attribute ‘shape‘









