当前位置:网站首页>Common prototype methods of canvas and the application of drawing pictures
Common prototype methods of canvas and the application of drawing pictures
2022-07-28 09:23:00 【Juefang】
Drawing lines
Draw triangle
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id="canvans" width="500" height="500"></canvas>
<img src="./img_the_scream.jpg" alt="">
<script>
var canvans = document.querySelector("#canvans")// obtain canvans object
if (canvans.getContext) {
// Monitor whether the browser supports canvas
var ctx = canvans.getContext('2d');// obtain 2D paint brush
// Draw a closed triangle
ctx.beginPath();// Grab the pen first
ctx.moveTo(100, 100);// The beginning of a path
ctx.lineTo(200, 50);// even
ctx.lineTo(200, 150);// even
ctx.closePath(); // Finally, the third side needs to be closed
ctx.stroke();// End painting
}
</script>
</body>
</html>
Note that every line drawing needs ctx.beginPath() Grab a pen , then ctx.stroke() Put the pen
Draw a circle
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id="canvans" width="500" height="500"></canvas>
<img src="./img_the_scream.jpg" alt="">
<script>
var canvans = document.querySelector("#canvans")// obtain canvans object
if (canvans.getContext) {
// Monitor whether the browser supports canvas
var ctx = canvans.getContext('2d');// obtain 2D paint brush
// circular
ctx.beginPath();
ctx.arc(300,300,50,0,2*Math.PI,true)
ctx.stroke();
}
</script>
</body>
</html>
- Painting garden :arc()
- Draw arc :arc()
Drawing pictures
demand : Suppose there's a h5 Posters , But the QR code in the picture is dynamic , And generated at any time . This is where it comes in canvas Dynamic picture rendering technology .
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id="canvans" width="500" height="500"></canvas>
<img src="./img_the_scream.jpg" alt="">
<script>
var canvans = document.querySelector("#canvans")// obtain canvans object
if (canvans.getContext) {
// Monitor whether the browser supports canvas
var ctx = canvans.getContext('2d');// obtain 2D paint brush
let img = document.querySelector('img')
// Drawing pictures
img.onload = function(){
ctx.drawImage(img,200,200)
}
}
</script>
</body>
</html>
<!-- ctx.
drawImage() It is a very practical prototype method
other
canvas There are many rendering techniques , For example, you can draw shadows 、 Linear gradient 、 Radial Gradient 、 Color filling, etc
边栏推荐
- 51单片机存储篇:EEPROM(I2C)
- 【SwinTransformer源码阅读二】Window Attention和Shifted Window Attention部分
- How to obtain the subordinate / annotation information of KEGG channel
- A perfect cross compilation environment records the shell scripts generated by PETA
- 7 C控制语句:分支和跳转
- Train your own classification [Bao Jiaobao, the data are ready]
- 中国地图省>市>级>区>镇>村5级联动下载【2019和2021】
- Code management platform SVN deployment practice
- 【leetcode周赛总结】LeetCode第 83场双周赛(7.23)
- MySQL 8.0.30 GA
猜你喜欢

CSV file storage

Linux initializes MySQL with fatal error: could not find my-default.cnf

公众号简介
![Magic brace- [group theory] [Burnside lemma] [matrix fast power]](/img/cf/606d1bc7cd877771afbdd7640b718c.png)
Magic brace- [group theory] [Burnside lemma] [matrix fast power]
![[English postgraduate entrance examination vocabulary training camp] day 15 - analyze, general, avoid, surveillance, compared](/img/a8/2c2fab613035f5e50524056d5f51a3.png)
[English postgraduate entrance examination vocabulary training camp] day 15 - analyze, general, avoid, surveillance, compared

Implementation principle of golang synergy
![【解决】ERROR in [eslint] ESLint is not a constructor](/img/58/2ce1243d0085462af3ba6d3da0817d.png)
【解决】ERROR in [eslint] ESLint is not a constructor

Get started quickly with flask (I) understand the framework flask, project structure and development environment

MDM data quality application description

C language array pointer and pointer array discrimination, analysis of memory leakage
随机推荐
【C语言】详解顺序表(SeqList)
Centralized log management with sentry
F - jealous two-dimensional reverse order pair
LeetCode_406_根据身高重建队列
Recommend an artifact to get rid of the entanglement of variable names and a method to modify file names in batches
golang升级到1.18.4版本 遇到的问题
Machine learning: self paced and fine tuning
QT basic hand training applet - simple calculator design (with source code, analysis)
台大林轩田《机器学习基石》习题解答和代码实现 | 【你值得拥有】
Implementation principle of golang synergy
TXT text file storage
2022年安全员-B证考试模拟100题及答案
5 运算符、表达式和语句
Introduction to official account
公众号简介
2022 high voltage electrician examination simulated 100 questions and simulated examination
1.5 merge\rebase\revert\stash\branch
侯捷STL标准库和泛型编程
信息学奥赛一本通 1617:转圈游戏 | 1875:【13NOIP提高组】转圈游戏 | 洛谷 P1965 [NOIP2013 提高组] 转圈游戏
OpenShift 4 之AMQ Streams(1) - 多个Consumer从Partition接收数据