gsap实现通过json配置时间轴元素画布设置制作webm动画视频并下载代码

代码语言:html

所属分类:多媒体

代码描述:gsap实现通过json配置时间轴元素画布设置制作webm动画视频并下载代码,浏览器中就能通过son配置动画效果,支持语音解说,最终合成视频下载。

代码标签: 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="//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>
        // Initial Configuration Data (can be loaded from textarea)
        const gsapAnimationConfigExample = {
            canvas: {
                width: 800,
                height: 450,
                backgroundColor: '#0a0a1a'
            },
            svgIcons: {
                rocket: `<svg viewBox="0 0 512 512" width="100" height="100"><path fill="#F44336" d="M256,46c-25.4,0-46,20.6-46,46s20.6,46,46,46s46-20.6,46-46S281.4,46,256,46z"/><path fill="#FFC107" d="M256,420c-10,0-20-2-30-6c-10-4-20-10-30-18c-10-8-20-18-30-30s-20-26-30-42c-10-16-20-34-30-54 c-10-20-20-42-30-66c0-2,0-4,2-6c2-2,4-2,6-2c24,10,46,20,66,30c20,10,38,20,54,30c16,10,30,20,42,30s22,20,30,30 c8,10,14,20,18,30c4,10,6,20,6,30c0,10-2,20-6,30c-4,10-10,20-18,30c-8,10-18,20-30,30s-26,20-42,30c-16,10-34,20-54,30 c-20,10-42,20-66,30c-2,0-4,0-6-2c-2-2-2-4-2-6c10-24,20-46,30-66c10-20,20-38,30-54c10-16,20-30,30-42s20-22,30-30 c10-8,20-14,30-18c10-4,20-6,30-6V420z"/><path fill="#F44336" d="M326,186c-10-10-20-20-30-30c-10-10-20-20-30-30c-10-10-20-20-30-30c-10-10-20-20-30-30 c-2-2-2-4,0-6c2-2,4-2,6,0c10,10,20,20,30,30c10,10,20,20,30,30c10,10,20,20,30,30c10,10,20,20,30,30c2,2,2,4,0,6 C330,188,328,188,326,186z"/></svg>`,
                planet: `<svg viewBox="0 0 512 512" width="100" height="100"><circle cx="256" cy="256" r="120" fill="#4CAF50"/><circle cx="206" cy="206" r="30" fill="#8BC34A"/><circle cx="306" cy="256" r="40" fill="#8BC34A"/><circle cx="226" cy="306" r="25" fill="#8BC34A"/><circle cx="256" cy="256" r="140" fill="none" stroke="#BBDEFB" stroke-width="5" stroke-dasharray="10,15"/><circle cx="256" cy="256" r="180" fill="none" stroke="#BBDEFB" stroke-width="5" stroke-dasharray="10,15"/><circle cx="256" cy="256" r="220" fill="none" stroke="#BBDEFB" stroke-width="5" stroke-dasharray="10,15"/></svg>`,
                star: `<svg viewBox="0 0 512 512".........完整代码请登录后点击上方下载按钮下载查看

网友评论0