refract()
Purpose
Find the refraction of a vector
Description
Find the refraction of a vector when it passes through a surface
Syntax
result = refract( incident, normal, ior )
Arguments
result resulting refraction vector { x, y, z, w }
incident incident vector { x, y, z, w }
normal normal vector orthoganal to the surface { x, y, z, w }
ior index of refraction of the material from which the surface is made
Example
centre = { gWidth() / 2, gHeight() / 2 }
dir = { 1, 1 }
ior = 0.5
loop
clear()
c = controls( 0 )
ior += c.lx * 0.1
refractedDir = refract( dir, { 0, -1 }, ior )
box( 0, centre.y, gWidth(), centre.x, { 0, 0, 1, 0.2 }, false )
line( { centre.x - 250 * refractedDir.x, centre.y - 250 * dir.y }, centre, white )
line( centre, { centre.x + 250 * refractedDir.x, centre.y + 250 * refractedDir.y }, white )
printAt( 0, 0, "Move left Joy-Con Control stick left or right to adjust index of refraction" )
printAt( 0, 1, "Index of refraction: " + ior )
update()
repeat
Associated Commands