Skip to content

🎥 Make videos programmatically with React

fast updates test composition

Jonny Burger133b75baffb3
diff --git a/packages/example/fast-updates.ts b/packages/example/fast-updates.ts
new file mode 100644
index 0000000000..8025da4ef0
--- /dev/null
+++ b/packages/example/fast-updates.ts
@@ -0,0 +1,61 @@
+import {writeFileSync} from 'fs';
+import {join} from 'path';
+
+const filePath = join(__dirname, 'src/VisualModeTests/FastUpdates.tsx');
+
+const makeContent = (seed: number, duplicateLightLeak: boolean) => {
+ const lightLeaks = duplicateLightLeak
+ ? `<LightLeak durationInFrames={60} seed={${seed}} hueShift={0} />
+ <LightLeak durationInFrames={60} seed={${seed}} hueShift={0} />`
+ : `<LightLeak durationInFrames={60} seed={${seed}} hueShift={0} />`;
+
+ return `// This file can be changed through the script: packages/example/fast-updates.ts
+import {LightLeak} from '@remotion/light-leaks';
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+export const FastUpdates: React.FC = () => {
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ ${lightLeaks}
+ </AbsoluteFill>
+ );
+};
+`;
+};
+
+const makeContentWithoutLightLeak = () => {
+ return `// This file can be changed through the script: packages/example/fast-updates.ts
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+export const FastUpdates: React.FC = () => {
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black'}} />
+ );
+};
+`;
+};
+
+let iteration = 0;
+
+const update = () => {
+ const step = iteration % 5;
+
+ if (step < 3) {
+ const seed = Math.floor(Math.random() * 1000);
+ console.log(`Step ${step + 1}/5: Changing seed to ${seed}`);
+ writeFileSync(filePath, makeContent(seed, false));
+ } else if (step === 3) {
+ console.log('Step 4/5: Duplicating <LightLeak>');
+ writeFileSync(filePath, makeContent(Math.floor(Math.random() * 1000), true));
+ } else {
+ console.log('Step 5/5: Removing <LightLeak>');
+ writeFileSync(filePath, makeContentWithoutLightLeak());
+ }
+
+ iteration++;
+};
+
+update();
+setInterval(update, 1000);
diff --git a/packages/example/src/VisualModeTests/FastUpdates.tsx b/packages/example/src/VisualModeTests/FastUpdates.tsx
index 5d298981d4..490ddaedc4 100644
--- a/packages/example/src/VisualModeTests/FastUpdates.tsx
+++ b/packages/example/src/VisualModeTests/FastUpdates.tsx
@@ -1,3 +1,4 @@
+// This file can be changed through the script: packages/example/fast-updates.ts
import {LightLeak} from '@remotion/light-leaks';
import React from 'react';
import {AbsoluteFill} from 'remotion';
@@ -5,7 +6,7 @@ import {AbsoluteFill} from 'remotion';
export const FastUpdates: React.FC = () => {
return (
<AbsoluteFill style={{backgroundColor: 'black'}}>
- <LightLeak durationInFrames={60} seed={1} hueShift={0} />
+ <LightLeak durationInFrames={60} seed={855} hueShift={0} />
</AbsoluteFill>
);
};