tutorial code + adaptation for square vertices