Microsoft Small Basic

Program Listing: VZQ274
GraphicsWindow.width=400
GraphicsWindow.height=400

x=50 'bij deze coordinaat begin de invallende lichtstraal

TekenWaterEnNormaal()
TekenLichtstralen()

GraphicsWindow.MouseDown=OnMouseDown

Sub TekenWaterEnNormaal
GraphicsWindow.Clear()

'teken het water
GraphicsWindow.BrushColor=GraphicsWindow.GetColorFromRGB(0,0,200)
GraphicsWindow.FillRectangle(0,200,400,200)

' schrijf water en lucht
GraphicsWindow.BrushColor="black"
GraphicsWindow.DrawBoundText(5,180,400,"lucht")
GraphicsWindow.DrawBoundText(205,10,400,"de normaal")
GraphicsWindow.DrawBoundText(5,10,400,"klik bij de grijze lijn!")

GraphicsWindow.BrushColor="white"
GraphicsWindow.DrawBoundText(5,210,400,"water")

' teken een grijze lijn waar de lichtstraal kan beginnen
GraphicsWindow.PenColor=GraphicsWindow.GetColorFromRGB(150,150,150)
GraphicsWindow.DrawLine(0,50,200,50)




GraphicsWindow.PenColor="black"
' teken de normaal
GraphicsWindow.DrawLine(200,0,200,400)


Endsub

Sub TekenLichtstralen
' de invallende lichtstraal
GraphicsWindow.PenColor="black"
GraphicsWindow.DrawLine(x,50,200,200)

' bereken de richting van de gebroken lichtstraal
hoekvaninval=math.ArcTan(150/(200-x))

waarde=Math.Sin(hoekvaninval)/0.8
If waarde<1 then
brekingshoek=Math.ArcSin(waarde)

' teken de gebroken lichtstraal
x2=150/math.Tan(brekingshoek)

GraphicsWindow.DrawLine(200,200,200+x2,350)
else
GraphicsWindow.BrushColor="black"
GraphicsWindow.DrawBoundText(210,30,400,"alleen reflectie")
endif

EndSub

Sub OnMouseDown
' alleen in de buurt van de grijze lijn
If (GraphicsWindow.MouseY>40) And (GraphicsWindow.mouseY<60) And (GraphicsWindow.MouseX<200) then
x=graphicsWindow.mouseX

TekenWaterEnNormaal()
TekenLichtstralen()


endif

endsub