!This program will calculate the box counting dimension of a graphic object
!that is in a PICT file format; asks for filename and box size as inputs,
!then allows to click on the boxes, keeping count of how many (N).
!It outputs N and L, log(N) and log (1/L). To get a new output, run it again
!selecting a different box size L.
!
SET MODE "graphics"
ASK PIXELS hpix, vpix
LET ratio=hpix/vpix
SET WINDOW 0,ratio,0,1
!Lets import the picture to analyze its box counting dimension
OPEN #1: SCREEN 0,.4,.85,1
SET WINDOW 0,1,0,1
INPUT PROMPT "PICT FILENAME (Full path please):":filename$
CALL READ_image("PICT",picture$,filename$)
WINDOW #0
BOX SHOW picture$ AT 0,0
!Ask for box size (L)
WINDOW #1
INPUT PROMPT "BOX SIZE? (0 to 1) :":L
!Done if clicked at x<.2, to output N vs. L result
PRINT "CLICK ->HERE<- WHEN DONE"
!Let's draw the boxes of size L
WINDOW #0
FOR i = 0 to ratio step L
FOR j = 0 to 1 step L
BOX LINES i,i+L,j,j+L
NEXT j
NEXT i
!Lets click on the boxes, color them red, and count the clicks
LET count=0
DO
GET POINT x,y
IF x<.2 THEN EXIT DO
IF x>=.2 THEN
LET count=count+1
SET COLOR "red"
PLOT AREA: L*INT(x/L),L*INT(y/L);L*(INT(x/L)+1),L*INT(y/L);L*(INT(x/L)+1),L*(INT(y/L)+1);L*INT(x/L),L*(INT(y/L)+1);L*INT(x/L),L*INT(y/L)
END IF
LOOP
!Lets print the N vs L results
WINDOW #1
CLEAR
PRINT "N =";count;"BOXES OF SIZE L =";L
PRINT "LOG(N) =";LOG10(count)
PRINT "LOG(1/L) =";LOG10(1/L)
END