Ok I looked into the cube animator files, it stores the leds as bits, where 4 bytes are used for each plane, leaving 7 bits free. Some of those are used to set the intensity of the frame, some other bits are also set, but I don’t know why. They are not needed.
I created this simple C(++) program to test it out, it works great This code generates a bouncing ball animation of 1000 frames. Looks great on the higest speed.
You can run the code in visual c++ and it will generate the file in c:\
I also uploaded the animation file that you can load into CubeAnimator.
bouncingball.cb5
#include "stdafx.h"
#include <math.h>
//general stuff
bool leds[125];
FILE *fp;
//ball stuff
float ballx, bally, ballz;
float dirx, diry, dirz;
float ballwidth=3.5;
void clear()
{
for (int i=0; i<125; i++)
leds[i]=false;
}
void set(int x, int y, int z, bool value)
{
leds[z*25 + y*5 + x]=value;
}
bool get(int x, int y, int z)
{
return leds[z*25 + y*5 + x];
}
void writePlane(int plane)
{
char bits=0;
char bitcount=7;
for (int y=0; y<5; y++)
{
for (int x=0; x<5; x++)
{
if (get(x,y,plane))
bits |= 1 << bitcount;
else
bits &= ~(1 << bitcount);
bitcount--;
if (bitcount==-1)
{
fwrite(&bits, sizeof(unsigned char), 1, fp);
bitcount=7;
bits=0;
}
}
}
fwrite(&bits, sizeof(unsigned char), 1, fp);
}
void writeFrame()
{
for (int z=0; z<5; z++)
writePlane(z);
}
void checkForBall(int x, int y, int z)
{
//if (x>=5 || x<0 || y>=5 || y<0 || z>=5 || z<0) return;
float dist = sqrt(
(x-ballx)*(x-ballx) +
(y-bally)*(y-bally) +
(z-ballz)*(z-ballz)
);
if (dist<ballwidth/2) set(x,y,z,true);
}
int _tmain(int argc, _TCHAR* argv[])
{
clear();
fp = fopen("c:\\bouncingball.cb5","w");
ballx = bally = ballz = 2.5;
dirx = 0.1;
diry = 0.2;
dirz = 0.3;
int frames = 1000;
while (frames>0)
{
clear();
for (int z=0; z<5; z++)
{
for (int y=0; y<5; y++)
{
for (int x=0; x<5; x++)
{
checkForBall(x,y,z);
}
}
}
ballx+=dirx;
bally+=diry;
ballz+=dirz;
if (ballx + (ballwidth/4) > 5 || ballx - (ballwidth/4) < 0) dirx*=-1;
if (bally + (ballwidth/4) > 5 || bally - (ballwidth/4) < 0) diry*=-1;
if (ballz + (ballwidth/4) > 5 || ballz - (ballwidth/4) < 0) dirz*=-1;
writeFrame();
frames--;
}
fclose(fp);
return 0;
}