canvas 旋转

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8"></head><body>    <canvas id="myCanvas" style="border:1px solid red" width="300" height="300"></canvas>    <script>

function draw(){            var ctx = document.getElementById(‘myCanvas‘).getContext(‘2d‘);            //绘制背景            ctx.fillStyle="yellow";            ctx.fillRect(0,0,300,300);            ctx.fill();            //绘制圆形            ctx.beginPath();            ctx.arc(150,150,130,0,Math.PI*2,true);            //裁剪路径          //  ctx.clip();            ctx.translate(200,20);            for(var i=0;i<90;i++){                ctx.save();               ctx.transform(0.98,0,0,0.95,30,30);                ctx.rotate(Math.PI/12);                ctx.beginPath();                ctx.fillStyle="red";                ctx.globalAlpha="0.4";                ctx.arc(0,0,50,Math.PI*2,true);                ctx.closePath();                ctx.fill();            }        }        window.onload=function(){            draw();        }    </script></body></html>

				
时间: 2024-10-28 14:24:58

canvas 旋转的相关文章

canvas旋转

canvas旋转的两种方法: 1.先用translate()将(0,0)坐标移动到想要旋转的中心点,再用rotate()旋转,最后要用translate()将中心移回(0,0)点. 2.将要旋转的内容放在save()方法和restore()方法之间(类似于将两个方法里的绘制放在新的画布里),此方法也要用translate()方法移动(0,0)点,再用rotate()方法. 注意: 1.rotate()方法要放在绘制图形之前. 2.要先用translate()再用rotate(). 3.第一种方法

html5 canvas旋转

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

canvas旋转文本

canvas旋转文本 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatibl

[ html canvas 旋转 缩放 平移 ] canvas绘图实现旋转复制实例演示

<!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title> <meta name='description' content='this is my page'> <meta name='keywords' content='keyword1,keyword2,keyword3'> <meta http-equiv="

Canvas旋转图片--保持大小不变的算法

 function drawImg(angle) { canvas.width = canvas.width; var distance = size / 2 * Math.sqrt(2) * Math.sin(angle * Math.PI / 180 / 2) * 2; var degree = 180 - 45 - (180 - angle) / 2; var x = distance * Math.sin(degree * Math.PI / 180); var y = distanc

jQuery + Canvas 旋转的时钟

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Canvas</title> <script type="text/javascript" src="jQuery.js"></script> </head> <style type="text/css&q

html5 canvas 旋转扩大

<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> window.onload = function () { var oC = document.getElementById('c1'); var oGC = oC.getContext('2d'); var num = 0; var in

关于Canvas的旋转和平移

Drawable newDrawable = getResources().getDrawable(mImageIds[newState])                .mutate();Drawable oldDrawable = getResources().getDrawable(mImageIds[oldState])                .mutate();Bitmap bitmap = null; bitmap = Bitmap.createBitmap(width,

Android canvas rotate():平移旋转坐标系至任意原点任意角度-------附:android反三角函数小结

自然状态下,坐标系以屏幕左上角为原点,向右是x正轴,向下是y正轴.现在要使坐标系的原点平移至任一点O(x,y),且旋转a角度,如何实现? 交待下我的问题背景,已知屏幕上有两点p1和p2,构成直线l.我要以两点的中点mid(x,y)为坐标原点,线段l的中垂线为一个轴,l为另外一个轴,做一个坐标系.切割出一个边长为d的正方形.示意图如下所示: double d = Math.sqrt((p2.x-p1.x)*(p2.x - p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); //p1.p