Source: q07_fourpane_beta.py

ASCII source for IDLE / py -3.13. File: q07_fourpane_beta.py

# -*- coding: ascii -*-
"""Standalone beta: four-pane Q07 family sims with YES/NO.

Layout (2x2):
  Q07   | Q07A
  Q07B  | Q07C

Run: py -3.13 q07_fourpane_beta.py
IDLE: open this file, F5.
ESC quit. R reset answers. Space pause.
Does not touch WordPress, intro, or the map HTML.
"""
from __future__ import annotations

import math
import random
import sys

import pygame

W, H = 1200, 720
FPS = 60
BG = (8, 10, 14)
PANEL = (12, 16, 22)
GOLD = (252, 216, 88)
PALE = (214, 214, 196)
DIM = (140, 140, 120)
BLUE = (120, 180, 220)
GREEN = (80, 200, 140)
RED = (220, 84, 74)
TEAL = (30, 60, 70)
WHITE = (236, 236, 220)
ORANGE = (220, 140, 60)

# Authored stands (reference only; player may disagree)
STAND = {"Q07": "yes", "Q07A": "no", "Q07B": "no", "Q07C": "open"}


def clamp(x, lo, hi):
    return lo if x < lo else hi if x > hi else x


def lerp(a, b, t):
    return a + (b - a) * t


def draw_text(surf, font, text, pos, color, center=False):
    img = font.render(text, True, color)
    r = img.get_rect()
    if center:
        r.center = pos
    else:
        r.topleft = pos
    surf.blit(img, r)
    return r


def wrap_blit(surf, font, text, box, color, line_h=16):
    words = text.split()
    lines = []
    cur = ""
    max_w = box.w - 8
    for w in words:
        trial = (cur + " " + w).strip()
        if font.size(trial)[0] <= max_w:
            cur = trial
        else:
            if cur:
                lines.append(cur)
            cur = w
    if cur:
        lines.append(cur)
    y = box.y
    for line in lines[:4]:
        surf.blit(font.render(line, True, color), (box.x + 4, y))
        y += line_h


class Pane:
    def __init__(self, key, title, rect):
        self.key = key
        self.title = title
        self.rect = rect
        self.answer = None  # "yes" | "no" | None
        self.rng = random.Random(hash(key) & 0xFFFFFFFF)
        self.rays = self._make_rays()

    def _make_rays(self):
        rays = []
        for i in range(14):
            ang = -0.55 + i * (1.1 / 13.0)
            rays.append({"ang": ang, "phase": self.rng.uniform(0, math.tau)})
        return rays

    def yes_rect(self):
        x = self.rect.x + 10
        y = self.rect.bottom - 36
        return pygame.Rect(x, y, 70, 26)

    def no_rect(self):
        x = self.rect.x + 90
        y = self.rect.bottom - 36
        return pygame.Rect(x, y, 70, 26)


def pane_grid():
    margin = 8
    header = 36
    usable_h = H - header - margin
    pw = (W - margin * 3) // 2
    ph = (usable_h - margin) // 2
    specs = [
        ("Q07", "Do ordinary null convergence and a trapped surface end some future history?"),
        ("Q07A", "Does positive Lambda repeal Penrose 1965?"),
        ("Q07B", "Is the incomplete generator an exterior measurement outcome?"),
        ("Q07C", "Does a quantum null-energy violation repeal Penrose 1965?"),
    ]
    panes = []
    for i, (key, title) in enumerate(specs):
        col = i % 2
        row = i // 2
        x = margin + col * (pw + margin)
        y = header + row * (ph + margin)
        panes.append(Pane(key, title, pygame.Rect(x, y, pw, ph)))
    return panes


def draw_button(surf, font, label, rect, selected, mouse):
    hot = rect.collidepoint(mouse)
    if selected:
        fill, border = (40, 50, 30), GOLD
    elif hot:
        fill, border = (30, 40, 50), PALE
    else:
        fill, border = (22, 28, 34), DIM
    pygame.draw.rect(surf, fill, rect, border_radius=4)
    pygame.draw.rect(surf, border, rect, width=2, border_radius=4)
    draw_text(surf, font, label, rect.center, WHITE, center=True)


# --- shared focusing geometry inside a pane local surface ---

