分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

html5-canvas

发布时间:2023-09-06 01:30责任编辑:赖小花关键词:暂无标签

canvas(画布)

html实例

<canvas id="myCanvas" width="200" height="100"></canvas>

使用style增加边框

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000"></canvas>

使用js绘制图像

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000"></canvas><script>var doc = document;var c = doc.getElementById("myCanvas");var ctx = c.getContext("2d");ctx.fillStyle="#ff0000";ctx.fillRect(0,0150,75)</script>

上面的fillStyle方法拥有的参数(x轴,y轴,width,height);

Canvas-路径

1.moveTo(x,y)定义线条开始坐标

2.lineTo(x,y)定义线条结束坐标

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000"></canvas><script>var doc = document;var c = doc.getElementById("myCanvas");var ctx = c.getContext("2d"); ???ctx.moveTo(0,0); ???ctx.lineTo(200,100); ???ctx.stroke();//绘制线条</script>

Canvas-圆

方法:arc(x,y,r,start,stop,counterclockwise);

x:圆的中心的x坐标

y:圆的中心的y坐标

r:圆的半径

start:起始角,以时钟的三点钟起始。

stop:结束角。

counterclockwise:可选,规定应该逆时针还是顺时针,false=顺时针,true-=逆时针。

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000"></canvas><script>var doc = document;var c = doc.getElementById("myCanvas");var ctx = c.getContext("2d"); ??ctx.beginPath(); ???ctx.arc(95,50,40,0,2*Math.PI); ???ctx.stroke();</script>

具体请参考:http://www.w3school.com.cn/tags/html_ref_canvas.asp

html5-canvas

原文地址:http://www.cnblogs.com/MJ-MY/p/8040292.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved