i, r, n1, n2, lineix, lineiy, linerx, linery, lineixw, lineiyw, d, h, lambda = 45, 28.12, 1, 1.5, 50, 0, 228, 220, 270, 0, 168.41, 89.99, 41.81 setn1, setn2, seti = false, false ,false input="" function setn1() setn1 = true platform.window:invalidate() end function setn2() setn2 = true platform.window:invalidate() end function seti() seti = true platform.window:invalidate() end function on.paint(gc) r = math.floor(math.asin(n1*math.sin(i/360*2*math.pi)/n2)*100/(2*math.pi)*360)/100 i = math.floor(i*100)/100 n1 = math.floor(n1*1000)/1000 n2 = math.floor(n2*1000)/1000 h = math.floor(math.tan(math.pi/2-i/360*2*math.pi)*90*100)/100 d = math.floor(math.tan(math.pi/2-r/360*2*math.pi)*90*100)/100 if i<=45 then lineix = 160 - 22*i/9 lineiy = 0 lineixw = 160 + 22*i/9 lineiyw = 0 else lineiy = 22*i/9 - 110 lineix = 50 lineiyw = 22*i/9 - 110 lineixw = 270 end if r<=45 then linerx = 160 + 22*r/9 linery = 220 else linery = 220+(110-22*r/9) linerx = 270 end if n1 >= n2 then lambda = math.asin(n2/n1)/(2*math.pi)*360 else lambda = math.asin(n1/n2)/(2*math.pi)*360 end gc:setFont("sansserif","r","6") gc:setColorRGB(3,142,250) --blauw gc:fillRect(0,110,320,110) --rechthoek gc:setColorRGB(200,200,200) --grijs gc:drawArc(140,90,40,40,90-i,i) --hoekaanduiding weerk gc:drawLine(lineixw,lineiyw,160,110) --weerkaatste straal gc:drawLine(160,110,lineixw,220-lineiyw) --doorloping invallende straal --gc:drawLine(250,100,250,220) --vert lijn voor schijnb diepte gc:setColorRGB(0,0,0) --zwart gc:drawLine(0,110,320,110) --scheidingslijn stoffen gc:drawLine(160,0,160,220) --normaal lijn gc:drawString("n1: "..math.floor(n1*1000)/1000,15,195,"top") --print n1 gc:drawString("n2: "..math.floor(n2*1000)/1000,95,195,"top") --print n2 gc:drawString("i: "..i,190,195,"top") --print invallende hoek gc:drawString("normal",162,0,"top") --print "normal" gc:drawString("n1",1,92,"top") --print middenstof n1 gc:drawString("n2",1,112,"top") --print middenstof n2 gc:drawLine(lineix,lineiy,160,110) --invallende straal if i<=lambda then gc:drawLine(linerx,linery,160,110) --brekingsstraal gc:drawArc(140,90,40,40,-90,r) --hoekaanduiding brekingsstraal gc:drawString("r: "..r,260,195,"top") --print brekingshoek else gc:drawString("Total refl.",260,195,"top") end --gc:drawString("d = "..d,252,108,"top") --print schijnb diepte --gc:drawString("h = "..h,252,116,"top") --print echte diepte gc:drawString("Lambda = "..math.floor(lambda*100)/100,1,1,"top") --max hoek gc:drawArc(140,90,40,40,90,i) --hoekaanduiding invallende straal if seti or setn1 or setn2 then if seti then gc:drawString("i=",1,20,"top") end if setn1 then gc:drawString("n1=",1,20,"top") end if setn2 then gc:drawString("n2=",1,20,"top") end gc:setColorRGB(255,255,255) gc:fillRect(25,20,40,16) gc:setColorRGB(0,0,0) gc:drawRect(25,20,40,16) gc:setFont("sansserif","r","6") gc:drawString(input,27,20,"top") end end function on.enterKey() if seti or setn1 or setn2 then seti = false setn1 = false setn2 = false input = "" end platform.window:invalidate() end function on.activate() r = math.floor(math.asin(n1*math.sin(i/360*2*math.pi)/n2)*100/(2*math.pi)*360)/100 i = (var.recall("inputi") or math.floor(i)) n1 = (var.recall("inputn1") or math.floor(n1*1000)/1000) n2 = (var.recall("inputn2") or math.floor(n2*1000)/1000) --h = math.floor(math.tan(r)*d/math.tan(i)*100)/100 --h = math.floor(math.tan(math.pi/2-i/360*2*math.pi)*90*100)/100 --d = math.floor(math.tan(math.pi/2-r/360*2*math.pi)*90*100)/100 platform.window:invalidate() end function on.charIn(char) if seti then if char == '1' or char == '2' or char == '3' or char == '4' or char == '5' or char == '6' or char == '7'or char == '8' or char == '9' or char == '0' or char == '.' then if char == '.' and string.len(input) == 0 then input = input.."0" end input = input..char if tonumber(input) >= 90 then input = "90" end platform.window:invalidate() end if input == "" then i = 0 else i = tonumber(input) end end if setn1 then if char == '1' or char == '2' or char == '3' or char == '4' or char == '5' or char == '6' or char == '7'or char == '8' or char == '9' or char == '0' or char == '.' then if char == '.' and string.len(input) == 0 then input = input.."0" end if string.len(input)<=9 then input = input..char end platform.window:invalidate() end if input == "" then n1 = 0 else n1 = tonumber(input) end end if setn2 then if char == '1' or char == '2' or char == '3' or char == '4' or char == '5' or char == '6' or char == '7'or char == '8' or char == '9' or char == '0' or char == '.' then if char == '.' and string.len(input) == 0 then input = input.."0" end if string.len(input)<=9 then input = input..char end platform.window:invalidate() end if input == "" then n2 = 0 else n2 = tonumber(input) end end end function on.tabKey() --[tab] reset alles i, r, n1, n2, lineix, lineiy, linerx, linery, lineixw, lineiyw, d, h, lambda = 45, 28.12, 1, 1.5, 50, 0, 232, 220, 270, 0, 168.41, 89.99, 0 platform.window:invalidate() --scherm printen end function on.backspaceKey() if seti or setn1 or setn2 then input = string.usub(input,0,string.len(input)-1) end if seti then if input == "" then i = 0 else i = tonumber(input) end end if setn1 then if input == "" then n1 = 0 else n1 = tonumber(input) end end if setn2 then if input == "" then n2 = 0 else n2 = tonumber(input) end end platform.window:invalidate() end menu = { {"Change values", {"n1", setn1}, {"n2", setn2}, {"i", seti}, } } toolpalette.register(menu) setn1, setn2, seti = false, false ,false