3D Snippet…,

please let me know how

to possibly use the Mintoris sort() command in this snippet…

please let me know how

to possibly use the Mintoris sort() command in this snippet…

Code: [Select]

`REM 3D Animated Balls`

REM original by Dr. Chip: http://appball.com/basic/viewtopic.php?f=7&t=343&p=1146&hilit=3D+balls#p1146

REM mod&port by Operator with painters algorithm

REM MBasic 6.3.3 / Moto G / Android 4.4.4

Graphics ON

Color 0,0,0

CLS

scw = ScreenX()

sch = ScreenY()

csw = scw/2 'center_screenwidth

csh = sch/2 'center_screenheight

'27 balls with 3 coordinates (x,y,z)

DIM balls(27,3)

lop:

Gosub Rotate

Gosub sort_z

Gosub draw

GOTO lop

Rotate:

'increment = faster rotations

a = a + 0.1

b = b + 0.1

c = c + 0.1

i = 0

FOR x = -1 TO 1

FOR y = -1 TO 1

FOR z = -1 TO 1

i = i + 1

'rotate about the z-axis

x1 = x*COS(a) - y*SIN(a)

y1 = y*COS(a) + x*SIN(a)

'rotate about the y-axis

x2 = x1*COS(b) - z *SIN(b)

z1 = z *COS(b) + x1*SIN(b)

'rotate about the x-axis

y2 = y1*COS(c) - z1*SIN(c)

z2 = z1*COS(c) + y1*SIN(c)

'load array with rot. coordinates

balls(i,1) = x2

balls(i,2) = y2

balls(i,3) = z2

NEXT z

NEXT y

NEXT x

i = 0

Return

sort_z:

'bubble sort z coordinate

FOR n = 27 TO 1 STEP -1

FOR i = 1 TO n-1

IF balls(i,3) > balls(i+1,3) THEN

temp = balls(i,3)

balls(i,3) = balls(i+1,3)

balls(i+1,3) = temp

temp = balls(i,2)

balls(i,2) = balls(i+1,2)

balls(i+1,2) = temp

temp = balls(i,1)

balls(i,1) = balls(i+1,1)

balls(i+1,1) = temp

Endif

NEXT i

NEXT n

Return

draw:

'draw all the balls…

color 0,0,0

CLS

FOR i = 1 TO 27

'perspective trans. mod 500 value for depth

sx = 500*balls(i,1)/(balls(i,3)-8)+csw

sy = 500*balls(i,2)/(balls(i,3)-8)+csh

'green, darker if further away (z)

COLOR 0,(balls(i,3)+2)*20,0

'circle, smaller if further away (z)

CIRCLE sx, sy, (balls(i,3) + 4) * 6,1

NEXT i

wait(10)

Return