def draw_focus_bundle(local, t, cx, cy, rays, scale=1.0, tip_dead=True):
    """Null congruence focusing toward a tip. Returns tip (x,y) in local coords."""
    # trapped surface (ellipse that shrinks)
    focus_u = 0.5 + 0.5 * math.sin(t * 0.7)
    # monotonic focus envelope
    fu = clamp((0.35 * t) % 2.4 / 2.4, 0.0, 1.0)
    area = lerp(70, 14, fu) * scale
    pygame.draw.ellipse(
        local,
        TEAL,
        pygame.Rect(int(cx - area), int(cy - area * 0.55), int(area * 2), int(area * 1.1)),
        1,
    )
    # label tick for trapped surface
    if fu > 0.15:
        local.blit(
            pygame.font.SysFont("consolas", 12).render("trapped", True, DIM),
            (int(cx - 24), int(cy - area * 0.55 - 14)),
        )

    tip_x, tip_y = cx + 110 * scale, cy
    tip_alive_until = 0.78
    for i, ray in enumerate(rays):
        ang = ray["ang"] * (0.85 + 0.15 * math.sin(t + ray["phase"]))
        # ray from left toward tip, focusing
        x0 = cx - 120 * scale
        y0 = cy + math.sin(ang) * lerp(90, 18, fu) * scale
        # incomplete: stop before infinite extension
        stop = tip_alive_until if tip_dead else 1.05
        x1 = lerp(x0, tip_x, stop)
        y1 = lerp(y0, tip_y, stop)
        col = (int(180 + 40 * math.sin(t * 2 + i)), int(180), 100)
        pygame.draw.line(local, col, (int(x0), int(y0)), (int(x1), int(y1)), 1)
        # neighbor tick marks (congruence)
        mx, my = lerp(x0, x1, 0.45), lerp(y0, y1, 0.45)
        pygame.draw.circle(local, DIM, (int(mx), int(my)), 1)

    if tip_dead:
        # affine bound marker
        pygame.draw.circle(local, RED, (int(tip_x - 8 * scale), int(tip_y)), 5, 1)
        pygame.draw.line(
            local,
            RED,
            (int(tip_x - 18 * scale), int(tip_y - 10)),
            (int(tip_x + 2 * scale), int(tip_y + 10)),
            1,
        )
    else:
        pygame.draw.circle(local, GREEN, (int(tip_x), int(tip_y)), 4)

    return tip_x, tip_y


def sim_q07(local, pane, t):
    """Parent: NCC + trapped -> incomplete generator."""
    cx, cy = local.get_width() // 2 - 20, local.get_height() // 2 - 10
    draw_focus_bundle(local, t, cx, cy, pane.rays, scale=1.0, tip_dead=True)
    f = pygame.font.SysFont("consolas", 13)
    local.blit(f.render("focusing of congruence", True, GOLD), (12, local.get_height() - 58))
    local.blit(f.render("incomplete generator", True, RED), (12, local.get_height() - 42))
    # relative velocity hint: two drifting labels
    vx = int(20 + 10 * math.sin(t))
    local.blit(f.render("v rel", True, DIM), (vx, 8))


def sim_q07a(local, pane, t):
    """Lambda present on spacetime; null contraction drops it out."""
    cx, cy = local.get_width() // 2 - 20, local.get_height() // 2 - 10
    # background Lambda wash (scale push)
    wash = pygame.Surface(local.get_size(), pygame.SRCALPHA)
    a = int(40 + 30 * abs(math.sin(t * 0.8)))
    wash.fill((40, 50, 90, a))
    local.blit(wash, (0, 0))
    f = pygame.font.SysFont("consolas", 13)
    local.blit(f.render("Lambda wash", True, BLUE), (12, 8))
    draw_focus_bundle(local, t, cx, cy, pane.rays, scale=0.95, tip_dead=True)
    # show drop-out: Lambda badge struck on the ray contraction
    bx, by = cx - 40, cy - 70
    pygame.draw.rect(local, (30, 40, 70), pygame.Rect(bx, by, 86, 22), border_radius=3)
    local.blit(f.render("Lambda*g", True, BLUE), (bx + 6, by + 3))
    # strike through -> 0 on null k
    pygame.draw.line(local, RED, (bx - 2, by + 11), (bx + 88, by + 11), 2)
    local.blit(f.render("null k -> 0", True, GOLD), (bx + 96, by + 3))
    local.blit(f.render("hypothesis absent =/= repeal", True, PALE), (12, local.get_height() - 58))


