Estoy usando p5js para convertir un código de helecho barnsley en un objeto usando el código del tren de codificación.
Estoy tratando de animarlo cambiando uno de los coeficientes, pero primero necesito que el helecho se represente correctamente como un objeto.
Mi problema es que el helecho no se representa correctamente después de que transfiero las propiedades y los métodos a un objeto de helecho barnsley. Lo único que rinde a veces es el tallo pero ninguna de las hojas lo hace.
Intenté cambiar el orden en la función de dibujo, usando un enfoque de fábrica de funciones y literales de objetos, pero sigo obteniendo el mismo resultado 😭
Aquí está el p5sketch para que puedas ver
let x = 0; let y = 0; let barnFernInst; function setup() { createCanvas(500, 500); background(0); barnFernInst = new BarnsleyFernObject(); } function draw() { for (let i = 0; i < 100; i++) { barnFernInst.drawPoint(); barnFernInst.nextPoint(); } } class BarnsleyFernObject { constructor() { this.x = 0; this.y = 0; this.px = 0; this.py = 0; this.nextX = 0; this.nextY = 0; this.r = random(1); this.newB2Var = 0.04; } drawPoint() { stroke(255); strokeWeight(0.5); this.px = map(this.x, -2.182, 2.6558, 50, width /2); this.py = map(this.y, 0, 9.9983, height /1.5, 50); point(this.px, this.py); } nextPoint() { if (this.r < 0.01) { this.nextY = 0.16 * this.y; this.nextX = 0; } else if (this.r < 0.86) { this.nextX = 0.85 * this.x + this.newB2Var * this.y; this.nextY = -0.04 * this.x + 0.85 * this.y + 1.6; } else if (this.r < 0.93) { this.nextX = 0.2 * this.x + -0.26 * this.y; this.nextY = 0.23 * this.x + 0.22 * this.y + 1.6; } else { this.nextX = -0.15 * this.x + 0.28 * this.y; this.nextY = 0.26 * this.x + 0.24 * this.y + 0.44; } this.x = this.nextX; this.y = this.nextY; } }Te perdiste la actualización de r en la función nextPoint()
this.r = random(1);https://editor.p5js.org/ghaithalzein05/sketches/_pSAifyr0
¡Déjame saber si necesitas algo más!