REM **** simulation of simple lens ***** by smbstarv
'        refraction index AND cuvature of lens are variable (within limits)
'        theta1 AND theta2 are in/ouput angles on the left side of the lens
'        phi1 AND phi2 are in/output angles on the right side of the lens
'
     IF DEVICE_TYPE$()<>"iPad" THEN
         PRINT "for iPad only"
         STOP
     END IF
'g'
     GRAPHICS
     GRAPHICS CLEAR 0,0,0
     SET ORIENTATION 2
     OPTION ANGLE DEGREES
     SLIDER "rix" VALUE .5 AT 10,10 SIZE 300     'refractive index
     SLIDER "curv" VALUE .8 AT 500,10 SIZE 500   'curvature of leftside lens
     xrside=300
     topx=xrside
     topy=200
     botx=xrside
     boty=600
     y0=(topy+boty)/2
     
 s0:
     DRAW LINE topx,topy TO botx,boty            'draw rightside lens
     rix=1+SLIDER_VALUE("rix")*2
     DRAW TEXT "refraction index n = "&STR$(rix) AT 10,50
     svc=SLIDER_VALUE("curv")
     IF ABS(svc-.5)<.0001 THEN svc=.50001
     r=100/(svc-.5)
     h1=ASIN((boty-topy)/2/r)
     DRAW TEXT "curvature R= "&STR$(r) AT 510,50
     IF r>0 THEN
         x0=300+SQR(r^2-((boty-topy)/2)^2)
         DRAW ARC x0,y0,r,180-h1,180+h1          'draw leftside if convex lens
     END IF
     IF r<0 THEN
         x0=xrside+r
         DRAW ARC x0,y0,-r,h1,-h1                'draw leftside if concave lens
         cp=r-r*COS(h1)                          'cap length
         DRAW LINE TOpx+cp,TOpy TO TOpx,TOpy     'cap upper edge
         DRAW LINE botx+cp,boty TO botx,boty     'cap bottom edge
     END IF
'r'
     REFRESH OFF
     FOR y=(topy+10) TO (boty-10) STEP 20
         x1=x0-SQR(r^2-(y0-y)^2)*SIGN(r)
         y1=y
         DRAW LINE 0,y TO x1,y1                  'ray onto leftside lens
         theta1=ASIN((y-y0)/r)
         theta2=ASIN((y-y0)/r)/rix
         y2=TAN(theta1-theta2)*(x1-botx)+y
         IF topy<y2 AND boty>y2 THEN DRAW LINE x1,y TO xrside,y2'ray onto rightside lens
         phi1=theta1-theta2
         phi2=ASIN(SIN(phi1)*rix)
         maxphi1=ASIN(rix)
         IF ABS(SIN(phi1))<1/rix THEN            'from rightside onward
             IF topy<y2 AND boty>y2 THEN DRAW LINE xrside,y2 TO xrside+COS(phi2)*900,y2-SIN(phi2)*900
         END IF
     NEXT y
     REFRESH ON
'b'
     DO
         sw1=SLIDER_CHANGED("rix")
         sw2=SLIDER_CHANGED("curv")
         sw=sw1+ sw2
     UNTIL sw
     GRAPHICS CLEAR 0,0,0
     GOTO s0
     
     END
     