! 3D Animated Balls gr.open 255,0,0,0 gr.orientation 0 gr.color 255,0,0,0 LET scw = 1280 LET sch = 800 LET csw = scw/2  % center_screenwidth LET 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 LET a = a + 0.1 LET b = b + 0.1 LET c = c + 0.1 LET i = 0 FOR x = -1 TO 1  FOR y = -1 TO  1    FOR z = -1 TO 1  LET i = i + 1 ! rotate about the z-axis   LET x1 = x*COS(a) - y*SIN(a)        LET y1 = y*COS(a) + x*SIN(a)        ! rotate about the y-axis     LET x2 = x1*COS(b) - z *SIN(b)      LET z1 = z *COS(b) + x1*SIN(b)     ! rotate about the x-axis     LET y2 = y1*COS(c) - z1*SIN(c)     LET 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 LET 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: FOR i = 1 TO 27 ! perspective trans. mod 500 value for depth LET sx = 500*balls[i,1]/(balls[i,3]-8)+csw   LET sy = 500*balls[i,2]/(balls[i,3]-8)+csh   ! green, darker if further away (z)   gr.color 255,0,(balls[i,3]+2)*20,0      ! circle, smaler if further away (z) gr.circle kr,sx, sy, (balls[i,3] + 4) * 6 NEXT i  gr.render gr.cls Return