首页
产品
快图
小程序
微商城
网站建设
新闻
公司动态
行业资讯
关于
案例
联系
html5 canvas绘图矩形框和圆形的案例编码
2021-02-24 10:24
jianzhan
html5 canvas绘图矩形框和圆形的案例编码
JavaScript Code
拷贝內容到剪贴板
<!DOCTYPE html>
<html>
<head>
<meta charset=
"UTF⑻"
>
<title></title>
</head>
<body onload=
"draw(),drawarc()"
>
<!--绘图的流程:获得canvas元素->获得左右文->填充与绘图边框->设置制图款式-->
<!--绘图别的繁杂图型必须应用相对路径:刚开始建立相对路径->建立图型相对路径->关掉相对路径->绘图图型-->
<!--eg:绘图矩形框-->
绘图矩形框:<canvas id=
"ca"
></canvas><br />
绘图圆形:<canvas id=
"yuan"
></canvas>
</body>
</html>
<script>
//绘图矩形框
function
draw(){
var
canvas=document.getElementById(
'ca'
);
//获得canvas元素
if
(canvas==
null
)
return
false
;
var
context=canvas.getContext(
'2d'
);
//获得左右文
context.fillStyle=
'#EEEFF'
;
//填充色调
context.fillRect(0,0,400,300);
//填充矩形框 (矩形框1)
context.fillStyle=
'red'
;
context.strokeStyle=
'blue'
;
//边框色调
context.lineWidth=1;
//边框宽度
context.fillRect(50,50,100,100);
//填充矩形框(內部矩形框2)
context.strokeRect(50,50,100,100);
//绘图边框
}
//绘图圆形
function
drawarc(){
var
canvas2=document.getElementById(
'yuan'
);
//获得canvas元素
if
(canvas2==
null
)
if
(canvas2==
null
)
return
false
;
var
context2=canvas2.getContext(
'2d'
);
//获得左右文
context2.fillStyle=
'#EEEEEF'
;
context2.fillRect(0,0,400,300);
var
n=0;
for
(
var
i=0;i<10;i++){
context2.beginPath();
//刚开始建立相对路径
context2.arc(i*25,i*25,i*10,0,Math.PI*2,
true
);
//建立圆形相对路径
context2.closePath();
//关掉相对路径
context2.fillStyle=
'Rgba(255,0,0,0.25)'
;
//设定色调
context2.fill();
//填充图型
}
}
</script>
以上便是网编为大伙儿带来的html5 canvas绘图矩形框和圆形的案例编码的所有內容了,期待大伙儿多多适用步伐之家。
为您推荐
html5 canvas绘图矩形框和圆形的案例编码
案例解读运用HTML5 Canvas API实际操作图型转
HTML5当地储存之Web Storage详解
canvas 基本之图象解决的应用
HTML5触碰恶性事件(touchstart、touchmove和to
所有文章
公司动态
行业资讯