p5-recorder is a deadly simple class that be able to create gif from canvas
for p5.js. Depends on CCapture.all.js and gif.worker.js
var recorder;
function setup(){
recorder = new P5Recorder({gifLength: 100});
createCanvas(windowWidth, windowHeight);
}
function draw(){
//draw something on canvas...
recorder.capture(frameCount);
}
Don't forget to include the dependencies.
<script src="js/p5.js"></script>
<script src="js/CCapture.all.min.js"></script>
<script src="js/gif.worker.js"></script>
<script src="js/recorder.js"></script>
<script src="js/sketch.js"></script>