高考加油(Python+HTML)

打印 上一主题 下一主题

主题 1990|帖子 1990|积分 5970

前言

询问DeepSeek根据自己所学到的知识来生成多个可执行的代码,为高考学子加油。最开始生成的都会有点小问题,还是必要自己调试一遍,下面就是完备的代码,当然了最后几天也不会有多少人看,都在用心的备考。
Python励志桌面程序

  1. pip install pyqt5
复制代码
通过按下ESC键举行退出。 
  1. # 文件名:inspire_screensaver.py
  2. import sys
  3. import random
  4. import time
  5. from PyQt5.QtWidgets import QApplication, QWidget, QLabel
  6. from PyQt5.QtCore import Qt, QTimer, QPoint
  7. from PyQt5.QtGui import QFont, QColor, QPainter
  8. class Screensaver(QWidget):
  9.     def __init__(self):
  10.         super().__init__()
  11.         self.texts = [
  12.             "你考的不是试,是前途和暮年的欢喜",
  13.             "关关难过关关过,前路漫漫亦灿灿",
  14.             "愿你合上笔盖的刹那,有侠客收剑入鞘的骄傲",
  15.             "笔锋所指处,皆是心之所向,愿合笔时如收刀入鞘般骄傲!",
  16.             "十二载星月为伴,今朝试锋,定当光芒万丈",
  17.             "你的考卷终将化作通向理想大学的云梯,拾级而上终见星辰",
  18.             "此刻奋笔疾书的每个字,都是未来人生的精彩伏笔",
  19.             "乾坤未定,你我皆是奔腾向前的黑马",
  20.             "愿提笔时惊风落雨,收卷日笑看云起",
  21.             "寒窗墨香终成剑,一朝出鞘动四方",
  22.             "且将新火试新茶,少年仗剑趁年华",
  23.             "鹏北海,凤朝阳,今携书剑路茫茫",
  24.             "春风得意马蹄疾,一日看尽长安花",
  25.             "不必追求完美答卷,只需写出青春无悔",
  26.             "错的每道题都是为了遇见对的人,对的每道题都是为了遇见更好的自己",
  27.             "高考只是人生车站,从容下车后还有万里山河待你丈量",
  28.             "备好2B铅笔,也请带上百分百的勇气",
  29.             "早餐要吃好,准考证别忘带,你平稳发挥就是最棒状态",
  30.             "当交卷铃声响起,整个世界都会为你的坚持鼓掌",
  31.             "把三年青春浓缩成笔尖锋芒,刺破迷茫照亮远方",
  32.             "此刻你不仅是考生,更是手握命运改写权的英雄",
  33.             "那些熬过的夜终将化作星光,铺就你的状元之路",
  34.             "少年应有鸿鹄志,当骑骏马踏平川",
  35.             "愿九月踏入的校园,正是你此刻心驰神往的方向",
  36.             "今日考场方寸地,明日天地任尔行",
  37.             "这场考试过后,你选择的世界正在向你奔来",
  38.             "现在写下的每个答案,都在勾勒未来人生的轮廓",
  39.             "金榜题名时,勿忘与恩师共赏这漫天彩霞",
  40.             "请相信:你的long类型努力终将转化为double型成功",
  41.             "人生不是单选题,但这次请坚定选择自己的最优解",
  42.             "用三年的函数积累,求导出最灿烂的极值人生",
  43.             "当交卷铃声如约而至,便是你开启新副本的入场音效",
  44.             "这场考试的隐藏奖励是:解锁无限可能的人生DLC"
  45.         ]
  46.         self.initUI()
  47.         # 初始化存储数组
  48.         self.positions = []  # 存储(坐标, 颜色, 文本)
  49.         self.time_stamps = []  # 对应生成时间戳
  50.         self.directions = []  # 移动方向向量
  51.         # 运动参数配置
  52.         self.timer = QTimer(self)
  53.         self.timer.timeout.connect(self.update)
  54.         self.timer.start(40)  # 刷新间隔(ms)
  55.         self.fade_speed = 1.5  # 淡出速度
  56.         self.max_trails = 15  # 最大点数
  57.         self.move_speed = 2  # 移动速度(像素/帧)
  58.     def initUI(self):
  59.         self.setWindowTitle("高考加油屏保")
  60.         self.showFullScreen()
  61.         self.setCursor(Qt.BlankCursor)
  62.         self.setStyleSheet("background: black;")
  63.         # 退出提示标签(动态适应分辨率)
  64.         self.status_label = QLabel("按 ESC 退出", self)
  65.         self.status_label.setStyleSheet("color: white; font-size: 16px;")
  66.         self.status_label.adjustSize()
  67.         self.status_label.move(10, self.height() - self.status_label.height() - 10)
  68.     def paintEvent(self, event):
  69.         painter = QPainter(self)
  70.         painter.setRenderHint(QPainter.Antialiasing)
  71.         current_time = time.time()
  72.         text_metrics = painter.fontMetrics()
  73.         text_font = QFont("微软雅黑", 20)  # 字号从默认调整为20
  74.         painter.setFont(text_font)
  75.         # === 运动计算 ===
  76.         survived_indices = []
  77.         for idx in range(min(len(self.positions), len(self.time_stamps), len(self.directions))):
  78.             age = current_time - self.time_stamps[idx]
  79.             alpha = 255 - int(self.fade_speed * age * 30)
  80.             if alpha > 0:  # 保留未消失的点
  81.                 survived_indices.append(idx)
  82.         # 更新存活点数据(严格同步截断)
  83.         self.positions = [self.positions[i] for i in survived_indices][:self.max_trails]
  84.         self.directions = [self.directions[i] for i in survived_indices][:self.max_trails]
  85.         self.time_stamps = [self.time_stamps[i] for i in survived_indices][:self.max_trails]
  86.         # === 移动计算 ===
  87.         new_positions = []
  88.         new_directions = []
  89.         for idx in range(len(self.positions)):
  90.             (pos, color, text) = self.positions[idx]
  91.             dx, dy = self.directions[idx]
  92.             # 计算新坐标(带边界约束)
  93.             text_width = text_metrics.width(text)
  94.             text_height = text_metrics.height()
  95.             new_x = pos.x() + dx
  96.             new_y = pos.y() + dy
  97.             # 边界反弹处理
  98.             if new_x < 0 or new_x > (self.width() - text_width):
  99.                 dx = -dx * 0.8
  100.                 new_x = max(0, min(new_x, self.width() - text_width))
  101.             if new_y < text_height or new_y > (self.height() - text_height):
  102.                 dy = -dy * 0.8
  103.                 new_y = max(text_height, min(new_y, self.height() - text_height))
  104.             new_positions.append((QPoint(int(new_x), int(new_y)), color, text))
  105.             new_directions.append((dx, dy))
  106.         # 更新数据
  107.         self.positions = new_positions
  108.         self.directions = new_directions
  109.         # === 生成新点 ===
  110.         while len(self.positions) < self.max_trails:
  111.             new_text = random.choice(self.texts)
  112.             text_width = text_metrics.width(new_text)
  113.             text_height = text_metrics.height()
  114.             # 安全坐标生成(带异常处理)
  115.             try:
  116.                 safe_x = random.randint(0, self.width() - text_width)
  117.                 safe_y = random.randint(text_height, self.height() - text_height)
  118.             except ValueError:
  119.                 safe_x = 0
  120.                 safe_y = text_height
  121.             self.positions.append((
  122.                 QPoint(safe_x, safe_y),
  123.                 QColor(
  124.                     random.randint(150, 255),
  125.                     random.randint(150, 255),
  126.                     random.randint(150, 255)
  127.                 ),
  128.                 new_text
  129.             ))
  130.             self.directions.append((
  131.                 random.uniform(-self.move_speed, self.move_speed),
  132.                 random.uniform(-self.move_speed, self.move_speed)
  133.             ))
  134.             self.time_stamps.append(time.time())
  135.         # === 绘制所有点 ===
  136.         for (pos, color, text), ts in zip(self.positions, self.time_stamps):
  137.             age = current_time - ts
  138.             alpha = max(0, 255 - int(self.fade_speed * age * 50))
  139.             painter.setPen(QColor(
  140.                 color.red(),
  141.                 color.green(),
  142.                 color.blue(),
  143.                 alpha
  144.             ))
  145.             painter.drawText(pos, text)
  146.     def keyPressEvent(self, event):
  147.         if event.key() == Qt.Key_Escape:
  148.             self.close()
  149. if __name__ == "__main__":
  150.     # Windows系统内存优化
  151.     if sys.platform == 'win32':
  152.         import ctypes
  153.         ctypes.windll.kernel32.SetProcessWorkingSetSize(-1, 0x100000, 0x200000)
  154.     app = QApplication(sys.argv)
  155.     ex = Screensaver()
  156.     sys.exit(app.exec_())
