当前位置:网站首页>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
边栏推荐
- Openshift 4 - use verticalpodautoscaler to optimize application resource request and limit
- leetcode 452. Minimum Number of Arrows to Burst Balloons 用最少数量的箭引爆气球(中等)
- [advanced drawing of single cell] 07. Display of KEGG enrichment results
- QT basic hand training applet - simple calculator design (with source code, analysis)
- An entry artifact tensorflowplayground
- 【高数】高数平面立体几何
- 2022安全员-C证特种作业证考试题库及答案
- c# 有符号和无符号字节变量
- 【多线程】println方法底层原理
- 【leetcode周赛总结】LeetCode第 83场双周赛(7.23)
猜你喜欢

训练一个自己的分类 | 【包教包会,数据都准备好了】

The chess robot pinched the finger of a 7-year-old boy, and the pot of a software testing engineer? I smiled.

C simply call FMU for simulation calculation

IntelliJ idea associated database

IntelliJ IDEA 关联数据库

OpenShift 4 - 使用 VerticalPodAutoscaler 优化应用资源 Request 和 Limit
![Train your own classification [Bao Jiaobao, the data are ready]](/img/bd/08d0fbf0d41bb5ba7c418848ea1a4c.jpg)
Train your own classification [Bao Jiaobao, the data are ready]

2022 high voltage electrician examination simulated 100 questions and simulated examination

Sentinel

Introduction to official account
随机推荐
Recommend an artifact to get rid of the entanglement of variable names and a method to modify file names in batches
Alibaba cloud server setup and pagoda panel connection
一款入门神器TensorFlowPlayground
【JVM】JVM表示浮点数
【英语考研词汇训练营】Day 15 —— analyst,general,avoid,surveillance,compared
10、学习MySQL LIKE 子句
2022 safety officer-b certificate examination simulated 100 questions and answers
2022 high voltage electrician examination simulated 100 questions and simulated examination
信息学奥赛一本通 1617:转圈游戏 | 1875:【13NOIP提高组】转圈游戏 | 洛谷 P1965 [NOIP2013 提高组] 转圈游戏
【解决】ERROR in [eslint] ESLint is not a constructor
Machine learning (11) -- time series analysis
[English postgraduate entrance examination vocabulary training camp] day 15 - analyze, general, avoid, surveillance, compared
AMQ streams (1) of openshift 4 - multiple consumers receive data from partition
技术分享| 快对讲综合调度系统
Feign调用异常[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = n]
5 运算符、表达式和语句
Sentinel
CakePHP 4.4.3 发布,PHP 快速开发框架
The new mode of 3D panoramic display has become the key to breaking the game
Leetcode 452. minimum number of arrows to burst balloons (medium)