🎬 Stage 4: Flying Movie Title

Adding cinematic opening title sequence with zoom and straighten effects

movieCreditsSim4.html

👤 User Request #8

Objective: Create Stage 4 with flying movie title that zooms toward viewer before student credits appear

Requirements:

🤖 Implementation - Movie Title Configuration

First, I added configuration variables for the movie title animation:

const MOVIE_TITLE = "Learning CS with AI"; const TITLE_INITIAL_SIZE = 8; // Starting font size (very small) const TITLE_FINAL_SIZE = 200; // Ending font size (very large) const TITLE_GROWTH_RATE = 2.5; // How fast title grows each frame const TITLE_DURATION_MS = 3000; // How long title animation lasts (3 seconds)
📚 Teaching Point - Animation Constants:
  • TITLE_INITIAL_SIZE = 8: Very small starting size creates dramatic zoom effect
  • TITLE_FINAL_SIZE = 200: Large ending size fills screen before disappearing
  • TITLE_GROWTH_RATE = 2.5: Linear growth - same pixels added each frame
  • TITLE_DURATION_MS = 3000: 3 seconds matches typical movie title timing

These values create a cinematic "zoom from distance" effect!

🤖 Implementation - Title Object Structure

Created a global variable and initialization function for the movie title:

// Global variable to track movie title let movieTitle = null; /** * Initializes the movie title with starting properties */ function initializeMovieTitle() { movieTitle = { text: MOVIE_TITLE, size: TITLE_INITIAL_SIZE, opacity: 100, tiltAngle: random(-MAX_TILT, MAX_TILT), // Random tilt at start initialTiltAngle: null, // Will store starting tilt active: true // Controls visibility }; // Store the initial tilt for straightening calculation movieTitle.initialTiltAngle = movieTitle.tiltAngle; }
📚 Teaching Point - Object Properties:
  • initialTiltAngle: Saved at start so we can calculate progress toward 0°
  • active flag: Simple boolean to control when title is visible
  • random(-MAX_TILT, MAX_TILT): Reuses existing constant for consistency

Storing the initial value lets us create smooth transitions!

🤖 Implementation - Title Update Logic

The heart of the animation - growing and straightening the title:

