' Basic ASCII Raytracer — simple sphere rendering
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL x AS LONG, y AS LONG
    LOCAL val AS LONG
    LOCAL line0 AS STRING, line1 AS STRING
    LOCAL line2 AS STRING, line3 AS STRING, line4 AS STRING
    LOCAL line5 AS STRING, line6 AS STRING, line7 AS STRING
    LOCAL line8 AS STRING, line9 AS STRING
    LOCAL line10 AS STRING, line11 AS STRING

    PRINT "Basic ASCII Raytracer"
    PRINT "===================="
    PRINT ""
    PRINT "Rendering 12x20 ASCII sphere..."
    PRINT ""

    FOR y = -5 TO 6
        line0 = ""
        FOR x = -9 TO 10
            val = x * x + y * y
            IF val < 20 THEN
                line0 = line0 + "@"
            ELSEIF val < 30 THEN
                line0 = line0 + "#"
            ELSEIF val < 40 THEN
                line0 = line0 + "O"
            ELSEIF val < 55 THEN
                line0 = line0 + "."
            ELSEIF val < 70 THEN
                line0 = line0 + ","
            ELSE
                line0 = line0 + " "
            END IF
        NEXT x
        PRINT line0
    NEXT y

    PRINT ""
    PRINT "Scene: Sphere at center, light from top-left"
    PRINT "Legend: @=bright, #=medium, O=dim, .=dark, ,=edge"
    PRINT ""
    PRINT "ASCII raytracing uses distance from center"
    PRINT "to shade pixels. Closer = brighter."

    FUNCTION = 0
END FUNCTION
