当前位置:网站首页>canvas - 旋转
canvas - 旋转
2022-07-24 05:17:00 【梅花三】
canvas是基于状态绘制的,每次平移、旋转、缩放、矩阵等变换之前,先调用save()保存当前绘图状态,变换结束之后,若要继续使用变换之前的状态,调用restore()方法即可。
效果图:
<!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')
for(let i = 0; i < 11; i++) {
ctx.save()
ctx.translate(400, 300)
ctx.rotate(36 * i * Math.PI / 180)
ctx.bezierCurveTo(30, 50, 350, 550, 100, 150)
ctx.fillStyle = 'rgba(255, 0, 255, 0.25)'
ctx.fill()
ctx.restore()
}
}
</script>
</html>
边栏推荐
猜你喜欢
随机推荐
这是第一篇
Implementation and comparison of nine sorting (ten thousand words summary)
深度剖析数据在内存中的存储
一步一步带你学C(其二)
Skills of BeanShell dealing with JSON
C语言入门篇 五.初识指针 六.初识结构体
递归还能这么玩?递归实现扫雷游戏
day(0~6)代表每月第一天起始位置,stop代表每月天数,每天之间空两个空格。输入不同的day和stop,输出每月日历的样子。假设day为2,stop为31,则输出样式为
C语言入门篇 一.分支和循环语句
C语言从入门到入土(一)
C文件读写加链表增删改查
special effects - 鼠标移动,出现泡泡拖尾
程序员工具合集!(转载)
模板数据的二次加工
关键字_02break与continue
构造函数_Map构造函数
聊聊强缓存与协商缓存
C语言进阶篇 二. 指针
Relationship between sample and population in Statistics: sample success ratio + central limit theorem (sample mean)
Add, delete, modify and check JDBC









