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

FUNCTION PBMAIN() AS LONG
    LOCAL x AS LONG
LOCAL y AS LONG
    LOCAL val AS LONG
    LOCAL line0 AS STRING
LOCAL line1 AS STRING
    LOCAL line2 AS STRING
LOCAL line3 AS STRING
LOCAL line4 AS STRING
    LOCAL line5 AS STRING
LOCAL line6 AS STRING
LOCAL line7 AS STRING
    LOCAL line8 AS STRING
LOCAL line9 AS STRING
    LOCAL line10 AS STRING
LOCAL 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
