Its called a "scintillating scotoma" and is the result of a cortical spreading depression. It doesnt need to be associated with pain, though it often is. It goes away when the spreading depression stops, which doesnt take that long. You're actually kinda lucky, some of them can get really weird. Like when everything breaks into triangles, or the scotoma is a shimmering rainbow or is nearly invisible but forming a sharply curved arc.