当前位置:网站首页>cavans图形绘制
cavans图形绘制
2022-08-07 01:46:00 【好奇的菜鸟】
一、绘制直线
<!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>canvas</title>
</head>
<body>
<canvas id="myCanvas" width="200" height="200" style="border:1px solid #753838;">您的浏览器不支持HTML5 canvas</canvas>
</body>
<script>
<!-- 获取绘制元素-->
var c = document.getElementById("myCanvas");
//获取cavas绘制上下文
var ctx = c.getContext("2d");
//设置直线起点
//定义开始坐标
ctx.moveTo(0, 0);
//定义结束坐标
ctx.lineTo(200, 200)
//设开始绘制
ctx.stroke();
</script>
</html>

二、绘制多条直线(线帽)
<!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>canvas</title>
</head>
<body>
<canvas id="myCanvas" width="200" height="200" style="border:1px solid #753838;">您的浏览器不支持HTML5 canvas</canvas>
</body>
<script>
<!-- 获取绘制元素-->
var c = document.getElementById("myCanvas");
//获取cavas绘制上下文
var ctx = c.getContext("2d");
//开始绘制
ctx.beginPath();
//设置线宽
ctx.lineWidth = 10;
//设置联调端点样式,默认值添加平直边缘
ctx.lineCap = "butt";
//设置起点
ctx.moveTo(20, 20);
//设置终点
ctx.lineTo(180, 20)
//绘制
ctx.stroke();
ctx.beginPath();
//设置联调端点样式,添加圆形边缘
ctx.lineCap = "round";
ctx.moveTo(20, 40);
ctx.lineTo(180, 40);
ctx.stroke();
ctx.beginPath();
//设置联调端点样式,添加方形边缘
ctx.lineCap = "square";
ctx.moveTo(20, 60);
ctx.lineTo(180, 60);
ctx.stroke();
</script>
</html>

边栏推荐
猜你喜欢

【华为云至简致远】还在烦恼成本高、运维难?华为云数据库给你一个标准答案!

记一次To B开发普通的性能优化历程......报表优化

Remember a common performance optimization process for To B development... report optimization

LeetCode:每日一题【第一周】

六安 自驾800公里大别山风景道,探索六安全域旅游

只需 2 张照片就能 2D 变 3D,这个 AI 能自己脑补蜡烛吹灭过程

Literature Reading (183) MAGMA

一文了解DataStore(Proto)
![[8.6] Code Source - [Prefix Set] [Matrix Game] [Who is the final winner?】](/img/17/52912834f2b736ce92e692ffbccd82.png)
[8.6] Code Source - [Prefix Set] [Matrix Game] [Who is the final winner?】

【第七篇】商城系统-商品发布-SKU和SPU管理
随机推荐
一夜成名的航班追踪网站,什么来头?
【第六篇】商城系统-实现规格参数和销售属性
Apache APISIX Ingress v1.5-rc1 released
这个数据太骚!搞得我都激动了。
Pyhton知识点6——列表
切换时过渡和动画
decode()的用法
习题:选择结构(二)
[8.6] Code Source - [Prefix Set] [Matrix Game] [Who is the final winner?】
下载安装和使用Nvm
Literature Reading (183) MAGMA
刚入职985的他,发了Science!
基于华为云ECS的目标检测与识别的昇腾AI开发体验【华为云至简致远】
pytest合集(8)— API Functions
Go-Excelize API源码阅读(九)——SetSheetBackground(sheet, picture string)
【LeetCode】14080.数组中的字符串匹配
ASC WarGames 2022 WEB WriteUP
pytest collection (8) — API Functions
状态平滑的动画
sqlilabs less-42