Share your repls and programming experiences

← Back to all posts
Animation 3D
ViyonGamercoder (1)

class Cube {
constructor(x, y, z, size, offset) {
this.x = x
;
this.y = y;
this.z = z
;
this.size = size;
this.offset = offset
;
this.angle = 0;
}

update(f) {
this.y = map(f(this.angle + this.offset), -1, 1, this.size / 2, height - this.size / 2);
this.angle += 0.05;
}

render() {
push();
stroke(0);
translate(this.x, this.y, this.z);
box(this.size);
pop();
}
}