canvas旋转,平移,缩放一二例
来源:互联网 发布:时间简史 知乎 编辑:程序博客网 时间:2024/05/24 15:36
<!doctype html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><style> *{ padding:0; margin:0; } canvas{ display: inline-block; }</style></head><body><canvas id="myCanvas1" width='200' height='200' style="border:1px solid #ccc"></canvas><canvas id="myCanvas2" width='200' height='200' style="border:1px solid #ccc"></canvas><canvas id="myCanvas3" width='200' height='200' style="border:1px solid #ccc"></canvas><canvas id="myCanvas4" width='200' height='200' style="border:1px solid #ccc"></canvas><script>//canvas旋转,缩放,平移操作都是对整个画布的操作,如果有多次的话,本次操作是在上一场的操作的基础上操作的//canvas平移是对中心点的操作 var c=document.getElementById('myCanvas1'); var ctx=c.getContext('2d'); ctx.translate(100,0); //中心点由原来的(0,0)变为(100,0),画布大小,位置不变但是实际上是画布向右平移了100 ctx.fillStyle="red"; ctx.font="20px 微软雅黑"; ctx.fillText("no.1",0,20); ctx.translate(-100,0); //画布向左平移100,回到原始位置 ctx.beginPath(); ctx.font="20px 微软雅黑"; ctx.fillText("no.2",0,20); ctx.closePath(); //canvas缩放 var c2=document.getElementById('myCanvas2'); var ctx2=c2.getContext('2d'); ctx2.fillStyle="red"; ctx2.font="20px 微软雅黑"; ctx2.fillText("no.1原始",80,100); ctx2.scale(0.5,0.5); //实际上是画布缩小了一倍 ctx2.fillStyle="red"; ctx2.font="20px 微软雅黑"; ctx2.fillText("no.1缩放",80,100); ctx2.scale(0.5,0.5); //这个缩放一倍是在上次缩放的基础上缩放的 ctx2.fillStyle="red"; ctx2.font="20px 微软雅黑"; ctx2.fillText("no.2缩放",80,100); ctx2.scale(4,4) //这个缩放是让画布回到原来的大小 ctx2.fillStyle="red"; ctx2.font="20px 微软雅黑"; ctx2.fillText("no.3缩放",80,120); ctx2.scale(1.2,1.2) //在上一场的基础上放大1.2倍 ctx2.fillStyle="red"; ctx2.font="20px 微软雅黑"; ctx2.fillText("no.4缩放",80,120); //canvas旋转 var c3=document.getElementById('myCanvas3'); var ctx3=c3.getContext('2d'); ctx3.fillStyle="red"; ctx3.font="20px 微软雅黑"; ctx3.fillText("no.1原始",80,120); ctx3.rotate(Math.PI/8) //画布旋转了45度 ctx3.fillStyle="red"; ctx3.font="20px 微软雅黑"; ctx3.fillText("no.1原始",80,120); //canvas平移和旋转 var c4=document.getElementById('myCanvas4'); var ctx4=c4.getContext('2d'); ctx4.translate(100,100) //画布中心点在原画布的中心点上,而不是在左上角了 ctx4.fillStyle="red"; ctx4.font="20px 微软雅黑"; ctx4.fillText("no.1原始",0,10); ctx4.rotate(Math.PI/4) //画布旋转了45度 ctx4.fillStyle="red"; ctx4.font="20px 微软雅黑"; ctx4.fillText("no.1旋转",0,10); ctx4.rotate(Math.PI/4) //画布旋转了90度 ctx4.fillStyle="red"; ctx4.font="20px 微软雅黑"; ctx4.fillText("no.2旋转",0,10); ctx4.rotate(Math.PI/4) //画布旋转了135度 ctx4.fillStyle="red"; ctx4.font="20px 微软雅黑"; ctx4.fillText("no.3旋转",0,10); ctx4.rotate(Math.PI/4) //画布旋转了180度 ctx4.fillStyle="red"; ctx4.font="20px 微软雅黑"; ctx4.fillText("no.4旋转",0,10); ctx4.rotate(Math.PI/4) //画布旋转了225度 ctx4.fillStyle="red"; ctx4.font="20px 微软雅黑"; ctx4.fillText("no.5旋转",0,10); ctx4.rotate(Math.PI/4) //画布旋转了270度 ctx4.fillStyle="red"; ctx4.font="20px 微软雅黑"; ctx4.fillText("no.6旋转",0,10); ctx4.rotate(Math.PI/4) //画布旋转了360度 ctx4.fillStyle="red"; ctx4.font="20px 微软雅黑"; ctx4.fillText("no.7旋转",0,10);</script></body></html>
0 0
- canvas旋转,平移,缩放一二例
- canvas 平移 缩放 旋转
- Bitmap和Canvas的平移、缩放、旋转
- 图片处理(旋转,平移,缩放)View---Canvas;Paint;Bitmap
- canvas之图形的变化(平移,缩放,旋转)
- canvas之图形的变化(保存,平移,缩放,旋转)
- canvas之图形的变化(平移,缩放,旋转)
- Html5 canvas学习5-图形变形:缩放 旋转 平移 变形
- Direct 平移,旋转,缩放
- Transform【缩放、平移、旋转】
- Quartz2D-平移,旋转,缩放
- OpenGLES---平移/旋转/缩放
- Graphics平移缩放旋转
- 手势 平移 缩放 旋转
- 自定义控件(11)---Canvas的平移、旋转、缩放、错切、Matrix直接变换Canvas
- OpenGL中的平移旋转缩放
- [C#] Graphics平移缩放旋转
- Quartz2D-3(旋转、平移、缩放)
- myEclipse多个workspace使用相同的配置
- VR学习(Demo)以及在Unity3D上的项目
- oracle中110个常用函数介绍
- hdu 5739 2016多校2
- jquery的对象数组的添加元素,删除元素
- canvas旋转,平移,缩放一二例
- NYOJ 1000 又见斐波那契数列
- 垃圾收集器,详解jdk参数配置
- Android网络技术
- Android App优化
- 《编程之美》3.6判断链表是否相交之扩展:链表找环方法证明
- WPF TreeView tools
- IDE的一键Build背后隐藏了什么
- HTML高级知识