Hi there,
The overarching goal I have is to teach p5.js during a women’s hackathon at my university using Observable. I feel like it’s a great way for attendees to have a portfolio like set of their work to share and collaborate with.
There’s many examples of the instanced sketch
methods for p5 on observable, https://observablehq.com/@tmcw/p5 … which require putting code inside a p5 function call, and prepending sketch.
in front of all predefined p5 functions. See the following as an example
p5(sketch => {
let system;
const c = sketch.color('#DC3F74');
sketch.setup = function() {
sketch.createCanvas(640, 300);
sketch.textAlign(sketch.CENTER);
sketch.textFont('sans-serif');
sketch.textStyle(sketch.BOLD);
};
sketch.draw = function() {
sketch.translate(sketch.millis() / 10 % sketch.width, sketch.height / 2);
sketch.background(viewof background.valueAsNumber);
sketch.fill(c).textSize(100);
sketch.text('p5.js', 0, 0);
};
})
but for students that haven’t done much/any coding I want what they write to be as similar to the p5 reference/documentation/quickstarts as possible.
Therefore, I have experimented with https://observablehq.com/@devinbayly/processing-p5-js-iframe-technique, where standard p5.js can be typed into the textarea, and it will get run in an iframe above. The problem here is that the work is not retained.
My question is therefore, can anyone suggest a way that contents provided to the textarea can be retained? Or… is there a totally separate approach which still allows for users to supply p5 code as it is written in the reference to create visuals?
I’m aware this is a bit of a niche case, so if its just a little too much to pull off then the next best thing is to fall back to the instanced sketch
methods linked above. Thanks so much!