svg实现剧本转2d有声卡通动画片代码

代码语言:html

所属分类:其他

代码由gemini-4 ai生成,可能有错误,仅供参考:点击查看提示词

代码描述:剧本转2d有声卡通网页动画片

代码标签: svg 剧本 转 2d 有声 卡通 动画片 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>纸片剧场 — 剧本转 SVG 动画播放器</title>
<!--
====================================================================
《纸片剧场》单文件剧本转 SVG 动画播放器
====================================================================
【玩法说明】
1. 在左侧文本框粘贴或编写剧本(支持分镜指令与角色台词),点击「🎬 生成动画」。
2. 系统自动解析分镜、匹配场景与纸片人角色,并在 16:9 舞台上用纯 SVG 渲染播放。
3. 播放时支持拖动进度条、倍速调节、镜头运动、环境动效及浏览器语音配音。

【剧本格式速览】
片名:最后一只萤火虫
总时长:60秒

[镜头1] 0:00-0:12 | 场景=夏夜·老屋院子 | 镜头=缓慢推近 | 转场=淡入淡出
旁白:那年夏天,院子里的萤火虫,像撒了一地的星星。
小萤(8岁):奶奶,它们会飞走吗?

【TTS 配音说明】

    使用浏览器原生 window.speechSynthesis,需在用户点击「生成动画」或「播放」后激活。

    自动优先匹配中文语音(zh),并按角色特征(旁白/小孩/老人/动物/成人)分配音色与语速。

    「语音优先模式」开启时,画面会等待当前台词语音播完再进入下一句;关闭时严格按剧本时间轴推进。

【CONFIG 调参说明】

    所有核心参数集中在 <script> 顶部的 CONFIG 对象中,包含默认镜头时长、转场时长、
    台词最小间隔、字幕字号、TTS 默认音量与语速、镜头抖动强度、环境粒子密度及示例剧本。
    ====================================================================
    -->

<style>
:root {
--bg-app: #14171f;
--bg-panel: #1d222d;
--bg-panel-alt: #252b38;
--border-subtle: rgba(255, 255, 255, 0.09);
--text-main: #eef2f7;
--text-muted: #9aa5b8;
--accent: #f0a85b;
--accent-hover: #f5b978;
--accent-soft: rgba(240, 168, 91, 0.16);
--danger: #e57373;
--warning: #f6c453;
--success: #79c79b;
--radius: 10px;
}

* {
box-sizing: border-box;
user-select: none;
}

html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--bg-app);
color: var(--text-main);
font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
font-size: 14px;
line-height: 1.5;
}

.hidden {
display: none !important;
}

button {
font-family: inherit;
cursor: pointer;
border: none;
outline: none;
transition: background-color 0.2s ease, transform 0.12s ease, opacity 0.2s ease, border-color 0.2s ease;
}

button:active {
transform: scale(0.97);
}

/* ==================== 编辑界面 ==================== */
#editor-view {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
padding: 16px 24px 18px;
gap: 14px;
background: radial-gradient(circle at 18% 12%, #212838 0%, #14171f 62%);
}

.editor-header {
display: flex;
align-items: center;
justify-content: space-between;
flex-shrink: 0;
}

.brand {
display: flex;
align-items: center;
gap: 12px;
}

.brand-badge {
width: 38px;
height: 38px;
border-radius: 10px;
background: linear-gradient(135deg, #f0a85b, #d87a56);
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
box-shadow: 0 4px 14px rgba(240, 168, 91, 0.28);
}

.brand-title {
font-size: 20px;
font-weight: 700;
letter-spacing: 0.5px;
margin: 0;
}

.brand-sub {
font-size: 12px;
color: var(--text-muted);
margin: 0;
}

.editor-main {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: 1.35fr 1fr;
gap: 18px;
}

.editor-left,
.editor-right {
background: var(--bg-panel);
border: 1px solid var(--border-subtle);
border-radius: var(--radius);
display: flex;
flex-direction: column;
min-height: 0;
overflow: hidden;
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

.pane-header {
padding: 10px 16px;
background: rgba(255, 255, 255, 0.03);
border-bottom: 1px solid var(--border-subtle);
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 600;
font-size: 13px;
color: var(--text-main);
flex-shrink: 0;
}

.pane-header-hint {
font-weight: 400;
font-size: 12px;
color: var(--text-muted);
}

#script-input {
flex: 1;
min-height: 0;
width: 100%;
padding: 14px 16px;
background: #171b24;
color: #e9eef5;
border: none;
outline: none;
resize: none;
font-family: "Cascadia Mono", "Fira Code", "Consolas", "Courier New", monospace;
font-size: 13.5px;
line-height: 1.65;
overflow-y: auto;
user-select: text;
}

#script-input::-webkit-scrollbar,
.right-scroll::-webkit-scrollbar {
width: 8px;
}

#script-input::-webkit-scrollbar-thumb,
.right-scroll::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.16);
border-radius: 4px;
}

.left-actions {
padding: 10px 16px;
background: rgba(255, 255, 255, 0.02);
border-top: 1px solid var(--border-subtle);
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
flex-shrink: 0;
}

.btn-group {
display: flex;
gap: 8px;
}

