-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoving.html
More file actions
231 lines (187 loc) · 5.73 KB
/
moving.html
File metadata and controls
231 lines (187 loc) · 5.73 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MOVE</title>
<style>
canvas{
background: #fff;
border:2px #2ac1cc solid;
background: url("011.jpg");
}
h1{
font-family:Cambria,Cochin,Georgia,Times,"Times New Roman",Serif;
font-size: x-large;
color: #999999;
}
body{
background: #f4ffec;
padding:10px;
}
p{
font-family:"Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;
font-size: 20px;
}
a{
color:#3E99CA;
text-decoration: none;
}
.info{
background: #E2F0F8;
border:2px #7eccb6 solid;
width: 869px;
}
.place{
}
</style>
</head>
<body>
<h1>Aircraft Cruising</h1>
<div id="container">
<canvas id="myCanvas" width="1850px" height="835px">
Your browser does not support HTML5 canvas.
</canvas>
</div>
<div class="info">
<p><b>飞机位置信息:</b></p>
<p id="locationX">X--</p>
<p id="locationY">Y--</p>
</div>
<script type="text/javascript">
var canvas=document.querySelector("#myCanvas");
var ctx=canvas.getContext("2d");
var locationX=document.getElementById("locationX");
var locationY=document.getElementById("locationY");
canvasWidth=canvas.width;
canvasHeight=canvas.height;
var myImage=new Image();
myImage.src="flight5.jpg";
var placeImage=new Image();
placeImage.src="place.png";
// depending on your browser, the right version of the rAF function will be returned...I hope
var requestAnimationFrame = window.requestAnimationFrame
||window.mozRequestAnimationFrame
||window.webkitRequestAnimationFrame
||window.msRequestAnimationFrame;
//this array contains a reference to every flight that you will create
var flights=new Array();
//the location class of light
var c={
x:0,
y:0
};
//the flight get some angle
var angle=0;
var angle1=0;
var speedX=0;
var speedY=0;
var radius=70;
var radius1=0;
var bounce=-0.8;
//the function of draw to contain everything
function draw() {
ctx.clearRect(0,0,canvasWidth,canvasHeight);
drawPlace();
// drawScanning();
drawScanning2();
drawFlight();
move();
info();
requestAnimationFrame(draw);
}
//Your can see some flights in this place
function drawPlace() {
ctx.beginPath();
ctx.arc(50,50,100,0,Math.PI*2,true);
ctx.closePath();
ctx.fillStyle="#CC682E";
ctx.fill();
}
//the flights is fly in the sky
function drawFlight() {
ctx.fillStyle="rgba(0,0,0,0,0.4)";
ctx.strokeStyle="rgba(0,153,255,0.2)";
ctx.drawImage(myImage,c.x,c.y,30,30);
}
// //the scanning of flight
// function drawScanning() {
// ctx.beginPath();
// ctx.arc(c.x+radius*Math.cos(angle1),c.y+radius*Math.sin(angle1),5,0,Math.PI*2,true);
// ctx.closePath();
// ctx.fillStyle="#000";
// ctx.fill();
//
// angle1 += 0.1;
// }
//the scanning2 of flight
function drawScanning2() {
ctx.beginPath();
ctx.arc(c.x,c.y+12,radius1,Math.PI*(1/6),Math.PI*(-1/6),true);
ctx.closePath();
ctx.fillStyle="red";
ctx.fill();
if(radius1 < 100) {
radius1 += 5;
}else{
radius1 -= 100;
}
}
// //check the flight arrived at edge
// function checkEdge(x,y) {
// if(x > canvasWidth){
// speedX *= bounce;
// }
// if(y > canvasHeight){
// speedY *= bounce;
// }
// }
//how to fly for flights
function move() {
//flight fly randomly
// var decimal=Math.random();
// c.x=decimal*canvasWidth;
// c.y=decimal*canvasWeight;
// var a=0.001;
// speedX += a;
// //flight fly straight line in x
// c.x += speedX;
// if(c.x < canvasWidth) {
// c.x += speedX;
// }else{
// c.x -= canvasWidth;
// }
//
// speedY = 3;
// //flight fly straight line in y
// c.y += speedY;
// if(c.y < canvasHeight){
// c.y += speedY;
// }else{
// c.y -= canvasHeight;
// }
//flight fly in smooth motion
var range=60;
if(c.x < canvasWidth) {
c.x += 3;
}else{
c.x -= canvasWidth;
}
c.y = canvasHeight / 2 + Math.sin(angle) * range;
angle += 0.1;
//flight fly in curve
// if(c.y > canvasHeight){
// speedY *= bounce;
// }
// checkEdge(c.x,c.y);
}
//present the information of flight
function info(){
locationX.innerHTML="X-- <u>"+c.x.toFixed()+"</u>";
locationY.innerHTML="Y-- <u>"+c.y.toFixed()+"</u>";
}
//invoke to draw the map again ang again
draw();
//setInterval(draw,100000);
</script>
</body>
</html>