Advertisement
askanton

Відтворюємо еволюцію на #python(web)

Apr 15th, 2023
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.14 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Еволюційна модель</title>
  6. </head>
  7. <body>
  8.     <h1>Еволюційна модель</h1>
  9.     <h2>Поточне середовище: {{ environment }}</h2>
  10.     <div id="population-area" style="width: 500px; height: 500px; border: 1px solid black; display: flex; flex-wrap: wrap;"></div>
  11.     <form method="post">
  12.         <button type="submit">Наступне покоління</button>
  13.     </form>
  14.     <script>
  15.         // Define a function to generate the emoji for each individual in the population
  16.         function generateEmoji(individual) {
  17.             if (individual == 'A') {
  18.                 return '🐀';
  19.             } else {
  20.                 return '🐁';
  21.             }
  22.         }
  23.  
  24.         // Get the population and population area elements from the HTML
  25.         var population = {{ population|tojson }};
  26.         var populationArea = document.getElementById("population-area");
  27.  
  28.         // Loop through the population and add each individual to the population area as an emoji
  29.         for (var i = 0; i < population.length; i++) {
  30.            var emoji = generateEmoji(population[i]);
  31.            var square = document.createElement("div");
  32.            square.style.width = "50px";
  33.            square.style.height = "50px";
  34.            square.style.border = "1px solid black";
  35.            square.style.textAlign = "center";
  36.            square.style.fontSize = "40px";
  37.            square.style.lineHeight = "50px";
  38.            square.innerText = emoji;
  39.            if (i % Math.sqrt(population.length) == Math.floor(i / Math.sqrt(population.length))) {
  40.                square.style.borderLeft = "none";
  41.                square.style.borderTop = "none";
  42.            } else if (i % Math.sqrt(population.length) == Math.floor(i / Math.sqrt(population.length)) + 1) {
  43.                square.style.borderRight = "none";
  44.                square.style.borderBottom = "none";
  45.            } else {
  46.                square.style.border = "none";
  47.            }
  48.            populationArea.appendChild(square);
  49.        }
  50.    </script>
  51. </body>
  52. </html>
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement