Multi-file sketches

Posted on by Ari Bader-Natal

Follow on Twitter

Last week, I posted that you can now use external Javascript libraries when creating sketches in the public studios (studio.sketchpad.cc and p5js.sketchpad.cc.) I extended this functionality to support another popular request: you can now create multi-file sketches by load code from one Sketchpad sketch into another Sketchpad sketch. This means, among other things, that you can better organize your code into files that can be edited independently, you can reuse classes across multiple sketches, and you can even make use of classes built by others people on Sketchpad.

How do I create a multi-file sketch?

To load code from one sketch into another sketch, simply open up the new HTML menu in the editor above the code, click the Load a Sketchpad sketch link, paste in the URL of the other sketch, click Load and then Save.

This screencast demonstrates this using an example sketch from Daniel Shiffman's "The Nature of Code" book. You can view this Stay Within Walls sketch on Sketchpad or run it right here.