The two triangles have different slopes... 2:5 and 3:8, while in the first setup it appears to make one big triangle, it doesn't the "hypotenuse" isn't a straight line, so I guess you could call it an optical trick.

Add up the individual areas and they are the same, or as Todras said, just look at each piece they haven't changed, it's just a different arrangement.