def sim_q07b(local, pane, t):
    """Exterior record stops at horizon; tip not an outcome."""
    w, h = local.get_width(), local.get_height()
    cx, cy = w // 2 - 30, h // 2 - 10
    # horizon line
    hx = cx + 40
    pygame.draw.line(local, ORANGE, (hx, 20), (hx, h - 70), 2)
    f = pygame.font.SysFont("consolas", 12)
    local.blit(f.render("horizon", True, ORANGE), (hx - 22, 6))
    # outsider worldline + records (left)
    ox = 36
    pygame.draw.line(local, GREEN, (ox, 30), (ox, h - 80), 2)
    for i in range(5):
        yy = 50 + i * 28 + int(4 * math.sin(t + i))
        if yy < h - 90:
            pygame.draw.circle(local, GREEN, (ox, yy), 4)
            local.blit(f.render("rec", True, DIM), (ox + 8, yy - 5))
    local.blit(f.render("exterior", True, GREEN), (8, h - 58))
    # tip region right of horizon (incomplete, unlabeled by outsider)
    tip_x, tip_y = hx + 70, cy
    # faint forbidden rays past horizon from outside
    for i in range(6):
        y0 = cy - 40 + i * 14
        pygame.draw.line(local, (60, 60, 50), (hx - 30, y0), (hx, y0), 1)
    pygame.draw.circle(local, RED, (int(tip_x), int(tip_y)), 6, 1)
    # refuse badges
    pulse = 0.5 + 0.5 * math.sin(t * 3)
    for i, lab in enumerate(("eigenvalue?", "accelerometer?")):
        bx = hx + 20
        by = 40 + i * 28
        col = (int(120 + 80 * pulse), 60, 60)
        pygame.draw.rect(local, (30, 20, 20), pygame.Rect(bx, by, 120, 20), border_radius=3)
        local.blit(f.render(lab, True, col), (bx + 4, by + 3))
        pygame.draw.line(local, RED, (bx, by + 10), (bx + 120, by + 10), 1)
    local.blit(f.render("tip not exterior outcome", True, RED), (hx + 8, h - 58))


def sim_q07c(local, pane, t):
    """Classical focusing continues; QFT NEC flicker pressures hypothesis only."""
    cx, cy = local.get_width() // 2 - 20, local.get_height() // 2 - 10
    draw_focus_bundle(local, t, cx, cy, pane.rays, scale=0.95, tip_dead=True)
    f = pygame.font.SysFont("consolas", 12)
    # NEC flicker patch
    flicker = abs(math.sin(t * 2.2)) > 0.65
    patch = pygame.Rect(cx - 90, cy - 50, 70, 40)
    if flicker:
        pygame.draw.rect(local, (90, 40, 90), patch, border_radius=4)
        local.blit(f.render("NEC flicker", True, PALE), (patch.x + 4, patch.y + 12))
    else:
        pygame.draw.rect(local, (40, 40, 50), patch, 1, border_radius=4)
        local.blit(f.render("NCC holds", True, DIM), (patch.x + 8, patch.y + 12))
    # Quantum column has no tip record; that is not the player's YES/NO mark.
    tip_x, tip_y = cx + 100, cy
    pygame.draw.rect(local, (20, 20, 20), pygame.Rect(int(tip_x - 10), int(tip_y - 36), 128, 18), border_radius=3)
    local.blit(f.render("quantum tip record: absent", True, DIM), (int(tip_x - 8), int(tip_y - 34)))
    local.blit(f.render("leave hypothesis =/= tip pass", True, PALE), (12, local.get_height() - 58))


SIM = {
    "Q07": sim_q07,
    "Q07A": sim_q07a,
    "Q07B": sim_q07b,
    "Q07C": sim_q07c,
}


def feedback_color(key, answer):
    """Color only after the player marks. Ledger stand is never forced into the buttons."""
    stand = STAND[key]
    if answer is None:
        return DIM
    if stand == "open":
        return ORANGE  # either mark is pressure, not forced close
    if answer == stand:
        return GREEN
    return RED


