demo_06Canvas
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#myCanvas{
background-color: #fde;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="1000" height="500"></canvas>
</body>
<script type="text/javascript">
var oc = document.getElementById("myCanvas"); var ctx = oc.getContext("2d"); var isAdd ;
var obj = {
x : 50,
y: 50,
width : 200,
height : 200
}
var num = 0
function rotate(){
ctx.save();
if(num==200){
isAdd = false;
}
if(num==0){
isAdd = true;
}
if(isAdd){
num++;
}
else{
num--;
}
ctx.clearRect(0,0,500,500);
ctx.fillStyle="blueviolet";
ctx.translate(obj.x+(obj.width)/2,obj.y+(obj.height)/2);
ctx.scale(num/100,num/100);
ctx.rotate(num*Math.PI/180); ctx.translate(-(obj.x+(obj.width)/2),-(obj.y+(obj.height)/2))
ctx.fillRect(obj.x,obj.y,obj.width,obj.height);
ctx.restore();
}
setInterval(function(){
rotate(); },10); </script>
</html>
在Canvas中添加save()和restore()方法是因为Canvas的绘制实在上一个绘制图形之后继续绘制的(覆盖)。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
body{
background: red;
}
#canvas{
background: white;
width: 400px;
height: 400px;
} </style>
</head>
<body>
<!-- 默认canvas大小width300px,height150px -->
<!-- 宽高必须在canvas标签的属性中设置,在css中写的话,是将canvas进行拉伸 -->
<canvas id="canvas" width="400" height="400">
<span>这是一个画布,请用ie10+浏览器查看,或者。。。。</span>
</canvas> <input type="color" id="colorInput"/>
<input type="number" id="numberInput" value="1"/> <script>
//得到画布
var oC = document.getElementById('canvas');
//得到canvas的上下文环境
//目前只支持2d环境
var oGC = oC.getContext('2d'); oC.onmousedown = function(ev){
var colorInput = document.getElementById('colorInput');
var numberInput = document.getElementById('numberInput');
oGC.strokeStyle = colorInput.value;
oGC.lineWidth = numberInput.value;
oGC.beginPath(); var ev = ev || window.event;
//得到按下这个点相对于canvas的位置
oGC.moveTo(ev.clientX - oC.offsetLeft, ev.clientY - oC.offsetTop); document.onmousemove = function(ev){
var ev = ev || window.event;
oGC.lineTo(ev.clientX - oC.offsetLeft, ev.clientY - oC.offsetTop);
oGC.stroke();
} document.onmouseup = function(){
oGC.closePath();
document.onmousemove = null;
document.onmouseup = null;
} } </script>
</body>
</html>
demo_06Canvas的更多相关文章
随机推荐
- oracle数据库自动备份脚本
::通过exp命令导出远程机器(192.168.2.1)上指定服务(orcl)指定用户(pmis)及密码(pmis)的数据 ::运行该脚本的机器必须安装oracle @echo off @echo [ ...
- JSP中解决获取请求参数中文乱码问题
分两种情况: 1.获取访问请求参数时乱码 解决方法:构造一个新的String String user = new String(request.getParameter("user" ...
- JBPM学习(二):ProcessEngine与Service API
1.获取processEngine的方法: a) 方法一 private ProcessEngine processEngine = new Configuration().setResource(& ...
- 部署服务--NLB
通过服务部署NLB,是对某一层(一层下面可以自定义VM实例数量)服务下的多台VM进行NLB,而不是对多个层进行NLB.需要先进行如下准备: 1.VM需要使用静态IP和静态MAC,所以需要先在进行NLB ...
- netbeans下将全部jar包打成一个,俗称fat jar
netbeans的java项目中.默认会将配置好的外部引用jar包,复制到dist文件夹的lib文件夹中去.假设须要公布出去.就须要将dist文件夹生成的jar和lib文件夹都拷贝出去公布,不方便. ...
- Mysql性能优化之缓存参数优化
数据库属于 IO 密集型的应用程序,其主要职责就是数据的管理及存储工作.而我们知道,从内存中读取一个数据库的时间是微秒级别,而从一块普通硬盘上读取一个IO是在毫秒级别,二者相差3个数量级.所以,要优化 ...
- 教你用笔记本破解无线路由器password
近期非常多人问我怎么破解WiFipassword…看来大家都对免费的东西比較有兴趣.要么也可能是我太招摇了…囧… 好吧,我就写篇小小的教程,看完后,你应该可以破解大部分无线路由器password了,写 ...
- linux shell read command-Getting User Input Via Keyboard--ref
ref:http://bash.cyberciti.biz/guide/Getting_User_Input_Via_Keyboard You can accept input from the ke ...
- leecode 每日解题思路 102-Binary Tree Level Order Traversal
題目描述: 题目链接: 102-Binary Tree Level Order Traversal 这个问题要解决的是如何逐层遍历一个二叉树,并把同一层元素放入同一list中, 再将所有元素返回. 其 ...
- C#泛型比较大小
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...