sync on : sync rate 0
 
`Color array
dim col(8)
col(1) = rgb(255,0,0) : col(2) = rgb(0,255,0) : col(3) = rgb(0,0,255)
col(4) = rgb(255,255,0) : col(5) = rgb(0,255,255) : col(6) = rgb(255,0,255)
col(5) = rgb(255,255,255) : col(8) = 0
 
`Create objects
CreateColorBox(1, 5.0, col(1), col(2), col(3), col(4), col(5), col(6), col(7), col(8))
CreateColorBox(2, 10.0, col(8), col(7), col(6), col(5), col(4), col(3), col(2), col(1))
make object 1,1,0 : set object cull 1, 0 : set object light 1, 0
make object 2,2,0 : set object cull 2, 0 : set object light 2, 0
ghost object on 1
 
do
 
   `Reposition objects
   position object 1,0,0,0
   position object 2,0,0,0
 
   `Rotate objects
   rotate object 1, wrapvalue(object angle x(1) + 0.2), wrapvalue(object angle y(1) + 0.333), wrapvalue( object angle z(1) - 0.77)
   rotate object 2, wrapvalue(object angle x(2) + 0.4), wrapvalue(object angle y(1) + 0.8), wrapvalue( object angle z(1) + 0.2 )
 
   `reposition camera
   position camera 0,0,0
 
   sync
loop
 
function CreateColorBox(id, size#, col1, col2, col3, col4, col5, col6, col7, col8)
 
   `A cube has 6 sides. 1 side = 2 triangles and 1 triangle = 3 verteces. --> 6*2*3 = 36 verteces for the cube
   Verts = 36
   s# = size# / 2
 
   `Create the memblock
   make memblock id, 12 + (Verts*36)
   write memblock dword id, 0, 338
   write memblock dword id, 4, 36
   write memblock dword id, 8, Verts
 
   `Write verteces
 
   `Top face
   WriteVertPos(id, 1, s#,s#,s#) : WriteVertNormal(id, 1, s#, s#+0.1, s#)
   WriteVertPos(id, 2, s#,s#,-s#) : WriteVertNormal(id, 2, s#, s#+0.1, -s#)
   WriteVertPos(id, 3, -s#,s#,-s#) : WriteVertNormal(id, 3, -s#, s#+0.1, -s#)
 
   WriteVertPos(id, 4, -s#,s#,-s#) : WriteVertNormal(id, 4, -s#, s#+0.1,-s#)
   WriteVertPos(id, 5, -s#,s#,s#) : WriteVertNormal(id, 5, -s#, s#+0.1, s#)
   WriteVertPos(id, 6, s#,s#,s#) : WriteVertNormal(id, 6, s#, s#+0.1, s#)
 
   `Bottom face
   WriteVertPos(id, 9, s#,-s#,s#) : WriteVertNormal(id, 9, s#, -s#-0.1, s#)
   WriteVertPos(id, 8, s#,-s#,-s#) : WriteVertNormal(id, 8, s#, -s#-0.1, -s#)
   WriteVertPos(id, 7, -s#,-s#,-s#) : WriteVertNormal(id, 7, -s#, -s#-0.1, -s#)
 
   WriteVertPos(id, 12, -s#,-s#,-s#) : WriteVertNormal(id, 12, -s#, -s#-0.1,-s#)
   WriteVertPos(id, 11, -s#,-s#,s#) : WriteVertNormal(id, 11, -s#, -s#-0.1, s#)
   WriteVertPos(id, 10, s#,-s#,s#) : WriteVertNormal(id, 10, s#, -s#-0.1, s#)
 
   `Front face
   WriteVertPos(id, 13, -s#,s#,-s#) : WriteVertNormal(id, 13, -s#,s#,-s#-0.1)
   WriteVertPos(id, 14, s#,s#,-s#) : WriteVertNormal(id, 14, s#,s#,-s#-0.1)
   WriteVertPos(id, 15, s#,-s#,-s#) : WriteVertNormal(id, 15, s#,-s#,-s#-0.1)
 
   WriteVertPos(id, 16, s#,-s#,-s#) : WriteVertNormal(id, 16, s#,-s#,-s#-0.1)
   WriteVertPos(id, 17, -s#,-s#,-s#) : WriteVertNormal(id, 17, -s#,-s#,-s#-0.1)
   WriteVertPos(id, 18, -s#,s#,-s#) : WriteVertNormal(id, 18, -s#,s#,-s#-0.1)
 
   `Back face
   WriteVertPos(id, 21, -s#,s#,s#) : WriteVertNormal(id, 21, -s#,s#,s#+0.1)
   WriteVertPos(id, 20, s#,s#,s#) : WriteVertNormal(id, 20, s#,s#,s#+0.1)
   WriteVertPos(id, 19, s#,-s#,s#) : WriteVertNormal(id, 19, s#,-s#,s#+0.1)
 
   WriteVertPos(id, 24, s#,-s#,s#) : WriteVertNormal(id, 24, s#,-s#,s#+0.1)
   WriteVertPos(id, 23, -s#,-s#,s#) : WriteVertNormal(id, 23, -s#,-s#,s#+0.1)
   WriteVertPos(id, 22, -s#,s#,s#) : WriteVertNormal(id, 22, -s#,s#,s#+0.1)
 
   `Left face
   WriteVertPos(id, 25, -s#,s#,s#) : WriteVertNormal(id, 25, -s#-0.1,s#,s#)
   WriteVertPos(id, 26, -s#,s#,-s#) : WriteVertNormal(id, 26, -s#-0.1,s#,-s#)
   WriteVertPos(id, 27, -s#,-s#,-s#) : WriteVertNormal(id, 27, -s#-0.1,-s#,-s#)
 
   WriteVertPos(id, 28, -s#,-s#,-s#) : WriteVertNormal(id, 28, -s#-0.1,-s#,-s#)
   WriteVertPos(id, 29, -s#,-s#,s#) : WriteVertNormal(id, 29, -s#-0.1,-s#,s#)
   WriteVertPos(id, 30, -s#,s#,s#) : WriteVertNormal(id, 30, -s#-0.1,s#,s#)
 
   `Right face
   WriteVertPos(id, 33, s#,s#,s#) : WriteVertNormal(id, 33, s#+0.1,s#,s#)
   WriteVertPos(id, 32, s#,s#,-s#) : WriteVertNormal(id, 32, s#+0.1,s#,-s#)
   WriteVertPos(id, 31, s#,-s#,-s#) : WriteVertNormal(id, 31, s#+0.1,-s#,-s#)
 
   WriteVertPos(id, 36, s#,-s#,-s#) : WriteVertNormal(id, 36, s#+0.1,-s#,-s#)
   WriteVertPos(id, 35, s#,-s#,s#) : WriteVertNormal(id, 35, s#+0.1,-s#,s#)
   WriteVertPos(id, 34, s#,s#,s#) : WriteVertNormal(id, 34, s#+0.1,s#,s#)
 
   `Write colors
   `First color
   `s#, s#, s#
   WriteVertAlpha(id, 1, col1) : WriteVertAlpha(id, 6, col1)
   WriteVertAlpha(id, 20, col1) : WriteVertAlpha(id, 33, col1)
   WriteVertAlpha(id, 34, col1)
 
   `s#,s#,-s#
   WriteVertAlpha(id, 2, col2) : WriteVertAlpha(id, 14, col2)
   WriteVertAlpha(id, 32, col2)
 
   `-s#,s#,-s#
   WriteVertAlpha(id, 3, col3) : WriteVertAlpha(id, 4, col3)
   WriteVertAlpha(id, 13, col3) : WriteVertAlpha(id, 18, col3)
   WriteVertAlpha(id, 26, col3)
 
   `-s#,s#,s#
   WriteVertAlpha(id, 5, col4) : WriteVertAlpha(id, 21, col4)
   WriteVertAlpha(id, 22, col4) : WriteVertAlpha(id, 25, col4)
   WriteVertAlpha(id, 30, col4)
 
   `s#,-s#,s#
   WriteVertAlpha(id, 9, col5) : WriteVertAlpha(id, 10, col5)
   WriteVertAlpha(id, 19, col5) : WriteVertAlpha(id, 24, col5)
   WriteVertAlpha(id, 35, col5)
 
   `-s#,-s#,-s#
   WriteVertAlpha(id, 7, col6) : WriteVertAlpha(id, 12, col6)
   WriteVertAlpha(id, 17, col6) : WriteVertAlpha(id, 27, col6)
   WriteVertAlpha(id, 28, col6)
 
   `s#,-s#,-s#
   WriteVertAlpha(id, 8, col7) : WriteVertAlpha(id, 15, col7)
   WriteVertAlpha(id, 16, col7) : WriteVertAlpha(id, 31, col7)
   WriteVertAlpha(id, 36, col7)
 
   `-s#,-s#,s#
   WriteVertAlpha(id, 11, col8) : WriteVertAlpha(id, 23, col8)
   WriteVertAlpha(id, 29, col8)
 
   make mesh from memblock id, id
 
endfunction
 
function WriteVertPos(id, VertNr, x#, y#, z#)
 
   `calc position
   pos = 12 + ((VertNr-1)*36)
 
   `write
   write memblock float id, pos, x#
   write memblock float id, pos+4, y#
   write memblock float id, pos+8, z#
 
endfunction
 
function WriteVertNormal(id, VertNr, x#, y#, z#)
 
   `Calc potition
   pos = 24 + ((VertNr-1)*36)
 
   `Write
   write memblock float id, pos, x#
   write memblock float id, pos+4, y#
   write memblock float id, pos+8, z#
 
endfunction
 
function WriteVertAlpha(id, VertNr, color)
 
   `Calc position
   pos = 36 + ((VertNr-1)*36)
 
   `Write
   write memblock dword id, pos, color
 
endfunction
 
function WriteVertUV(id, VertNr, uvx#, uvy#)
 
   `Calc positon
   pos = 48 + ((VertNr-1)*36)
 
   `Write
   write memblock float id, pos, uvx#
   write memblock float id, pos+4, uvy#
 
endfunction