def feedback_label(key, answer):
    """Do not reveal ledger stand until the player has marked YES or NO."""
    if answer is None:
        return "your mark: -"
    stand = STAND[key]
    if stand == "open":
        return "%s  |  ledger: open (pressure only)" % answer.upper()
    if answer == stand:
        return "%s  |  matches map ledger" % answer.upper()
    return "%s  |  differs from map ledger" % answer.upper()


def draw_pane(surf, fonts, pane, t, mouse):
    r = pane.rect
    pygame.draw.rect(surf, PANEL, r, border_radius=6)
    pygame.draw.rect(surf, DIM, r, width=1, border_radius=6)

    # header
    head = pygame.Rect(r.x, r.y, r.w, 44)
    pygame.draw.rect(surf, (18, 24, 30), head, border_radius=6)
    draw_text(surf, fonts["key"], pane.key, (r.x + 10, r.y + 6), GOLD)
    wrap_blit(
        surf,
        fonts["q"],
        pane.title,
        pygame.Rect(r.x + 4, r.y + 22, r.w - 8, 36),
        PALE,
        line_h=14,
    )

    # simulation area
    sim_rect = pygame.Rect(r.x + 6, r.y + 48, r.w - 12, r.h - 92)
    local = pygame.Surface((sim_rect.w, sim_rect.h))
    local.fill((10, 14, 18))
    SIM[pane.key](local, pane, t)
    surf.blit(local, sim_rect.topleft)
    pygame.draw.rect(surf, (40, 40, 50), sim_rect, 1)

    # YES / NO
    draw_button(surf, fonts["btn"], "YES", pane.yes_rect(), pane.answer == "yes", mouse)
    draw_button(surf, fonts["btn"], "NO", pane.no_rect(), pane.answer == "no", mouse)

    # feedback chip -- ledger text only after a player mark
    chip = feedback_color(pane.key, pane.answer)
    msg = feedback_label(pane.key, pane.answer)
    draw_text(surf, fonts["btn"], msg, (r.x + 180, r.bottom - 30), chip)


def run_sim(screen=None, embedded=False):
    """Run the four-pane Q07 family. ESC returns.

    embedded=True: reuse screen, do not pygame.quit() (return to map).
    """
    own_display = screen is None
    if own_display:
        pygame.init()
        screen = pygame.display.set_mode((W, H))
    pygame.display.set_caption("Q07 four-pane beta -- affine bound family")
    clock = pygame.time.Clock()
    fonts = {
        "key": pygame.font.SysFont("consolas", 16, bold=True),
        "q": pygame.font.SysFont("consolas", 13),
        "btn": pygame.font.SysFont("consolas", 14, bold=True),
        "ui": pygame.font.SysFont("consolas", 16),
    }
    panes = pane_grid()
    t = 0.0
    paused = False
    running = True
    quit_app = False

    while running:
        dt = clock.tick(FPS) / 1000.0
        mouse = pygame.mouse.get_pos()
        for ev in pygame.event.get():
            if ev.type == pygame.QUIT:
                running = False
                quit_app = True
            elif ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_ESCAPE:
                    running = False
                elif ev.key == pygame.K_SPACE:
                    paused = not paused
                elif ev.key == pygame.K_r:
                    for p in panes:
                        p.answer = None
                    t = 0.0
            elif ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
                for p in panes:
                    if p.yes_rect().collidepoint(ev.pos):
                        p.answer = "yes"
                    elif p.no_rect().collidepoint(ev.pos):
                        p.answer = "no"

        if not paused:
            t += dt

        screen.fill(BG)
        hint = "ESC back to map" if embedded else "ESC quit"
        draw_text(
            screen,
            fonts["ui"],
            "Q07 family -- four sims  |  YES/NO  |  Space pause  R reset  |  " + hint,
            (12, 8),
            DIM,
        )
        for p in panes:
            draw_pane(screen, fonts, p, t, mouse)

        done = sum(1 for p in panes if p.answer)
        draw_text(screen, fonts["ui"], "answered %d / 4" % done, (W - 160, 8), PALE)

        pygame.display.flip()

    if own_display and not embedded:
        pygame.quit()
    return 0 if not quit_app else 1


def main():
    return run_sim(screen=None, embedded=False)


if __name__ == "__main__":
    sys.exit(main())