canvas之旋转一条线段

1 <canvas id="canvas" width="600" height="500" style="background-color: yellow;"></canvas>
 1  var canvas=document.getElementById("canvas");
 2     var cxt=canvas.getContext(‘2d‘);
 3     cxt.lineWidth=10;
 4     cxt.beginPath();
 5     cxt.moveTo(20,20);
 6     cxt.lineTo(180,20)
 7     cxt.stroke();
 8     cxt.closePath();
 9
10     //设置异次元空间
11     cxt.save();
12     //异次元空间 重置原点,默认是画布的(0,0)点
13     cxt.translate(20,20);
14     //设置旋转角度  参数时弧度 角度0--360 弧度=角度*Math.PI/180
15     cxt.rotate(-30*Math.PI/180);
16     //旋转一个线段
17     cxt.lineWidth=10;
18     cxt.beginPath();
19     cxt.moveTo(0,0);
20     cxt.lineTo(20,180);
21     cxt.stroke();
22     cxt.closePath();
23     //将旋转之后的元素返回原画布
24     cxt.restore();

canvas之旋转一条线段

时间: 2024-10-16 15:01:58

canvas之旋转一条线段的相关文章

canvas之画一条线段

1 var canvas=document.getElementById("canvas"); 2 //设置绘图环境 3 var cxt=canvas.getContext('2d'); 4 //开启新路近 5 cxt.beginPath(); 6 // 设置笔触的宽度 7 cxt.lineWidth=10; 8 //设置笔触的颜色 9 cxt.strokeStyle="#00ff00"; 10 //设定笔触的位置 11 cxt.moveTo(20,20); 12

当前插入的线段能完整覆盖存在的几条线段 树状数组 HDU 5372 Segment Game

http://acm.hdu.edu.cn/showproblem.php? pid=5372 Segment Game Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1284    Accepted Submission(s): 375 Problem Description Lillian is a clever girl so

(hdu step 5.1.3)Segment set(求与一条线段相交的线段集合中的线段的数量)

题目: Segment set Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 177 Accepted Submission(s): 82   Problem Description A segment and all segments which are connected with it compose a segment set. T

每次输出有几条线段能完全覆盖大于自己和hdu5372相反 树状数组或线段树 poj 2481 Cows

http://poj.org/problem?id=2481 Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 14762   Accepted: 4886 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one

(hdu 7.1.2)You can Solve a Geometry Problem too(求n条线段中,线段两两相交的数量)

题目: You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 145 Accepted Submission(s): 100   Problem Description Many geometry(几何)problems were designed in the ACM/IC

poj3304Segments(直线与多条线段相交)

链接 枚举两点(端点),循环遍历与直线相交的线段. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include<set>

关于Canvas的旋转和平移

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

HTML5 Canvas绘制环形进度条

最近比较迷恋canvas,加之做了一个个人网站,有用到环形进度条,记录下来. canvas中没有直接绘制圆的方法,但有一个绘制弧线的context.arc方法, 下面讲下用该方法如何绘制出图片效果. arc()方法介绍 context.arc(x,y,r,sAngle,eAngle,counterclockwise); 参数说明: x: 圆的中心的 x 坐标 y: 圆的中心的 y 坐标 r: 圆的半径 sAngle: 起始角,以弧度计.(弧的圆形的三点钟位置是 0 度) eAngle: 结束角,

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