.btn-secondary {
padding: 7px 14px;
border-radius: 7px;
background: var(--bg-panel-alt);
color: var(--text-main);
border: 1px solid var(--border-subtle);
font-size: 12.5px;
}

.btn-secondary:hover {
background: #2f3646;
border-color: rgba(255, 255, 255, 0.2);
}

.right-scroll {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 14px 16px;
display: flex;
flex-direction: column;
gap: 12px;
}

.status-card {
background: var(--bg-panel-alt);
border: 1px solid var(--border-subtle);
border-radius: 8px;
padding: 11px 13px;
}

.status-title {
font-size: 12.5px;
font-weight: 600;
margin-bottom: 6px;
display: flex;
align-items: center;
justify-content: space-between;
}

.badge {
font-size: 11px;
padding: 2px 8px;
border-radius: 999px;
font-weight: 500;
}

.badge-ok {
background: rgba(121, 199, 155, 0.16);
color: var(--success);
}

.badge-warn {
background: rgba(246, 196, 83, 0.16);
color: var(--warning);
}

.badge-err {
background: rgba(229, 115, 115, 0.16);
color: var(--danger);
}

.parse-summary {
font-size: 12.5px;
color: var(--text-muted);
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px 12px;
}

.parse-summary span strong {
color: var(--text-main);
}

.parse-messages {
margin-top: 8px;
font-size: 12px;
display: flex;
flex-direction: column;
gap: 4px;
}

.msg-warn {
color: var(--warning);
}

.msg-err {
color: var(--danger);
}

.guide-block {
background: rgba(255, 255, 255, 0.025);
border: 1px solid var(--border-subtle);
border-radius: 8px;
padding: 11px 13px;
font-size: 12.5px;
color: var(--text-muted);
}

.guide-block h4 {
margin: 0 0 6px;
font-size: 13px;
color: var(--text-main);
}

.guide-block ul {
margin: 0;
padding-left: 18px;
display: flex;
flex-direction: column;
gap: 4px;
}

.guide-code {
display: inline-block;
background: rgba(0, 0, 0, 0.28);
color: #f3c892;
padding: 1px 5px;
border-radius: 4px;
font-family: monospace;
font-size: 11.5px;
}

.shot-preview-list {
display: flex;
flex-direction: column;
gap: 6px;
}

.shot-preview-item {
background: rgba(0, 0, 0, 0.2);
border-radius: 6px;
padding: 6px 9px;
font-size: 12px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
}

.shot-preview-item .meta {
color: var(--text-muted);
font-size: 11.5px;
white-space: nowrap;
}

.editor-footer {
flex-shrink: 0;
display: flex;
justify-content: center;
padding-top: 2px;
}

#btn-generate {
width: 320px;
height: 46px;
border-radius: 12px;
background: linear-gradient(135deg, #f0a85b, #df8352);
color: #191410;
font-size: 16px;
font-weight: 700;
letter-spacing: 0.6px;
box-shadow: 0 8px 22px rgba(240, 168, 91, 0.32);
}

#btn-generate:hover {
background: linear-gradient(135deg, #f5b670, #e89162);
transform: translateY(-1px);
}

/* ==================== 播放界面 ==================== */
#player-view {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
background: #0d1016;
}

.player-topbar {
height: 48px;
padding: 0 20px;
background: rgba(20, 24, 33, 0.94);
border-bottom: 1px solid var(--border-subtle);
display: flex;
align-items: center;
justify-content: space-between;
flex-shrink: 0;
gap: 12px;
}

.topbar-left {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}

.movie-title {
font-size: 15px;
font-weight: 700;
color: var(--text-main);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.shot-indicator {
font-size: 12.5px;
color: var(--accent);
background: var(--accent-soft);
padding: 3px 10px;
border-radius: 999px;
white-space: nowrap;
}

.topbar-notices {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: nowrap;
overflow: hidden;
}

.notice-pill {
font-size: 12px;
padding: 3px 10px;
border-radius: 999px;
background: rgba(246, 196, 83, 0.16);
color: var(--warning);
white-space: nowrap;
}

#btn-back-edit {
padding: 6px 14px;
border-radius: 8px;
background: var(--bg-panel-alt);
color: var(--text-main);
border: 1px solid var(--border-subtle);
font-size: 12.5px;
white-space: nowrap;
}

#btn-back-edit:hover {
background: #303748;
}

.stage-viewport {
flex: 1;
min-height: 0;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
padding: 14px 20px;
background: radial-gradient(circle at center, #181c26 0%, #0a0c10 85%);
}

.stage-frame {
position: relative;
background: #0e1118;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

#stage-svg {
width: 100%;
height: 100%;
display: block;
transition: opacity 0.06s linear;
}

#transition-overlay {
position: absolute;
inset: 0;
background: #000000;
opacity: 0;
pointer-events: none;
}

#subtitle-overlay {
position: absolute;
left: 6%;
right: 6%;
bottom: 5.5%;
display: flex;
justify-content: center;
pointer-events: none;
transition: opacity 0.22s ease, transform 0.22s ease;
opacity: 0;
transform: translateY(6px);
}

#subtitle-overlay.visible {
opacity: 1;
transform: translateY(0).........完整代码请登录后点击上方下载按钮下载查看

网友评论0