Saurabh502 commited on
Commit
4bee0c3
·
verified ·
1 Parent(s): b89151f

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +131 -29
index.html CHANGED
@@ -1,29 +1,131 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <link rel="stylesheet" href="style.css" />
7
-
8
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
- <title>Transformers.js - Object Detection</title>
10
- </head>
11
-
12
- <body>
13
- <h1>Object Detection w/ 🤗 Transformers.js</h1>
14
- <label id="container" for="upload">
15
- <svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
16
- <path fill="#000"
17
- d="M3.5 24.3a3 3 0 0 1-1.9-.8c-.5-.5-.8-1.2-.8-1.9V2.9c0-.7.3-1.3.8-1.9.6-.5 1.2-.7 2-.7h18.6c.7 0 1.3.2 1.9.7.5.6.7 1.2.7 2v18.6c0 .7-.2 1.4-.7 1.9a3 3 0 0 1-2 .8H3.6Zm0-2.7h18.7V2.9H3.5v18.7Zm2.7-2.7h13.3c.3 0 .5 0 .6-.3v-.7l-3.7-5a.6.6 0 0 0-.6-.2c-.2 0-.4 0-.5.3l-3.5 4.6-2.4-3.3a.6.6 0 0 0-.6-.3c-.2 0-.4.1-.5.3l-2.7 3.6c-.1.2-.2.4 0 .7.1.2.3.3.6.3Z">
18
- </path>
19
- </svg>
20
- Click to upload image
21
- <label id="example">(or try example)</label>
22
- </label>
23
- <label id="status">Loading model...</label>
24
- <input id="upload" type="file" accept="image/*" />
25
-
26
- <script src="index.js" type="module"></script>
27
- </body>
28
-
29
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Snake Game</title>
7
+ <style>
8
+ body {
9
+ display: flex;
10
+ justify-content: center;
11
+ align-items: center;
12
+ height: 100vh;
13
+ margin: 0;
14
+ background-color: #f0f0f0;
15
+ }
16
+ canvas {
17
+ border: 1px solid black;
18
+ background-color: #fff;
19
+ }
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <canvas id="gameCanvas" width="400" height="400"></canvas>
24
+
25
+ <script>
26
+ const canvas = document.getElementById('gameCanvas');
27
+ const ctx = canvas.getContext('2d');
28
+ const box = 20; // Size of each grid box
29
+ const canvasSize = 400;
30
+
31
+ let snake = [];
32
+ snake[0] = { x: 9 * box, y: 10 * box }; // Initial snake position
33
+
34
+ let food = {
35
+ x: Math.floor(Math.random() * (canvasSize / box)) * box,
36
+ y: Math.floor(Math.random() * (canvasSize / box)) * box
37
+ };
38
+
39
+ let score = 0;
40
+ let direction;
41
+
42
+ document.addEventListener('keydown', setDirection);
43
+
44
+ function setDirection(event) {
45
+ if (event.keyCode == 37 && direction != 'RIGHT') {
46
+ direction = 'LEFT';
47
+ } else if (event.keyCode == 38 && direction != 'DOWN') {
48
+ direction = 'UP';
49
+ } else if (event.keyCode == 39 && direction != 'LEFT') {
50
+ direction = 'RIGHT';
51
+ } else if (event.keyCode == 40 && direction != 'UP') {
52
+ direction = 'DOWN';
53
+ }
54
+ }
55
+
56
+ function collision(head, array) {
57
+ for (let i = 0; i < array.length; i++) {
58
+ if (head.x == array[i].x && head.y == array[i].y) {
59
+ return true;
60
+ }
61
+ }
62
+ return false;
63
+ }
64
+
65
+ function draw() {
66
+ // Clear canvas
67
+ ctx.fillStyle = 'white';
68
+ ctx.fillRect(0, 0, canvasSize, canvasSize);
69
+
70
+ // Draw snake
71
+ for (let i = 0; i < snake.length; i++) {
72
+ ctx.fillStyle = (i == 0) ? 'green' : 'lightgreen';
73
+ ctx.fillRect(snake[i].x, snake[i].y, box, box);
74
+ ctx.strokeStyle = 'darkgreen';
75
+ ctx.strokeRect(snake[i].x, snake[i].y, box, box);
76
+ }
77
+
78
+ // Draw food
79
+ ctx.fillStyle = 'red';
80
+ ctx.fillRect(food.x, food.y, box, box);
81
+
82
+ // Old head position
83
+ let snakeX = snake[0].x;
84
+ let snakeY = snake[0].y;
85
+
86
+ // Which direction
87
+ if (direction == 'LEFT') snakeX -= box;
88
+ if (direction == 'UP') snakeY -= box;
89
+ if (direction == 'RIGHT') snakeX += box;
90
+ if (direction == 'DOWN') snakeY += box;
91
+
92
+ // If the snake eats the food
93
+ if (snakeX == food.x && snakeY == food.y) {
94
+ score++;
95
+ food = {
96
+ x: Math.floor(Math.random() * (canvasSize / box)) * box,
97
+ y: Math.floor(Math.random() * (canvasSize / box)) * box
98
+ };
99
+ // Don't remove tail
100
+ } else {
101
+ // Remove the tail
102
+ snake.pop();
103
+ }
104
+
105
+ // New head
106
+ let newHead = {
107
+ x: snakeX,
108
+ y: snakeY
109
+ };
110
+
111
+ // Game over conditions
112
+ if (snakeX < 0 || snakeX >= canvasSize || snakeY < 0 || snakeY >= canvasSize || collision(newHead, snake)) {
113
+ clearInterval(game);
114
+ alert('Game Over! Score: ' + score);
115
+ // Optionally reset game or provide restart button
116
+ document.location.reload(); // Simple reload to restart
117
+ }
118
+
119
+ snake.unshift(newHead);
120
+
121
+ // Draw score
122
+ ctx.fillStyle = 'black';
123
+ ctx.font = '20px Arial';
124
+ ctx.fillText('Score: ' + score, box, 1.6 * box);
125
+ }
126
+
127
+ let game = setInterval(draw, 100); // Game loop speed
128
+
129
+ </script>
130
+ </body>
131
+ </html>