A running record of all interactions and code development for the "Learning Computer Science with Copilot" course.
I am teaching a 'Discover Week' class on 'Learning Computer Science with Copilot' to students who have not seen any CS before. I am using HTML/CSS/Bootstrap5 and p5js. The primary focus will be JavaScript. I'm thinking of an app where I introduce the course like movie credits from the 1978 movie Superman, and the students names appear large in the canvas and then shrink and fade into the background as if they are stars of the show. I'd like to be able to teach this in about 5 hours. Can you create a shell for the project to get started called movieCreditsSim0.html. Let's use a canvas that is 800 by 600 and use HSB color mode throughout. I need lots of documentation. I'll also want to keep a running log of our interactions in a 'chatLog' where I can see my requests and your responses with pertinent code fragments. Let's start that too as chatLog0.html
movieCreditsSim0.html - Main project filechatLog0.html - Chat log fileInitial implementation included:
In version 1, let's address a bug: upon loading the animation works perfectly. When I mouse click or key press to reinitialize, all the students appear at once as evidenced by the student numbers all stacked on top of each other. It needs to be a fresh restart. What is causing this and how can we fix it? Please clearly state the 'fix' with comments and teach me what to avoid in the future.
When the animation was reset via mouse click or key press, all student credits appeared simultaneously instead of being staggered like on the initial load.
The issue was in how we tracked time:
millis() directly to check if a credit should appearmillis() returns milliseconds since the program started - it NEVER resets!millis() would still be 10000+startTime: 0 (0 * 3000)startTime: 3000 (1 * 3000)startTime: 6000 (2 * 3000)millis()millis() > credit.startTime was TRUE for all credits immediately!Absolute Time: Time since program started (never resets) - like a stopwatch that keeps running
Relative Time: Time since a specific event - like resetting a lap timer
When to use which:
We needed to track when the current animation started, not when the program started.
// STEP 1: Add a new global variable to track animation start time
let animationStartTime = 0;
// STEP 2: Set it when the animation first starts (in setup)
function setup() {
// ... other setup code ...
animationStartTime = millis(); // Record current time
}
// STEP 3: Calculate RELATIVE time in updateCredit()
function updateCredit(credit) {
// Calculate time since THIS animation started
let timeSinceStart = millis() - animationStartTime;
// Now check against relative time
if (!credit.active && timeSinceStart > credit.startTime) {
credit.active = true;
}
// ... rest of function ...
}
// STEP 4: Reset the timer when user restarts
function mousePressed() {
credits = [];
initializeCredits();
animationStartTime = millis(); // Reset to NOW!
}
function keyPressed() {
credits = [];
initializeCredits();
animationStartTime = millis(); // Reset to NOW!
}
Example Timeline:
animationStartTime = 0animationStartTime = 15000millis() directly for reset-able timings
credits array AND animationStartTimeanimationStartTime clearly indicates it's tracking when animation beganstartTime or t which are ambiguousmovieCreditsSim0.html - Version 1 with bug fix applied
The bug was caused by using absolute time (millis()) when we needed
relative time (time since animation started). The fix adds an animationStartTime
variable that resets each time the animation restarts, allowing us to calculate proper relative timing.
Result: Now when you click or press a key, the animation truly restarts with proper 3-second staggered intervals between each student credit! 🎬✨