当前位置:网站首页>了解canvas
了解canvas
2022-07-23 06:30:00 【M78_国产007】
网页中的两种绘图技术:1、SVG矢量图 2、canvas
SVG矢量图:就是用一个标签代码来画图
canvas :画布,h5新出的技术,用js来画图
它们都是代码,占用很小的内存;但是img是图片,是图片编码。
注意:画布的宽度和高度要用canvas的属性设置,不要直接在css里面定义;
canvas本身没有任何外观,只是在文档中创建了一个画板。
画布的坐标:画布以浏览器可视区域左上角(0, 0)为坐标原点;往右为X轴的坐标不断增大; 往下为Y轴的坐标不断增大。
canvas如何作图?
1、写一个canvas标签
2、获取创建的canvas元素
3、canvas点getContext("2d")得到一个“绘制上下文”对象
4、这个对象调用相应的方法,画线或着色。
小例子:
<canvas id="cav" width="400" height="400"></canvas>
<script>
var cav=document.querySelector("#cav")
var cxt=cav.getContext("2d")
cxt.moveTo(200,200)//确定线段起点
cxt.lineTo(300,300)//将上面定义的线段起点和这里指定的新的点连接起来
cxt.moveTo(300,300)
cxt.lineTo(400,200)
cxt.strokeStyle="yellow" //改变线段颜色
cxt.lineWidth=10 //改变线段粗细
cxt.stroke() //绘制图片
</script>页面效果:

需要补充一点: 关于lineTo()这个方法,是将moveTo()设置的起点与当前lineTo的点连接起来;但是当没有设置moveTo()时,lineTo()会将上条线段的终点当作起点,如果没有上一次的终点,就没有这一次的起点。
canvas适用于哪些场景?
双屏互动 大数据页面 游戏 广告 特效.......
边栏推荐
- [jzof] 10 Fibonacci series
- Wu Enda machine learning series p31~p42
- Google play app store may delete the overview of APP permissions and use a new combination of data security information
- 机器学习,吴恩达逻辑回归
- The current situation of the industry is disappointing. After working, I returned to UC Berkeley to study for a doctoral degree
- 0722~ thread pool extension
- 高性能JVM的参数
- 倍福PLC和C#通过ADS通信定时刷新IO
- Knowledge map: basic concepts
- MySQL index transaction & JDBC programming
猜你喜欢

Beifu PLC and C transmit string type through ads communication

Day 10 notes

Target segmentation for 10000 frames of video, with less than 1.4GB of video memory | eccv2022

网易白帽子黑客训练营笔记(2)

Opencv image processing (medium) image smoothing + histogram
![[noi simulation race] I don't know which CF paper title it is (probability expectation, martingale's stop time theorem)](/img/79/46e9bf2b39fbec9ae913c4e205acdc.png)
[noi simulation race] I don't know which CF paper title it is (probability expectation, martingale's stop time theorem)

Jupyter notebook add existing virtual environment

Are there any academic requirements for career transfer software testing? Is there really no way out below junior college?

Complex networks - common drawing software and libraries

Functional testing to automated testing, sharing ten years of automated testing experience
随机推荐
Bit synchronization process of CAN controller
0722~ thread pool extension
【JZOF】10斐波那契数列
深入理解微信小程序的底层框架(一)
知识图谱:基本概念
C语言插入排序(直接插入排序)
In depth interpretation of EVM's ecological Empire
The unity model is displayed in front of the UI, and the UI behind it jitters
Beifu PLC and C transmit bool array variables through ads communication
Opencv video operation
Google面试题原理解析 12个乒乓球其中有1个次品,用天平称重3次找出
UI automation
深入解读 EVM 的生态帝国
Dynamic planning daily practice (1)
High voltage MOS tube knx42150 1500v/3a is applied to frequency converter power supply inverter, etc
DeFi 永不消亡?
The relationship between method area, perpetual generation and meta space
Talk about "people" in the R & D team
NFT 交易市场的格局之变:从一家独大到百家争鸣
Summary of time complexity( Ο Is the asymptotic upper bound, Ω is the asymptotic lower bound, P, NP, NP hard, NPC problem)