鱼C论坛

 找回密码
 立即注册
查看: 54|回复: 6

[作品展示] 妇女节礼物!

[复制链接]
发表于 昨天 21:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

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

x
本帖最后由 不二如是 于 2026-3-9 08:08 编辑

妇女节礼物(代码)
python:
  1. import turtle
  2. import random

  3. # --- 第一部分:隐藏的加密逻辑 (核心) ---
  4. def encrypt_message(text, shift):
  5.     """凯撒密码加密函数"""
  6.     encrypted = ""
  7.     for char in text:
  8.         if char.isalpha():
  9.             # 转换为小写并进行位移
  10.             base = ord('a')
  11.             encrypted += chr((ord(char.lower()) - base + shift) % 26 + base)
  12.         else:
  13.             encrypted += char
  14.     return encrypted

  15. # 真正的祝福语
  16. SECRET_MESSAGE = "Happy Women's Day! You are amazing!"
  17. # 设定一个只有你知道的偏移量(这就是解密钥匙)
  18. SHIFT_KEY = 7

  19. # 加密后的乱码(会在画布上显示)
  20. ENCRYPTED_TEXT = encrypt_message(SECRET_MESSAGE, SHIFT_KEY)

  21. # --- 第二部分:Turtle 绘图 (视觉效果) ---
  22. def draw_puzzle():
  23.     screen = turtle.Screen()
  24.     screen.setup(800, 600)
  25.     screen.bgcolor("#1a1a2e")
  26.     screen.title("3.8 妇女节特别礼物:解密迷宫")

  27.     pen = turtle.Turtle()
  28.     pen.speed(0) # 最快速度
  29.     pen.hideturtle()
  30.     pen.width(2)

  31.     # 1. 画一个复杂的几何背景 (象征生活中的挑战与美丽)
  32.     for i in range(100):
  33.         pen.penup()
  34.         pen.goto(random.randint(-300, 300), random.randint(-200, 200))
  35.         pen.pendown()
  36.         
  37.         # 随机颜色
  38.         pen.color(random.random(), random.random(), random.random())
  39.         
  40.         # 画随机形状
  41.         for _ in range(4):
  42.             pen.forward(random.randint(50, 150))
  43.             pen.right(90 + random.randint(-10, 10))

  44.     # 2. 画出“迷宫路径” (象征寻找答案的过程)
  45.     pen.penup()
  46.     pen.goto(-350, -250)
  47.     pen.pendown()
  48.     pen.color("#00ffcc")
  49.     pen.width(3)
  50.    
  51.     # 画一条蜿蜒的蛇形路径
  52.     for x in range(-350, 350, 10):
  53.         y = 100 * (x / 350) ** 2  # 抛物线轨迹
  54.         pen.goto(x, y - 100)
  55.    
  56.     # 3. 在路径上写入加密的密文 (伪装成坐标或乱码)
  57.     pen.penup()
  58.     pen.goto(-300, 0)
  59.     pen.color("white")
  60.     pen.write("谜题:请破解这段乱码:", align="left", font=("Arial", 16, "bold"))
  61.    
  62.     pen.goto(-300, -50)
  63.     # 这里显示的是加密后的乱码,看起来像是一串无意义的字符
  64.     pen.write(f"密文: {ENCRYPTED_TEXT}", align="left", font=("Courier", 14, "normal"))
  65.    
  66.     pen.goto(-300, -100)
  67.     pen.write("提示:凯撒密码,钥匙是2位数。", align="left", font=("Arial", 12, "normal"))

  68.     # 4. 最后的交互环节
  69.     try:
  70.         guess = int(screen.numinput("解密挑战", "请输入偏移量(0-25)来解密:", minval=0, maxval=25))
  71.         
  72.         if guess == SHIFT_KEY:
  73.             pen.clear()
  74.             pen.goto(0, 0)
  75.             pen.color("#ff6b6b")
  76.             style = ('Arial', 24, 'bold')
  77.             pen.write(f"恭喜解密成功!\n\n{SECRET_MESSAGE}", align="center", font=style)
  78.             
  79.             # 庆祝动画
  80.             celebrate(screen)
  81.         else:
  82.             pen.goto(0, -150)
  83.             pen.color("red")
  84.             pen.write("尝试失败,再试一次!", align="center", font=("Arial", 16, "bold"))
  85.             
  86.     except:
  87.         pass

  88. def celebrate(screen):
  89.     """解密成功后的庆祝烟花"""
  90.     firework = turtle.Turtle()
  91.     firework.hideturtle()
  92.     firework.speed(0)
  93.     turtle.write('妇女节快乐', move=False, align='center', font=('Arial', 8, 'normal'))
  94.     for _ in range(20):
  95.         firework.penup()
  96.         firework.goto(random.randint(-300, 300), random.randint(-200, 200))
  97.         firework.pendown()
  98.         firework.color(random.random(), random.random(), random.random())
  99.         for _ in range(36):
  100.             firework.forward(30)
  101.             firework.backward(30)
  102.             firework.right(10)
  103.    
  104.     turtle.done()

  105. # --- 主程序 ---
  106. if __name__ == "__main__":
  107.     draw_puzzle()
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 昨天 21:43 | 显示全部楼层
妇女节礼物(代码)
python:
import turtle
import random