/** * Updates the movie title's size and tilt angle */ function updateMovieTitle(title) { // Grow the title size linearly if (title.size < TITLE_FINAL_SIZE) { title.size += TITLE_GROWTH_RATE; } else { // When title reaches final size, deactivate it title.active = false; title.opacity = 0; } // Calculate progress from 0 to 1 let progress = title.size / TITLE_FINAL_SIZE; // Straighten the tilt proportionally to progress title.tiltAngle = title.initialTiltAngle * (1 - progress); }
📚 Teaching Point - Progress Variables:

What is progress?

  • progress = currentSize / maxSize (e.g., 50 / 200 = 0.25 = 25%)
  • Always ranges from 0 (start) to 1 (finish)
  • Normalizing to 0-1 makes calculations easier

How does straightening work?

  • Start: progress = 0, so (1 - 0) = 1, tilt = initialTilt × 1 = full tilt
  • Middle: progress = 0.5, so (1 - 0.5) = 0.5, tilt = initialTilt × 0.5 = half tilt
  • End: progress = 1, so (1 - 1) = 0, tilt = initialTilt × 0 = 0° (horizontal)

Why mix linear and non-linear?

  • Size grows linearly: +2.5 pixels per frame (predictable)
  • Tilt shrinks proportionally: depends on progress (smooth)
  • Combination creates more interesting, natural-feeling motion

This is the same math used in movie CGI and video games!

🤖 Implementation - Title Display Function

Rendering the title with transformations:

/** * Displays the movie title with current transformations */ function displayMovieTitle(title) { push(); // Save current drawing state // Move to center of canvas translate(width / 2, height / 2); // Apply rotation for tilt effect rotate(radians(title.tiltAngle)); // Set text properties textAlign(CENTER, CENTER); textSize(title.size); fill(255, 215, 0, title.opacity); // Gold color // Draw the title text(title.text, 0, 0); pop(); // Restore drawing state }
📚 Teaching Point - Transformation Order:

The order of transformations matters!

  1. translate(width/2, height/2): Move origin to center
  2. rotate(radians(tiltAngle)): Rotate around center point
  3. text(title.text, 0, 0): Draw at origin (which is now center)

If we rotated BEFORE translating, the title would spin around the top-left corner!

push() and pop() protect these transformations from affecting other drawing.

🤖 Implementation - Sequencing with Credits

Modified the draw() function and credit initialization to sequence the animations:

function draw() { // ... background and stars code ... // Check if movie title should be shown if (movieTitle && movieTitle.active) { updateMovieTitle(movieTitle); displayMovieTitle(movieTitle); } // Update and display credits (as before) for (let i = 0; i < credits.length; i++) { // ... existing credit code ... } } function initializeCredits() { for (let i = 0; i < studentNames.length; i++) { credits.push({ name: studentNames[i], x: width / 2, y: height / 2, opacity: 100, fontSize: INITIAL_FONT_SIZE, tiltAngle: random(-MAX_TILT, MAX_TILT), // Delay credits until AFTER title finishes startTime: TITLE_DURATION_MS + (i * CREDIT_DELAY_MS) }); } }
📚 Teaching Point - Animation Sequencing:

Timeline breakdown:

  • 0-3000ms: Movie title active (zooming and straightening)
  • 3000ms: Title becomes inactive (active = false)
  • 3000ms: First student credit starts appearing
  • 8000ms: Second student credit starts (3000 + 5000)
  • 13000ms: Third student credit starts (3000 + 5000 + 5000)

Why this matters:

  • Creates narrative flow (title → credits)
  • Prevents visual clutter (only one animation at a time initially)
  • Builds anticipation and drama
  • Easy to adjust timing with TITLE_DURATION_MS constant

This is exactly how movie production works - timing is everything!

🤖 Implementation - Reset Functions

Updated interactive functions to reset the title along with credits:

function mousePressed() { // Reset movie title initializeMovieTitle(); // Reset all credits to start over credits = []; initializeCredits(); // Reset the animation start time animationStartTime = millis(); console.log("🔄 Animation reset!"); } function keyPressed() { // Reset movie title initializeMovieTitle(); // Reset all credits credits = []; initializeCredits(); // Reset the animation start time animationStartTime = millis(); console.log("🔄 Animation restarted with key press!"); }
📚 Teaching Point - Complete Lifecycle Management:

When resetting an animation, you need to reinitialize ALL moving parts:

  1. initializeMovieTitle(): Resets title with new random tilt
  2. credits = []: Clears old credit objects
  3. initializeCredits(): Creates fresh credit objects
  4. animationStartTime = millis(): Resets the clock

Miss any step and the animation won't restart cleanly!

✅ Stage 4 Complete!

🎯 What Students Learned in Stage 4:

1. Progress Variables (Normalization):

  • Converting any range to 0-1 for calculations
  • Using progress to drive multiple coordinated changes
  • Math: progress = (current - min) / (max - min)

2. Complementary Transformations:

  • One property grows (size) while another shrinks (tilt)
  • Creates richer, more natural-feeling animations
  • Requires careful coordination and testing

3. Linear vs Non-Linear Motion:

  • Linear: size += constant (same change every frame)
  • Non-linear: angle = initial × (1 - progress) (proportional change)
  • Mixing both creates complexity from simple math

4. Animation Sequencing:

  • Using time offsets to create narrative flow
  • startTime = TITLE_DURATION_MS + offset
  • Building stories through timed reveals

5. Object Lifecycle States:

  • active flag controls visibility and updates
  • Transition from active to inactive when complete
  • Clean separation of concerns (title vs credits)

Experiment Suggestions:

  • Change MOVIE_TITLE to your own text
  • Try TITLE_GROWTH_RATE of 1 (slow) or 5 (fast)
  • Experiment with TITLE_FINAL_SIZE (try 100 or 300)
  • Modify TITLE_INITIAL_SIZE (try 1 for dramatic zoom, or 20 for subtle)
  • Advanced: Try tiltAngle = initialTiltAngle * (1 - progress)² for non-linear straightening
  • Advanced: Add title.opacity = 100 * (1 - progress) to fade as it grows

Real-World Applications:

  • Movie/TV opening sequences
  • Video game title screens
  • Website hero animations
  • Mobile app splash screens
  • Presentation slide transitions

🎬 Students now understand how professional animators create dramatic zooming title effects!

📊 Stage 4 Summary

Key Files:

New Constants Added:

New Functions Added:

Modified Functions:

Animation Flow:

  1. Title appears small and tilted at center
  2. Title grows linearly while tilt decreases proportionally
  3. When size reaches TITLE_FINAL_SIZE, title becomes inactive
  4. After 3 seconds, first student credit begins
  5. Credits continue at 5-second intervals as before

Progressive Learning Path:

Each stage builds on previous concepts while introducing new programming patterns!