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

197
Visualizações
Imagen giratoria entre 2 ángulos en Javascript usando p5.js

Quiero rotar mi imagen entre cos(20) y -cos(20) con una animación fluida.

El árbol se realiza recursivamente con la función branch() . No puedo entender cómo hacerlo con bucles. ¿Hay una función integrada o un algoritmo específico para hacerlo?

 let angles = 0; var strokeValue = 1; function setup() { const canvas = createCanvas(540, 400); frameRate(8); } function draw() { background(220); angle = PI/8; translate(250, height); // I think the rotate function should be here branch(90); } function branch(length) { strokeWeight(strokeValue); line(1, 1, 1, -length); translate(0, -length); if (length > 4) { //Right branches push(); rotate(angle); branch(length * 0.72); pop(); // left branches push(); rotate(-angle); branch(length * 0.72); pop(); push(); // middle rotate(-angle * 0.2); branch(length * 0.3); pop(); } }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>

Esta es la foto

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Intenté esto, aunque no estoy seguro de que sea lo que pediste, así que siéntete libre de comentar.

 let angles = 0; var strokeValue = 1; function setup() { const canvas = createCanvas(540, 400); frameRate(30); } function draw() { background(220); angle = PI/8; translate(250, height); // I think the rotate function should be here rotate(cos(map(frameCount / 10,0,100,-20,20))); branch(90); } function branch(length) { strokeWeight(strokeValue); line(1, 1, 1, -length); translate(0, -length); if (length > 4) { //Right branches push(); rotate(angle); branch(length * 0.72); pop(); // left branches push(); rotate(-angle); branch(length * 0.72); pop(); push(); // middle rotate(-angle * 0.2); branch(length * 0.3); pop(); } }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>

about 4 years ago · Juan Pablo Isaza Relatório
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