# --- 第一部分:隐藏的加密逻辑 (核心) ---
def encrypt_message(text, shift):
    """凯撒密码加密函数"""
    encrypted = ""
    for char in text:
        if char.isalpha():
            # 转换为小写并进行位移
            base = ord('a')
            encrypted += chr((ord(char.lower()) - base + shift) % 26 + base)
        else:
            encrypted += char
    return encrypted

# 真正的祝福语
SECRET_MESSAGE = "Happy Women's Day! You are amazing!"
# 设定一个只有你知道的偏移量(这就是解密钥匙)
SHIFT_KEY = 7

# 加密后的乱码(会在画布上显示)
ENCRYPTED_TEXT = encrypt_message(SECRET_MESSAGE, SHIFT_KEY)

# --- 第二部分:Turtle 绘图 (视觉效果) ---
def draw_puzzle():
    screen = turtle.Screen()
    screen.setup(800, 600)
    screen.bgcolor("#1a1a2e")
    screen.title("3.8 妇女节特别礼物:解密迷宫")

    pen = turtle.Turtle()
    pen.speed(0) # 最快速度
    pen.hideturtle()
    pen.width(2)

    # 1. 画一个复杂的几何背景 (象征生活中的挑战与美丽)
    for i in range(100):
        pen.penup()
        pen.goto(random.randint(-300, 300), random.randint(-200, 200))
        pen.pendown()
        
        # 随机颜色
        pen.color(random.random(), random.random(), random.random())
        
        # 画随机形状
        for _ in range(4):
            pen.forward(random.randint(50, 150))
            pen.right(90 + random.randint(-10, 10))

    # 2. 画出“迷宫路径” (象征寻找答案的过程)
    pen.penup()
    pen.goto(-350, -250)
    pen.pendown()
    pen.color("#00ffcc")
    pen.width(3)
   
    # 画一条蜿蜒的蛇形路径
    for x in range(-350, 350, 10):
        y = 100 * (x / 350) ** 2  # 抛物线轨迹
        pen.goto(x, y - 100)
   
    # 3. 在路径上写入加密的密文 (伪装成坐标或乱码)
    pen.penup()
    pen.goto(-300, 0)
    pen.color("white")
    pen.write("谜题:请破解这段乱码:", align="left", font=("Arial", 16, "bold"))
   
    pen.goto(-300, -50)
    # 这里显示的是加密后的乱码,看起来像是一串无意义的字符
    pen.write(f"密文: {ENCRYPTED_TEXT}", align="left", font=("Courier", 14, "normal"))
   
    pen.goto(-300, -100)
    pen.write("提示:凯撒密码,钥匙是2位数。", align="left", font=("Arial", 12, "normal"))

    # 4. 最后的交互环节
    try:
        guess = int(screen.numinput("解密挑战", "请输入偏移量(0-25)来解密:", minval=0, maxval=25))
        
        if guess == SHIFT_KEY:
            pen.clear()
            pen.goto(0, 0)
            pen.color("#ff6b6b")
            style = ('Arial', 24, 'bold')
            pen.write(f"恭喜解密成功!\n\n{SECRET_MESSAGE}", align="center", font=style)
            
            # 庆祝动画
            celebrate(screen)
        else:
            pen.goto(0, -150)
            pen.color("red")
            pen.write("尝试失败,再试一次!", align="center", font=("Arial", 16, "bold"))
            
    except:
        pass

def celebrate(screen):
    """解密成功后的庆祝烟花"""
    firework = turtle.Turtle()
    firework.hideturtle()
    firework.speed(0)
    turtle.write('妇女节快乐', move=False, align='center', font=('Arial', 8, 'normal'))
    for _ in range(20):
        firework.penup()
        firework.goto(random.randint(-300, 300), random.randint(-200, 200))
        firework.pendown()
        firework.color(random.random(), random.random(), random.random())
        for _ in range(36):
            firework.forward(30)
            firework.backward(30)
            firework.right(10)
   
    turtle.done()

# --- 主程序 ---
if __name__ == "__main__":
    draw_puzzle()


感谢分享这段有趣的妇女节礼物代码!这是一个使用 Python 的 turtle 图形库制作的解密游戏。下面我来简要解释一下代码的功能和运行方式:

代码功能:
1. 加密逻辑: 使用凯撒密码将一句祝福语 Happy Women's Day! You are amazing! 加密,偏移量(密钥)为 7。
2. 绘图部分: 使用 turtle 绘制一个带有复杂几何背景和迷宫路径的窗口,并显示加密后的密文。
3. 交互解密: 弹出一个输入框让用户猜测偏移量,如果输入正确(7),则会显示解密成功的祝福语并播放庆祝烟花;否则提示失败。

如何运行:
1. 确保你安装了 Python(通常自带 turtle 库)。
2. 将代码保存为一个 .py 文件(例如 women_day_gift.py)。
3. 运行该文件,会弹出一个图形窗口。
4. 按照提示,在输入框中输入偏移量(0-25 之间的整数)进行解密。

注意事项:
- 该程序需要图形界面支持,如果你在命令行环境运行,请确保有可用的图形显示(例如 Windows 的 GUI、macOS 或 Linux 的 X11)。
- 代码中的加密只针对字母字符,非字母字符(如空格和标点)保持不变。
- 庆祝烟花部分会持续一段时间,你可以关闭窗口来结束程序。

这是一个很有创意的礼物,结合了编程、密码学和图形绘制,让接收者通过互动来获取祝福!如果你在运行过程中遇到任何问题,欢迎继续提问。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 5 小时前 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 5 小时前 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 3 小时前 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2 小时前 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-3-9 13:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表