Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from flask import Flask, render_template_string, session
- import random
- app = Flask(__name__)
- app.secret_key = "your_secret_key"
- heritage = 0
- stop = 0
- @app.route("/")
- def index():
- global heritage, stop
- template = """
- <!DOCTYPE html>
- <html>
- <head>
- <title>Mountain Visualization</title>
- <style>
- body {
- margin: 0;
- }
- .container {
- position: relative;
- display: flex;
- }
- .mountain {
- position: relative;
- width: 0;
- height: 0;
- border-left: 75px solid transparent;
- border-right: 75px solid transparent;
- border-bottom: 200px solid gray;
- margin-right: -10px;
- transform: translateY(50px);
- }
- .plateau {
- background-color: green;
- width: 350px;
- height: 50px;
- margin-right: -10px;
- transform: translateY(200px);
- }
- .plateau_wide {
- background-color: green;
- width: 950px;
- height: 50px;
- margin-right: -10px;
- transform: translateY(200px);
- }
- .cliff {
- background-color: black;
- width: 350px;
- height: 150px;
- margin-right: -10px;
- transform: translateY(250px);
- }
- .circle {
- position: absolute;
- border-radius: 50%;
- }
- .circle.fat {
- background-color: blue;
- width: 25px;
- height: 25px;
- }
- .circle.medium {
- background-color: orange;
- width: 15px;
- height: 15px;
- }
- .circle.slim {
- background-color: red;
- width: 5px;
- height: 5px;
- }
- .circle.new {
- background-color: yellow;
- width: 40px;
- height: 40px;
- }
- .color-count {
- transform: translateY(-60px);
- font-weight: bold;
- }
- </style>
- <meta http-equiv="refresh" content="3">
- </head>
- <body>
- <div class="container">
- <div class="cliff"></div>
- <div class="plateau"></div>
- <div class="mountain"></div>
- <div class="plateau_wide"></div>
- {% for circle in circles %}
- <div class="circle {{ circle.circle }}" style="bottom: {{ circle.bottom }}; left: {{ circle.left }}px;"></div>
- {% endfor %}
- </div>
- <div class="color-count">
- Blue Circles: {{ color_counts.blue }}
- </div>
- <div class="color-count">
- Orange Circles: {{ color_counts.orange }}
- </div>
- <div class="color-count">
- Red Circles: {{ color_counts.red }}
- </div>
- <div class="color-count">
- New Circles: {{ color_counts.new }}
- </div>
- <div class="color-count">
- Generation: {{ color_counts.gen }}
- </div>
- </body>
- </html>
- """
- if "refresh_count" not in session:
- session["refresh_count"] = 0
- i = session["refresh_count"]
- if stop == 1:
- time.sleep(1000)
- def create_circle(fat):
- if fat >= 40 and fat <= 100:
- circle = "fat"
- left = random.randint(350, 650)
- bottom = "0px"
- elif fat >= 20 and fat < 40:
- circle = "medium"
- left = random.randint(50, 300)
- bottom = "-55px"
- elif fat > 0 and fat < 20:
- circle = "slim"
- left = random.randint(720, 780)
- bottom = "50px"
- if fat == 0:
- circle = "new"
- left = random.randint(800, 900)
- bottom = "0px"
- return {"circle": circle, "bottom": bottom, "left": left}
- if heritage == 0:
- circles = [create_circle(random.randint(19, 100)) for _ in range(20)]
- elif heritage == 1:
- circles = [create_circle(random.randint(1, 100)) for _ in range(20)]
- elif heritage == 2:
- circles = [create_circle(random.randint(1, 100)) for _ in range(20)]
- circles.append({"circle": "new", "bottom": "0px", "left": 900})
- stop = 1
- color_counts = {
- "blue": sum(circle["circle"] == "fat" for circle in circles),
- "orange": sum(circle["circle"] == "medium" for circle in circles),
- "red": sum(circle["circle"] == "slim" for circle in circles),
- "new": sum(circle["circle"] == "new" for circle in circles),
- "gen": i,
- }
- if color_counts["red"] > 6:
- heritage = 2
- elif color_counts["red"] > 0:
- heritage = 1
- else:
- heritage = 0
- session["refresh_count"] += 1
- return render_template_string(template, circles=circles, color_counts=color_counts)
- if __name__ == "__main__":
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement