Skip to content

Commit 5156cf4

Browse files
committed
update
1 parent 4a92b58 commit 5156cf4

5 files changed

Lines changed: 94 additions & 23 deletions

File tree

Snow.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
$(document).ready(function () {
2-
window.onload = function () {
1+
2+
let icon = '';
3+
4+
fetch('http://dataservice.accuweather.com/forecasts/v1/daily/1day/324505?apikey=SD3IOUbAchPsZCz6KJoAfdoReCkm2wbk&metric=true')
5+
.then(function (resp) { return resp.json() })
6+
.then(function data(data) {
7+
console.log(data);
8+
icon = data.DailyForecasts[0].Day.Icon;
9+
const elem = document.getElementById('icon');
10+
elem.src = `https://www.accuweather.com/images/weathericons/${icon}.svg`
11+
atr = elem.getAttribute('src')
12+
console.log(atr);
13+
elem.onload = function () {
14+
var canvas = document.getElementById("canvas_icon");
15+
var ctx = canvas.getContext("2d");
16+
ctx.drawImage(elem, 100, 100);
17+
};
18+
interval = setInterval(elem.onload, 33)
19+
})
20+
.catch(function () { });
21+
22+
console.log(icon);
23+
24+
if (icon === 29 || (icon >= 19 && icon <= 23)) {
25+
26+
$(document).ready(function () {
27+
328
//canvas init
429
var canvas = document.getElementById("canvas");
530
var ctx = canvas.getContext("2d");
@@ -75,6 +100,8 @@ $(document).ready(function () {
75100

76101
//animation loop
77102
setInterval(draw, 33);
78-
}
79103

80-
})
104+
105+
})
106+
107+
}

app.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
2+
13
let canvas = document.getElementById("Canvas");
24
let ctx = canvas.getContext("2d");
35
//Variables
6+
function mathRendom() {
7+
return Math.round(Math.random() * 23 + 1) * cell;
8+
}
49
let cell = 20;
510
let score = 0;
6-
let deltaX = Math.round(Math.random() * 23 + 1) * cell;
7-
let deltaY = Math.round(Math.random() * 23 + 1) * cell;
8-
let fx = Math.round(Math.random() * 23 + 1) * cell;
9-
let fy = Math.round(Math.random() * 23 + 1) * cell;
11+
let deltaX = mathRendom();
12+
let deltaY = mathRendom();
13+
let fx = mathRendom();
14+
let fy = mathRendom();
1015
//snake boody
1116
let snake = [];
1217
snake[0] = {
@@ -21,6 +26,8 @@ snake[2] = {
2126
x: deltaX - cell * 2,
2227
y: deltaY
2328
};
29+
30+
2431
function drawSnake() {
2532
for (i = 0; i < snake.length; i++) {
2633
ctx.beginPath();
@@ -49,7 +56,6 @@ function drawSnake() {
4956

5057
}
5158
}
52-
drawSnake()
5359
/*apple drawl*/
5460
function food() {
5561
ctx.beginPath();
@@ -58,7 +64,7 @@ function food() {
5864
ctx.fillStyle = "#fa0a0a";
5965
ctx.fill();
6066
};
61-
food();
67+
6268

6369
//Collapse
6470
function eatTail(head, arr) {
@@ -126,15 +132,15 @@ function drawEyes() {
126132
ctx.fill();
127133
}
128134
}
129-
drawEyes()
135+
130136
function reDraw() {
131137
for (i = 0; i < snake.length; i++) {
132138
while (snake[i].x == fx && snake[i].y == fy) {
133139
fx = Math.round(Math.random() * 23 + 1) * cell, fy = Math.round(Math.random() * 23 + 1) * cell
134140
}
135141
}
136142
}
137-
reDraw();
143+
138144

139145
//Igra
140146
function drawGame() {
@@ -146,19 +152,15 @@ function drawGame() {
146152

147153
if (deltaX > canvas.width + cell) {
148154
deltaX = -cell;
149-
return deltaX;
150155
}
151156
if (deltaX < -cell) {
152157
deltaX = canvas.width + cell;
153-
return deltaX;
154158
}
155159
if (deltaY > canvas.height + cell) {
156160
deltaY = -cell;
157-
return deltaY;
158161
}
159162
if (deltaY < -cell) {
160163
deltaY = canvas.height + cell;
161-
return deltaY;
162164
}
163165
if (dir == "left") deltaX -= cell;
164166
if (dir == "right") deltaX += cell;
@@ -172,7 +174,7 @@ function drawGame() {
172174
function eat() {
173175
if (newHead.x === fx && newHead.y === fy) {
174176
score += 1
175-
return fx = Math.round(Math.random() * 23 + 1) * cell, fy = Math.round(Math.random() * 23 + 1) * cell;
177+
return fx = mathRendom(), fy = mathRendom();
176178

177179
} else {
178180
snake.pop();
@@ -189,15 +191,23 @@ function drawGame() {
189191
}
190192

191193
let game = '';
192-
let b1 = document.querySelector('.b1');
194+
let start = document.querySelector('.start');
193195

194-
b1.onclick = function f1() {
196+
start.onclick = () => {
195197
if (game == '') {
196198
game = setInterval(drawGame, 200);
197-
b1.innerHTML = 'RESTART'
199+
start.innerHTML = 'RESTART'
198200
}
199201
else {
200202
document.location.reload(true);
201203
}
202204
}
203205

206+
function init() {
207+
drawSnake();
208+
food();
209+
// drawEyes();
210+
reDraw();
211+
}
212+
213+
init();

index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
<body>
1111
<div class="container">
12-
<button class="b1">START</button>
12+
<button class="start">START</button>
1313
<canvas id="canvas" width="500" height="500"></canvas>
1414
<canvas id="Canvas" width="500" height="500"></canvas>
15+
<canvas id="canvas_icon" width="500" height="500"></canvas>
1516
</div>
17+
<img id="icon" class="hidden" src="" alt="">
1618

1719

1820

@@ -23,6 +25,7 @@
2325

2426

2527
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
28+
<!-- <script src="weather.js"></script> -->
2629
<script src="Snow.js"></script>
2730
<script src="app.js"></script>
2831

style.css

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@ body {
1313
background: #eee;
1414
display: block;
1515
position: absolute;
16+
z-index: 1;
1617
}
1718
#Canvas {
1819
background:transparent;
1920
display: block;
2021
position: absolute;
21-
z-index: 1;
22+
z-index: 3;
2223
}
23-
.b1 {
24+
#canvas_icon {
25+
background:transparent;
26+
display: block;
27+
position: absolute;
28+
z-index: 2;
29+
}
30+
.start {
2431
position: absolute;
2532
left: 200px;
2633
top: -30px;
2734
width: 100px;
2835
height: 30px;
2936
}
37+
.hidden {
38+
visibility: hidden;
39+
}

weather.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
fetch('http://dataservice.accuweather.com/forecasts/v1/daily/1day/324505?apikey=SD3IOUbAchPsZCz6KJoAfdoReCkm2wbk&metric=true')
4+
.then(function (resp) { return resp.json() })
5+
.then(function (data) {
6+
console.log(data);
7+
const icon = data.DailyForecasts[0].Day.Icon;
8+
const elem = document.getElementById('icon');
9+
elem.src = `https://www.accuweather.com/images/weathericons/${icon}.svg`
10+
atr = elem.getAttribute('src')
11+
console.log(atr);
12+
elem.onload = function () {
13+
var canvas = document.getElementById("canvas_icon");
14+
var ctx = canvas.getContext("2d");
15+
ctx.drawImage(elem, 100, 100);
16+
};
17+
ik = setInterval(elem.onload, 33)
18+
19+
20+
})
21+
.catch(function () { });

0 commit comments

Comments
 (0)