code for the magical adaptive surface