-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rotation.html
68 lines (68 loc) · 1.5 KB
/
Rotation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title></title>
<script>
function draw(id,deg){
var canvas = document.getElementById(id);
var context = canvas.getContext("2d");
context.fillStyle = "#eeeeef";
context.fillRect(0,0,1000,500);
var dx = 480;
var dy = 250;
var s = 100;
var dig = Math.PI / 15*11;
context.beginPath();
context.fillStyle = "rgb(220,20,60)";
context.strokeStyle = "rgb(255,215,0)";
for (var i = 0; i < 30; i++){
var x = Math.sin(i*dig+deg);
var y = Math.cos(i*dig+deg);
context.lineTo(dx+x*s,dy+y*s);
}
context.closePath();
context.fill();
context.stroke();
}
function whichButton(event){
var btnNum = event.button;
if (btnNum==0){
if (!ontransfer){
ontransfer = true;
dir = -dir;
}
}
}
</script>
</head>
<body onmousedown="whichButton(event)">
<!--move to line to-->
<canvas id="canvas" width="1000" height="500"></canvas>
<script>
var ddeg = Math.PI * 2 / 1440;
var dddeg = Math.PI * 2 / 1440 / 30;
var degpos = 0.0;
var ontransfer = false;
var dir = -1;
!function(){
if (!ontransfer){
draw("canvas",degpos);
degpos = degpos + ddeg;
if (degpos > Math.PI *2){degpos = degpos - Math.PI *2;}
}else{
ddeg = ddeg - dddeg*dir;
if (Math.abs(ddeg) > Math.PI * 2 / 1440){
ddeg = Math.round(Math.abs(ddeg)/ddeg)*Math.PI * 2 / 1440;
ontransfer = false;
}else{
draw("canvas",degpos);
degpos = degpos + ddeg;
if (degpos > Math.PI *2){degpos = degpos - Math.PI *2;}
}
}
setTimeout(arguments.callee,12);
}();
</script>
</body>
</html>