// LINES AND CIRCLES
init<-0;
ls <-0;
PointCount <- 4;
ap <- null;
rp <- null;
xp <- null;
yp <- null;
// Init display makes a voxel display wall using special display voxels.
function Init_Display(Size)
{
local x,y;
// Clear Zone
for (x=0;x<32;x++)
for (y=0;y<64;y++) UNF_PlaceVoxel3D(x+1,y,0,0);
// Setup the screen
for (x=0;x<Size;x++)
for (y=0;y<Size;y++) UNF_PlaceVoxel3D(x+1,y,0,223);
}
// This function is called repeatedly for each step of the robot.
function Voxel_Step()
{
local x,y,i,radius;
local ax,ay, bx,by,cx,cy;
// Startup code, build the environnment. Executes only once.
if (init == 0)
{
init = 1;
Init_Display(32); // Init the display wall.
ap = [ 0.0 , 1.570796325 , 3.14159265, 4.712388975 ];
rp = [ 15.5 , 15.5 , 15.5, 15.5 ];
xp = array(16);
yp = array(16);
Image_New(0,32,32); // Create image canva to work with.
}
// Transformation
for (i=0;i<PointCount;i++)
{
xp[i]=(sin(ap[i]+ls)*rp[i]).tointeger() + 15;
yp[i]=(cos(ap[i]+ls)*rp[i]).tointeger() + 15;
xp[i+PointCount]=(sin(ap[i]+ls+2.41)*rp[i]/2.0).tointeger() + 15;
yp[i+PointCount]=(cos(ap[i]+ls+2.41)*rp[i]/2.0).tointeger() + 15;
}
// Clear image, Set radius.
radius = 5.0;
Image_Clear(0,7);
// Circles
for (i=0;i<10;i++)
{
ax = GetRnd(32); ay = GetRnd(32); bx = GetRnd(5);
Image_Circle_Filled(0,ax,ay,2,4-GetRnd(1));
}
// White square
Image_Line(0,xp[0],yp[0],xp[1],yp[1],0);
Image_Line(0,xp[1],yp[1],xp[2],yp[2],0);
Image_Line(0,xp[2],yp[2],xp[3],yp[3],0);
Image_Line(0,xp[3],yp[3],xp[0],yp[0],0);
// Green square
Image_Line(0,xp[4],yp[4],xp[5],yp[5],9);
Image_Line(0,xp[5],yp[5],xp[6],yp[6],9);
Image_Line(0,xp[6],yp[6],xp[7],yp[7],9);
Image_Line(0,xp[7],yp[7],xp[4],yp[4],9);
// Render the canva to the voxel wall
for (x=0;x<32;x++)
for (y=0;y<32;y++)
{
i = Image_GetPixel(0,31-x,31-y);
Voxel_SetInfo(1+x,0+y,0,1,i);
}
// Animate display : Change values for the next display step.
ls+=0.30; if (ls > 6.2831853 ) ls -= 6.2831853;
}