复制代码

Vue3互动网页

时间设置的是const target = new Date('2025-06-07T09:00:00')
[code]<!-- 文件结构 -->
<!-- index.html -->
<!DOCTYPE html>
<html>

<head>
    <title>高考能量站</title>
    <script src="https://unpkg.com/vue@3"></script>
    <style>
        body {
            margin: 0;
            background: linear-gradient(45deg, #1a237e, #4a148c);
            height: 100vh;
            overflow: hidden;
        }

        #app {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: white;
        }

        .countdown {
            font-size: 3em;
            text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
        }

        .btn {
            padding: 15px 30px;
            background: #00e676;
            border: none;
            border-radius: 25px;
            font-size: 1.2em;
            cursor: pointer;
            transition: transform 0.3s;
        }

        canvas {
            position: fixed;
            top: 0;
            left: 0;
            pointer-events: none;
        }
    </style>
</head>

<body>
    <div id="app">
        <h1>高考能量补给站</h1>
        <div class="countdown">{{ days }}天{{ hours }}时{{ minutes }}分{{ second }}秒</div>
        <button class="btn" @click="sendConfetti">获取好运</button>
        <canvas ref="canvas"></canvas>
    </div>

    <script>
        const { createApp, ref, onMounted } = Vue;

        createApp({
            setup() {
                const canvas = ref(null)
                const days = ref(0)
                const hours = ref(0)
                const minutes = ref(0)
                const second = ref(0)
                let ctx = null

                // 倒计时计算
                const updateTime = () => {
                    // 高考时间(今年是25年了)
                    const target = new Date('2025-06-07T09:00:00')
                    const now = new Date()
                    const diff = target - now

                    days.value = Math.floor(diff / (1000 * 60 * 60 * 24))
                    hours.value = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
                    minutes.value = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
                    second.value = Math.floor((diff % (1000 * 60)) / 1000)
                }

                // 彩纸特效
                const sendConfetti = () => {
                    for (let i = 0; i < 50; i++) {
                        const x = Math.random() * canvas.value.width
                        const y = Math.random() * canvas.value.height
                        ctx.fillStyle = `hsl(${Math.random() * 360}, 70%, 60%)`
                        ctx.beginPath()
                        ctx.arc(x, y, 3, 0, Math.PI * 2)
                        ctx.fill()
                    }
                    console.log('

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

西河刘卡车医

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表