当前位置:网站首页>Learn about canvas
Learn about canvas
2022-07-23 13:38:00 【M78_ Domestic 007】
Two drawing techniques in web pages :1、SVG Vectorgraph 2、canvas
SVG Vectorgraph : Is to use a label code to draw pictures
canvas : canvas ,h5 New technology , use js To draw
They are all code , Take up very little memory ; however img It's a picture. , It's picture coding .
Be careful : The width and height of the canvas should be canvas Property settings for , Don't go straight to css It is defined ;
canvas It doesn't have any appearance , Just create a Sketchpad in the document .
Coordinates of canvas : The canvas is in the upper left corner of the browser's visible area (0, 0) It's the origin of the coordinates ; To the right X The coordinates of the axis are increasing ; Down is Y The coordinates of the axis are increasing .
canvas How to draw ?
1、 Write a canvas label
2、 Get the created canvas Elements
3、canvas spot getContext("2d") Get one “ Draw context ” object
4、 This object calls the corresponding method , Draw lines or colors .
Small example :
<canvas id="cav" width="400" height="400"></canvas>
<script>
var cav=document.querySelector("#cav")
var cxt=cav.getContext("2d")
cxt.moveTo(200,200)// Determine the starting point of the line segment
cxt.lineTo(300,300)// Connect the starting point of the line segment defined above with the new point specified here
cxt.moveTo(300,300)
cxt.lineTo(400,200)
cxt.strokeStyle="yellow" // Change the line segment color
cxt.lineWidth=10 // Change the thickness of the line segment
cxt.stroke() // Drawing pictures
</script>Page effects :

Need to add a little : About lineTo() This method , Yes, it will moveTo() Set the starting point and current lineTo Connect the points of ; But when there is no setting moveTo() when ,lineTo() The end point of the previous line segment will be taken as the starting point , If there is no last destination , There is no starting point for this time .
canvas What scenarios apply ?
Dual screen interaction Big data page game advertisement Special effects .......
边栏推荐
- Opencv video operation
- [visual scheduling software] Shanghai daoning brings netronic downloads, trials and tutorials to SMB organizations
- Optimising a 3D convolutional neural network for head and neck computed tomography segmentation with
- Opencv image processing (medium) image smoothing + histogram
- 【MUDUO】EPOLLPOLLER事件分发器
- 学会用canvas构建折线图、柱状图、饼状图
- Introduction to radar part vii 1 radar and resolution
- [daily training] 814. Binary tree pruning
- [noi simulation race] I don't know which CF paper title it is (probability expectation, martingale's stop time theorem)
- Point target simulation of SAR imaging (II) -- matlab simulation
猜你喜欢

【可视化调度软件】上海道宁为SMB组织带来NETRONIC下载、试用、教程

Shooting lesson 1-3: image Sprite

Don't be silly to distinguish these kinds of storage volumes of kubernetes

【JS高级】正则入门基础—关于你想知道的正则表达式_01
![[jzof] 11 minimum number of rotation array](/img/a3/6c3672a2a7b4f436874664034a4964.png)
[jzof] 11 minimum number of rotation array

Point target simulation of SAR imaging (II) -- matlab simulation

Introduction to radar part vii 2 imaging method
![[jzof] 07 rebuild binary tree](/img/c8/5b67a3921afda5323b0d1eea6a78bc.png)
[jzof] 07 rebuild binary tree

Uncaught (in promise) Neo4jError: WebSocket connection failure. Due to security constraints in your

决策树详解
随机推荐
【PART 2】OAK-D+TurtleBot3机器人项目全解析
4D antenna array layout design
我为大厂怒刷的《100道Android面试题》
0722~线程池扩展
ES6——周考题
[jzof] 11 minimum number of rotation array
给1万帧视频做目标分割,显存占用还不到1.4GB | ECCV2022
浅谈Anroid设备的CPU类型以及so文件的放置目录
ROS中引用和输出消息类型
太空射击 Part 2-2: 敌人精灵
动态规划每日一练(1)
Debug No5 basic lighting
Hardware system architecture of 4D millimeter wave radar
射击 第 1-3 课:图像精灵
Point target simulation of SAR imaging (II) -- matlab simulation
Deep understanding of the underlying framework of wechat applet (I)
【可视化调度软件】上海道宁为SMB组织带来NETRONIC下载、试用、教程
DeFi 永不消亡?
Machine learning, Wu Enda, logical regression
反常积分的审敛