Skip to content

Perfect Loop

You'll animate a sketch so the last frame flows into the first with no visible seam, and export it as a short clip that can play forever.

About

A looping animation is the native form of generative art on the internet, and the loop only works if the end meets the start. The trick is to treat time as a fraction from 0 to 1 and drive everything with sin and cos of that fraction times two pi, so frame 120 lands exactly where frame 0 began. For noise you do the same thing by sampling a circle through noise space instead of walking in a straight line. Keep the loop to two or three seconds, keep the file small enough to post, and keep anything that flashes under three flashes a second, because fast strobing can trigger seizures in some viewers.

At a glance

Per requirement
15 XP
Completion bonus
75 XP
Requirements
5
Takes
One evening
Skill level
Beginner (done it a few times)
Cost
Free
Supplies
Nothing special
Where
At home
Other people
On your own

Requirements

  1. 1
    Move a shape in a circle driven by frameCount. Set a loop length of 120 frames, compute t = (frameCount % 120) / 120, and place the shape at cos(TWO_PI * t) and sin(TWO_PI * t) times a radius. Film the screen for ten seconds so we can see it never stutters at the seam. Video
  2. 2
    Make a shape breathe with a sine wave instead of a linear ramp. Scale a circle by 1 + 0.3 * sin(TWO_PI * t) and compare it with a version that uses t directly, which snaps back at the end of every loop. Post a short clip of both. Video
  3. 3
    Loop noise by walking a circle through noise space. Sample noise(cx + r * cos(TWO_PI * t), cy + r * sin(TWO_PI * t)) for each element, with a different cx and cy per element and r around 1. Drive twenty or more wobbling lines or blobs this way. Film the result. Video
  4. 4
    Export the loop as a GIF or MP4 under 10 MB. p5.js has saveGif('loop', 2), and Processing can saveFrame() every frame for ffmpeg to stitch. Check the first and last frame side by side; if they are identical you have an off-by-one, because the last frame should be one step before the first. Post the exported file. Video
  5. 5
    Post it where it loops in public and check the seam at full speed. Any social site that autoplays works, and so does a shared folder with a friend. Let it run five times through, because a seam you miss on the first pass often shows on the third. Post a screen recording of it looping where you put it, and say what you'd tune. Video