Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

254
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda