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

199
Visualizações
Crear una clase a partir de un pequeño programa de 10 letras

Quería tomar este pequeño programa 10print (crédito para codingtrain ) y convertirlo en una clase, pero me encontré con este extraño problema: la versión OOP no funciona, mientras que la no OOP se está agotando.

Es el mismo código, ¿por qué no funciona? ¿Esto es un verdadero misterio para mí? Todas las variables están encapsuladas en la clase y referenciadas con "esto". palabra clave entonces, ¿por qué está actuando de manera diferente?

 let xx = 0; let yy = 0; let spacing = 20; function setup() { createCanvas(400, 400); background(0); } function draw() { stroke(255); if (random(1) < 0.5) { fill(2, 24, 242) line(xx, yy, xx + spacing, yy + spacing); } else { line(xx, yy + spacing, xx + spacing, yy); } xx = xx + spacing; if (xx > width) { xx = 0; yy = yy + spacing; } }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.js"></script>

 let tenPrint; function setup() { createCanvas(500, 500); tenPrint = new Tenprint(); } function draw() { tenPrint.drawit(); } class Tenprint { constructor() { this.xx = 0; this.yy = 0; this.spacing = 20; } drawit() { stroke(55); if (random(1) < 0.5) { fill(2, 24, 242) line(this.xx, this.yy, this.xx + this.spacing, this.yy + this.spacing); } else { line(this.xx, this.yy + this.spacing, this.xx + this.spacing, this.yy); } this.xx = this.xx + this.spacing; if (this.xx > this.width) { this.xx = 0; this.yy = this.yy + this.spacing; } } }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.js"></script>

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