awacke1 commited on
Commit
c371d92
·
verified ·
1 Parent(s): 616c79e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +67 -19
index.html CHANGED
@@ -1,19 +1,67 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const canvas = document.getElementById("gameCanvas");
2
+ const ctx = canvas.getContext("2d");
3
+
4
+ // Hexagon properties
5
+ const hexSize = 50; // Size of each hexagon
6
+ const hexWidth = Math.sqrt(3) * hexSize;
7
+ const hexHeight = 2 * hexSize;
8
+ const offsetX = hexWidth * 0.75;
9
+ const offsetY = hexHeight * 0.5;
10
+ const rows = 10;
11
+ const cols = 10;
12
+
13
+ // Hex map storage
14
+ let hexGrid = [];
15
+
16
+ // Function to generate a hexagonal grid
17
+ function generateHexGrid() {
18
+ for (let row = 0; row < rows; row++) {
19
+ for (let col = 0; col < cols; col++) {
20
+ let x = col * offsetX;
21
+ let y = row * hexHeight + (col % 2 ? offsetY : 0);
22
+ hexGrid.push({ x, y, type: getRandomTerrain() });
23
+ }
24
+ }
25
+ }
26
+
27
+ // Function to draw hexagons
28
+ function drawHex(x, y, type) {
29
+ ctx.beginPath();
30
+ for (let i = 0; i < 6; i++) {
31
+ let angle = (Math.PI / 3) * i;
32
+ let px = x + hexSize * Math.cos(angle);
33
+ let py = y + hexSize * Math.sin(angle);
34
+ ctx.lineTo(px, py);
35
+ }
36
+ ctx.closePath();
37
+ ctx.fillStyle = getTerrainColor(type);
38
+ ctx.fill();
39
+ ctx.stroke();
40
+ }
41
+
42
+ // Function to assign random terrain types
43
+ function getRandomTerrain() {
44
+ const terrains = ["water", "plains", "forest", "mountain"];
45
+ return terrains[Math.floor(Math.random() * terrains.length)];
46
+ }
47
+
48
+ // Function to get terrain color
49
+ function getTerrainColor(type) {
50
+ switch (type) {
51
+ case "water": return "#3A80BA";
52
+ case "plains": return "#C2B280";
53
+ case "forest": return "#228B22";
54
+ case "mountain": return "#A9A9A9";
55
+ default: return "#FFFFFF";
56
+ }
57
+ }
58
+
59
+ // Function to render the map
60
+ function renderMap() {
61
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
62
+ hexGrid.forEach(hex => drawHex(hex.x, hex.y, hex.type));
63
+ }
64
+
65
+ // Initialize and draw map
66
+ generateHexGrid();
67
+ renderMap();