' ****** START INCLUDE UrlKey$(key$) ******
FUNCTION UrlKey$(key$)
  UrlKey$ = ""
  keyPos% = INSTR( UCASE$(UrlQueryString$), [ UCASE$(key$) + "=" ] )
  IF keyPos% THEN
      step1$ = RIGHT$( UrlQueryString$, [ LEN(UrlQueryString$) - keyPos% - LEN(key$) ] )
      step2% = INSTR(step1$, "&")
      UrlKey$ = IFF( step2%, [ LEFT$(step1$, step2% - 1 ) ], step1$)
  END IF
END FUNCTION
'  ****** END INCLUDE UrlKey$(key$) ******

' 🟡 DECLARATIONS

  CONST pi2# = _PI(2)                       , _
        side_size% = 901                    , _ 
        pie_center% = (side_size% - 1) / 2  , _
        pie_radius% = pie_center% - 2       , _
        paint_pos_radius% = pie_radius% - 5
        
  DIM   slice_sum# , slice_pct# , color&     , _
        screen% , black& , white&            , _
        data$ , hex_prefix$ = ""

  DECLARE SUB SetupScreen()
  DECLARE SUB DoRead()
  DECLARE SUB DoChartPhase(phase%)

' 🟡 MAIN PROGRAM

  CALL SetupScreen()

  SCREEN _NEWIMAGE(side_size%, side_size%,screen%) : COLOR ,white& : CLS

  CALL DoChartPhase(1)
  CALL DoChartPhase(2)
  
  WHILE NOT _MOUSEBUTTON : WEND

  END

' 🟡 FUNCTIONS & SUBROUTINES

  SUB SetupScreen()
    LET temp% = VAL(UrlKey$("screen"))
    black& = 0
    SELECT CASE temp%
      CASE 0 TO 12
        screen% = 12
        white& = 15
      CASE 13 TO 17
        screen% = 17
        white& = 63
      CASE ELSE
        screen% = 27
        white& = &hFFFFFF
        hex_prefix$ = "0x"
    END SELECT
  END SUB
  
  SUB DoRead()
      LET comma_pos% = INSTR(data$, "," )
      slice_pct# = VAL(LEFT$(data$, comma_pos% - 1))
      data$ = RIGHT$(data$, LEN(data$) - comma_pos%)
      LET comma_pos% = INSTR(data$, "," )
      color& = VAL( hex_prefix$ + LEFT$(data$, comma_pos% - 1) )
      data$ = RIGHT$(data$, LEN(data$) - comma_pos%)
  END SUB

  SUB DoChartPhase(phase%)
      LET data$ = UrlKey$("data")       ' RESTORE
      IF LEN(data$) > 1 THEN
        slice_sum# = 0 : CALL DoRead()
        WHILE slice_pct# > 0
            CIRCLE (pie_center%,pie_center%), pie_radius%, CHOOSE(phase%, black&, white&) , - pi2# * slice_sum# / 100, - pi2# * (slice_pct# + slice_sum#) / 100
            IF phase% = 1 THEN
                PSET (pie_center%,pie_center%), black&
                DRAW "BTA" + (INT( _R2D( ( pi2# * (slice_pct#+slice_sum#)/100 ) ) ) - 2) + " R " + STR$(paint_pos_radius%)
                PAINT (POINT(0),POINT(1)), color&, black&
            END IF
            slice_sum# = slice_sum# + slice_pct#
            CALL DoRead()
        WEND 
      END IF
  END SUB