gsap实现一个json配置生成动画场景播放声音和画面引擎可导出webm视频代码

代码语言:html

所属分类:多媒体

代码描述:gsap实现一个json配置生成动画场景播放声音和画面引擎可导出webm视频代码

代码标签: gsap json 配置 生成 动画 场景 播放 声音 画面 引擎 代码 导出 webm 视频

下面为部分代码预览,完整代码请点击下载或在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>JSON动画生成系统</title>
<script type="text/javascript" src="https://repo.bfw.wiki/bfwrepo/js/gsap.3.12.2.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #0a0a1a;
            color: #ffffff;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .container {
            width: 100%;
            max-width: 1200px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        h1 {
            color: #64B5F6;
            margin-bottom: 10px;
        }

        .description {
            color: #B0BEC5;
            text-align: center;
            margin-bottom: 30px;
            max-width: 800px;
        }

        .canvas-container {
            position: relative;
            margin: 20px 0;
            box-shadow: 0 0 20px rgba(0, 150, 255, 0.3);
            border-radius: 4px;
            overflow: hidden;
            /* Will be sized by JS based on config */
        }

        canvas {
            display: block;
            background-color: #0a0a1a; /* Default, can be overridden by config */
        }

        .controls {
            display: flex;
            gap: 15px;
            margin: 20px 0;
            flex-wrap: wrap;
            justify-content: center;
        }

        button {
            padding: 12px 24px;
            background: linear-gradient(135deg, #2196F3, #673AB7);
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            min-width: 150px;
        }

        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 150, 255, 0.4);
        }

        button:disabled {
            background: #555;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        .config-editor {
            width: 100%;
            margin: 20px 0;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .editor-container {
            width: 100%;
            max-width: 800px; /* Limit editor width for better readability */
            display: flex;
            flex-direction: column;
        }

        .editor-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }

        .editor-title {
            font-size: 18px;
            color: #64B5F6;
        }

        textarea {
            width: 100%;
            height: 300px;
            background-color: #1a1a2a;
            color: #ffffff;
            border: 1px solid #333;
            border-radius: 4px;
            padding: 10px;
            font-family: monospace;
            resize: vertical;
            box-sizing: border-box;
        }

        .video-preview {
            margin-top: 30px;
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        video {
            max-width: 100%;
            border-radius: 4px;
            box-shadow: 0 0 20px rgba(0, 150, 255, 0.3);
        }

        .download-link {
            margin-top: 15px;
            padding: 12px 24px;
            background: linear-gradient(135deg, #4CAF50, #009688);
            color: white;
            text-decoration: none;
            border-radius: 4px;
            transition: all 0.3s ease;
        }

        .download-link:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
        }

        .status {
            margin-top: 10px;
            min-height: 1.2em; /* Prevent layout shift */
            color: #64B5F6;
        }

        .error {
            color: #FF5252;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>动画生成系统</h1>
        <p class="description">基于JSON配置的动画生成器 - 通过修改配置文件创建自定义动画,并导出为WebM视频</p>

        <div class="canvas-container">
            <canvas id="animationCanvas"></canvas>
        </div>

        <div class="controls">
            <button id="previewBtn">预览动画</button>
            <button id="recordBtn">录制视频</button>
            <button id="stopBtn" disabled>停止</button>
            <button id="resetBtn">重置</button>
        </div>

        <div class="config-editor">
            <div class="editor-container">
                <div class="editor-header">
                    <div class="editor-title">动画配置 (JSON)</div>
                    <button id="applyConfigBtn">应用配置</button>
                </div>
                <textarea id="configEditor"></textarea>
            </div>
        </div>

        <div class="video-preview" id="videoPreviewContainer" style="display: none;">
            <h2>视频预览</h2>
            <video id="recordedVideo" controls></video>
            <a id="downloadLink" class="download-link" download="animation.webm">下载视频</a>
        </div>

        <div id="status" class="status"></div>
    </div>

    <script>
    // Placeholder image URLs (replace with actual, accessible URLs for testing)
    // You can use services like placeholder.com or host your own images/SVGs.
    //const placeholderImageUrl = (width, height, text = "Image") => `//repo.bfw.wiki/random/${width}x.........完整代码请登录后点击上方下载按钮下载查看

网友评论0