P5.js not working in blogger

this worked for me

<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.js"></script>

<div id="p5canvas"></div>

<script>
  function setup() {
createCanvas(480, 120).parent("p5canvas");
}


function draw() {
if (mouseIsPressed) {
fill(0);
} else {
fill(155);
}
ellipse(mouseX, mouseY, 60, 60);
}
</script>

the problem is the editor on blogger is not the entire html page, but a portion of the page that renders the content. So you cannot add tags like <html> and <body>. The other issue is that if you don’t select parent() of the canvas, it will appear at the bottom of the page. You need to place <div> where you want to show your canvas, and attach the canvas to that div.

3 Likes