Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
How to embed code p5.js so that it is rendered inside the page block?

I have the code from the library p5.js, the rendering takes place in function setup(). How can I specify that this code is not rendered in the canvas that p5 creates, but in my div block.

<body>
<div class"box"></div>
</body>
let ball = {
  x: 100,
  y: 100,
  xspeed: 1,
  yspeed: 1
}

function setup() {
  createCanvas(1000, 400);
}

function draw() {
  background(0);
  display()
  move()
  bounce()
}

function display() {
  fill(random(255, 255), 0, 0);
  ellipse(ball.x, ball.y, 30, 30);
}

function move() {
  ball.x = ball.x + ball.xspeed
  ball.y = ball.y + ball.yspeed
}

function bounce() {
  if (ball.x > width || ball.x < 0) {
    ball.xspeed = ball.xspeed * -1
  }
  if (ball.y > height || ball.y < 0) {
    ball.yspeed = ball.yspeed * -1
  }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!