HTML5(五)html5<canvas路径和三角函数的故事>(下)
来源:互联网 发布:日本海关数据 编辑:程序博客网 时间:2024/05/18 03:11
利用canvas的路径实现直线跟着鼠标的方向转动和点击圆,圆变大变小的功能。
<!DOCTYPE html><html><head><title>canvas</title><style>canvas{background:#ccc;}</style><script>window.onload=function(){var canvas = document.getElementById("canvas");var cobj = canvas.getContext("2d");/*功能:直线跟着鼠标的方向转动*/cobj.lineWidth=5;cobj.strokeStyle="#f00";cobj.moveTo(200,250);cobj.lineTo(200,350);cobj.stroke();canvas.onmousemove=function(e){var mx=e.layerX;var my=e.layerY;var startx=200;var starty=250;var angle=Math.atan2((my-starty),(mx-startx));cobj.clearRect(0,0,400,400);cobj.beginPath();cobj.moveTo(startx,starty);cobj.lineTo(startx+100*Math.cos(angle),starty+100*Math.sin(angle));cobj.stroke();}/*功能:点击圆,圆变大变小*//*cobj.arc(200,200,50,0,2*Math.PI);cobj.stroke();var angle=0;canvas.onclick=function(e){var mx=e.layerX;var my=e.layerY;//判断是否在路径中if(cobj.isPointInPath(mx,my)){setInterval(function(){cobj.clearRect(0,0,400,400);angle+=0.2;cobj.beginPath();cobj.arc(200,200,50+10*Math.sin(angle),0,2*Math.PI);cobj.stroke();},50)}}*/}</script></head><body><canvas width="400px" height="400px" id="canvas">请您升级浏览器</canvas></body></html>
0 0
- HTML5(五)html5<canvas路径和三角函数的故事>(下)
- html5<canvas路径和三角函数的故事>
- HTML5(三)html5<canvas路径和三角函数的故事>(上)
- HTML5(四)html5<canvas路径和三角函数的故事>(中)
- HTML5 canvas画布(五)
- html5 canvas绘制路径
- HTML5之帆布(canvas)(五)
- HTML5中的Canvas绘图操作(五)
- HTML5(六)html5<canvas带音效的时钟>
- html5<canvas基础>
- HTML5 Canvas 起步(2) - 路径
- HTML5 Canvas 绘制路径实例
- HTML5那些故事:Canvas的KineticJS图片教程!
- html5 新元素和Canvas
- HTML5的学习 (canvas translate和restore的理解)
- html5 canvas坐标和大小的问题
- html5中的canvas和svg的使用
- html5 canvas的clearRect
- LeetCode:Insertion Sort List
- linux多命令顺序执行与管道符-54
- 直方图交叉核
- UIButton简单介绍
- Android UML类图、流程图总结
- HTML5(五)html5<canvas路径和三角函数的故事>(下)
- C#图形验证码
- Selenium浏览器自动化测试使用(2)
- 53篇PHP开发技术干货,拿走,不谢~
- Animation 优化
- 03 WAMPServer多站点的配置
- 【慕课笔记】第四章 流程控制语句 第2节 JAVA条件语句之if...else...
- 解决.gitignore无法忽略部分文件
- lr_eval_string()函数以及LR中参数、变量的简单使用