How to leave trail in my sketch without deleting the background in p5js?

I would like to leave line trails at each of the corners of the rectangles. I have tried createGraphics to add an extra canvas where I want to leave the trails but it’s just doesn’t work.

I purposefully rotate the rectangle with cosine. My assignment forbids to use the rotate function.

I followed this tutorial: https://www.youtube.com/watch?v=TaluaAD9MKA

The Sketch:

Without createGraphics: https://editor.p5js.org/plaszlo/sketches/W6Bq6zAI3

With createGraphics: https://editor.p5js.org/plaszlo/sketches/WQhPN5e7F

Thank you