public long MakeOneOrbit() { int size = Size; double dx = (XMax - XMin) / size; double dy = (Ymax - YMin) / size; double cx = XMin + Rand.NextDouble() * (XMax - XMin); double cy = YMin + Rand.NextDouble() * (Ymax - YMin); if (Extensions.IsInBulb(cx, cy) || Extensions.IsInCardiod(cx, cy)) { return(TotalHits); } const double EscapeNorm = 4; // Zet Z0. double x, xx, y, yy; x = cx; y = cy; xx = x * x; yy = y * y; bool divergent = false; // Iterate. for (int i = 1; i <= Iteration; i++) { y = 2 * x * y + cy; x = xx - yy + cx; xx = x * x; yy = y * y; if (xx + yy >= EscapeNorm) { divergent = true; break; } } if (divergent) { // Plot. x = cx; y = cy; xx = x * x; yy = y * y; // Iterate. for (int i = 1; i <= Iteration; i++) { int ix = (int)Math.Round((x - XMin) / dx); int iy = (int)Math.Round((y - YMin) / dy); if (0 <= ix && ix < size && 0 <= iy && iy < size) { Hits[iy, ix]++; TotalHits++; } else { // break; } y = 2 * x * y + cy; x = xx - yy + cx; xx = x * x; yy = y * y; if (xx + yy >= EscapeNorm * 10) { break; } } } return(TotalHits); }