xxxxxxxxxx
let objects = [] // create empty array
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
let spacing = 50
for (var x = -255; x < 255; x += spacing) {
for (var y = -255; y < 255; y += spacing) {
for (var z = -255; z < 255; z += spacing) {
let voxel = getVoxel(x,y,z,spacing/2)
objects.push(voxel)
}
}
}
}
function draw() {
background(0)
push()
scale(0.5)
rotateX(mouseX/1000)
rotateY(mouseY/1000)
rotateZ(frameCount/500)
objects.forEach(obj=>obj.display())
pop()
}
function getVoxel(x,y,z,size){
let obj = {}
obj.x = x
obj.y = y
obj.z = z
obj.size = size
obj.display = function(){
push()
fill(this.x,this.y,this.z)
translate(this.x,this.y,this.z)
box(this.size)
pop()
}
return obj
}