Canvas clears after changing var n