当前位置:网站首页>Canvas foundation 2 - arc - draw arc
Canvas foundation 2 - arc - draw arc
2022-07-06 13:50:00 【Ling Xiaoding】
List of articles
This article is about canvas Basics 2 - arc - Draw arc , Easy to understand , Xiaobai has no trouble , According to MOOCS liuyubobobo The teacher's video lesson learning and sorting
Video lesson guide : For class network liuyubobobo teacher Gorgeous countdown effect Canvas Fundamentals of drawing and animation
List of articles
1、arc Method to draw an arc
context.arc( The coordinates of the center of the circle x, The coordinates of the center of the circle y, Radius value , Which radian value to start from , End arc , Whether the radian is clockwise or counterclockwise defaults false For clockwise )
startingAngle
andendingAngle
explain
2、 A circle
- Draw a circle clockwise
<canvas id="canvas" style="background-color: rgb(200,200,200);display: block;margin: 20px auto;">
The current browser does not support canvas, Please change your browser and try again
</canvas>
<script> var canvas = document.getElementById('canvas') canvas.width = 1024 canvas.height = 768 if (canvas.getContext('2d')) {
var context = canvas.getContext('2d') context.lineWidth = 5 context.strokeStyle = '#005588' context.arc(300, 300, 200, 0, 1.5 * Math.PI) context.stroke() } </script>
2. Draw a circle counterclockwise
<canvas id="canvas" style="background-color: rgb(200,200,200);display: block;margin: 20px auto;">
The current browser does not support canvas, Please change your browser and try again
</canvas>
<script> var canvas = document.getElementById('canvas') canvas.width = 1024 canvas.height = 768 if (canvas.getContext('2d')) {
var context = canvas.getContext('2d') context.lineWidth = 5 context.strokeStyle = '#005588' context.arc(300, 300, 200, 0, 1.5 * Math.PI, true) context.stroke() } </script>
3、closePath characteristic
closePath
Represents the end of this path , If the current path is not closed , Will automatically close this path
4、2048 The board demo
<canvas id="canvas" width="800" height="800" style="display: block; background-color: #eee;margin: 10px auto;">
Out of commission canvas
</canvas>
<script> window.onload = function () {
var canvas = document.getElementById('canvas') var context = canvas.getContext('2d') // drawRoundRect(context, 10, 10, 600, 500, 50) // fillRoundRect(context, 50, 50, 600, 500, 50, '#500') fillRoundRect(context, 150, 150, 500, 500, 10, '#bbada0') for (var i = 0; i < 4; i++) for (var j = 0; j < 4; j++) fillRoundRect(context, 170 + i * 120, 170 + j * 120, 100, 100, 6, '#ccc0b3') } function drawRoundRect(cxt, x, y, width, height, radius) {
if (2 * radius > width || 2 * radius > height) return; cxt.save() cxt.translate(x, y) pathRoundRect(cxt, width, height, radius) cxt.strokeStyle = '#000' cxt.stroke() cxt.restore() } function fillRoundRect(cxt, x, y, width, height, radius, fillColor) {
if (2 * radius > width || 2 * radius > height) return; cxt.save() cxt.translate(x, y) pathRoundRect(cxt, width, height, radius) cxt.fillStyle = fillColor || '#000' cxt.fill() cxt.restore() } function pathRoundRect(cxt, width, height, radius) {
cxt.beginPath() cxt.arc(width - radius, height - radius, radius, 0, Math.PI / 2) cxt.lineTo(radius, height) cxt.arc(radius, height - radius, radius, Math.PI / 2, Math.PI) cxt.lineTo(0, radius) cxt.arc(radius, radius, radius, Math.PI, Math.PI * 3 / 2) cxt.lineTo(width - radius, 0) cxt.arc(width - radius, radius, radius, Math.PI * 3 / 2, Math.PI * 2) cxt.closePath() } </script>
summary
This paper is about canvas In the second quarter , After that, it will continue to update , If you feel it is still practical , It's OK to follow or like , Thank you very much!
边栏推荐
- 7-6 矩阵的局部极小值(PTA程序设计)
- MATLAB打开.m文件乱码解决办法
- 7-9 制作门牌号3.0(PTA程序设计)
- 1. First knowledge of C language (1)
- 5. Function recursion exercise
- Mortal immortal cultivation pointer-2
- MySQL中count(*)的实现方式
- fianl、finally、finalize三者的区别
- C语言入门指南
- 20220211-CTF-MISC-006-pure_ Color (use of stegsolve tool) -007 Aesop_ Secret (AES decryption)
猜你喜欢
3.输入和输出函数(printf、scanf、getchar和putchar)
Differences among fianl, finally, and finalize
canvas基础1 - 画直线(通俗易懂)
1.C语言初阶练习题(1)
C语言入门指南
Mortal immortal cultivation pointer-1
This time, thoroughly understand the MySQL index
MATLAB打开.m文件乱码解决办法
【手撕代码】单例模式及生产者/消费者模式
Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems
随机推荐
为什么要使用Redis
7-4 散列表查找(PTA程序设计)
7-6 矩阵的局部极小值(PTA程序设计)
4. Branch statements and loop statements
[the Nine Yang Manual] 2018 Fudan University Applied Statistics real problem + analysis
【手撕代码】单例模式及生产者/消费者模式
实验七 常用类的使用
实验九 输入输出流(节选)
杂谈0516
String ABC = new string ("ABC"), how many objects are created
ArrayList的自动扩容机制实现原理
稻 城 亚 丁
1. First knowledge of C language (1)
[the Nine Yang Manual] 2020 Fudan University Applied Statistics real problem + analysis
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
Detailed explanation of redis' distributed lock principle
(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。
【毕业季·进击的技术er】再见了,我的学生时代
关于双亲委派机制和类加载的过程