-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algorithm_ballMaze.html
218 lines (189 loc) · 4.39 KB
/
Algorithm_ballMaze.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ball Maze Animation</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
}
.maze {
position: relative;
width: 300px;
height: 300px;
border: 2px solid #000;
background-color: #fff;
border-radius:10px;
}
.wall {
position: absolute;
background-color: #000;
}
.wall1 {
top: 0;
left: 50px;
width: 3px;
height: 200px;
}
.wall2 {
top: 150px;
left: 100px;
width: 2px;
height: 100px;
}
.wall3{
top: 100px;
left: 100px;
width: 150px;
height: 2px;
}
.wall4{
top: 250px;
left: 50px;
width: 50px;
height: 2px;
}
.wall5{
top: 200px;
left: 50px;
width: 50px;
height: 2px;
}
.wall6{
top: 100px;
left: 150px;
width: 3px;
height: 200px;
}
.wall6{
top: 50px;
left: 100px;
width: 2px;
height: 50px;
}
.wall7{
top: 50px;
left: 150px;
width: 3px;
height: 250px;
}
.wall8{
top: 150px;
left: 200px;
width: 3px;
height: 150px;
}
.wall9{
top: 150px;
left: 250px;
width: 3px;
height: 100px;
}
.wall10{
top: 250px;
left: 250px;
width: 50px;
height: 2px;
}
.wall11{
top: 50px;
left: 200px;
width: 100px;
height: 2px;
}
.start{
position:absolute;
top: 5px;
color:green;
}
.end{
position:absolute;
bottom: 5px;
right:5px;
color:red;
}
.ball {
position: absolute;
width: 30px;
height: 30px;
top: 0;
left: 0;
animation: moveBall 10s linear infinite paused;
}
@keyframes moveBall {
0% { top: 15px; left: 15px; }
10% { top: 260px; left: 15px; }
15% { top: 260px; left: 120px; }
20% { top: 120px; left: 120px; }
30% { top: 120px; left: 60px; }
35% { top: 15px; left: 60px; }
45% { top: 15px; left: 160px; }
50% { top: 60px; left: 160px; }
60% { top: 60px; left: 260px; }
70% { top: 120px; left: 260px; }
80% { top: 120px; left: 220px; }
90% { top: 260px; left: 220px; }
100% { top: 260px; left: 260px; }
}
.controls {
margin-top: 20px;
}
.controls button {
margin: 0 5px;
padding: 10px 20px;
background-color:yellow;
font-size: 16px;
cursor: pointer;
transition:200ms;
border-radius:10px;
}
.controls button:hover{
transform:scale(1.1);
}
</style>
</head>
<body>
<div class="maze">
<div class="wall wall1"></div>
<div class="wall wall2"></div>
<div class="wall wall3"></div>
<div class="wall wall4"></div>
<div class="wall wall5"></div>
<div class="wall wall6"></div>
<div class="wall wall7"></div>
<div class="wall wall8"></div>
<div class="wall wall9"></div>
<div class="wall wall10"></div>
<div class="wall wall11"></div>
<div class="start"> START</div>
<div class="end"> END </div>
<img class="ball" src="https://static.vecteezy.com/system/resources/previews/011/887/128/original/black-metal-ball-png.png" id="ball"/>
</div>
<div class="controls">
<button onclick="startBall()">Start</button>
<button onclick="resumeBall()">Resume</button>
<button onclick="stopBall()">Stop</button>
</div>
<script>
const ball = document.getElementById('ball');
function startBall() {
ball.style.animation = 'none';
ball.offsetHeight;
ball.style.animation = null;
ball.style.animationPlayState = 'running';
}
function resumeBall() {
ball.style.animationPlayState = 'running';
}
function stopBall() {
ball.style.animationPlayState = 'paused';
}
</script>
</body>
</html>