I’m running the following pattern. The intention is to have several discrete objects move through the rendering volume and for a pixel to light up based on its x,y,z proximity to the objects. If a pixel is too far away it will be off, and if it is close enough to multiple objects it will use the closest one. The objects are currently moving on simple circular paths, but that can change. I update the object positions during the before render step and then compute the hue and brightness of every pixel during the render3d step. The code works fine. It doesn’t explicitly use much memory since I’m only keeping track of a small number of things.
However it can be quite slow for understandable reasons. I use a large number of pixels (currently 1440, eventually I hope to go to 2400). I use a fair number of objects, right now 6. The system has to compute the distance from each pixel (n) to each object (m) every cycle, leading to ~n*m computations. It goes faster with less pixels and less objects. With 1 object and 1440 pixels it runs at about 9 fps, with 6 it says 3.5, but probably actually less. Nothing really surprising here.
What concerns me is the following. When testing this the system itself becomes unstable in weird ways. The preview bar can take a very long time to load (20-60 seconds is not uncommon eventually). The pattern as seen on the LEDs can start relatively smooth (but slow) but become less so over time, eventually becoming very stuttery. Once the PB basically locked up and then when I went to go back to the code the pattern code itself had disappeared, though other patterns were fine. Often I have to reset the device or force reload the page. This becomes worse as I keep editing the pattern.
I’m sure my code is poorly optimized, obviously suggestions would be nice, but this is more of a bug report on how the system behaves under extreme loads.
var timespeed=0.5
var t1
var numballs=6
var ballsX=array(numballs)
var ballsY=array(numballs)
var ballsZ=array(numballs)
var ballsC=array(numballs)
function update_balls(t){
for(n=0;n<numballs;n++){
ballsX[n]=0.5*sin((t+n/numballs)*PI2)
ballsY[n]=0.5*cos((t+n/numballs)*PI2)
ballsZ[n]=1
ballsC[n]=t+n/numballs
}}
function render_balls(x,y,z){
mindist=10
color=0
for(n=0;n<numballs;n++){
X=ballsX[n]-x+0.5
Y=ballsY[n]-y+0.5
Z=ballsZ[n]-z
rad=sqrt(X*X+Y*Y+Z*Z)
if(rad<mindist){mindist=rad;color=ballsC[n]}
}
if(mindist<0.2){hsv(color+mindist,1-mindist,1-mindist*3)}
else(hsv(0,0,0))
}
export function beforeRender(delta) {
t1 = time(timespeed)
update_balls(t1)
}
export function render3D(index, x, y, z) {
render_balls(x,y,z)
}