private void IterateIcon() { int itcount = 0; int loopcount; if (isThreaded) { #region Threaded if (FirstPass) { for (int i = 0; i < threadcount; i++) { TValues[i] = new ThreadValues(i, Icon1.x + i * 0.00127, Icon1.y + i * 0.00172); } } ParallelLoopResult loopResult = new ParallelLoopResult(); loopResult = (Parallel.ForEach(TValues, tvalue => { // double _x = tvalue.qx; double _y = tvalue.qy; IconLoop(out loopcount, ref tvalue.qx, ref tvalue.qy); //tvalue.qx = _x; tvalue.qy = _y; itcount += loopcount; })); #endregion } else { #region Not-Threaded // double _x = Icon1.x; double _y = Icon1.y; IconLoop(out loopcount, ref Icon1.x, ref Icon1.y); itcount += loopcount; // Icon1.x = _x; Icon1.y = _y; #endregion } itsPerFrame = itcount; iterates += itcount;//(isThreaded ? (int)itsPerFrame * 8 : (int)itsPerFrame); }
private void IterateHexagon() { bool stop = false; int itcount = 0; if (isThreaded) { #region Threaded if (FirstPass) { for (int i = 0; i < threadcount; i++) { TValues[i] = new ThreadValues(i, Hexgn.x + i * 0.0127, Hexgn.y + i * 0.0172); } } Parallel.ForEach(TValues, tvalue => { double bx = 0, by = 0, xnew = tvalue.qx, ynew = tvalue.qy; //for (int thisRun = 0; thisRun < itsPerFrame; thisRun++) while (!stop) { double s11 = Math.Sin(p2 * (Hexgn.el11 * xnew + Hexgn.el12 * ynew)); double s12 = Math.Sin(p2 * (Hexgn.el21 * xnew + Hexgn.el22 * ynew)); double s13 = Math.Sin(p2 * (Hexgn.el31 * xnew + Hexgn.el32 * ynew)); double s21 = Math.Sin(p2 * (Hexgn.em11 * xnew + Hexgn.em12 * ynew)); double s22 = Math.Sin(p2 * (Hexgn.em21 * xnew + Hexgn.em22 * ynew)); double s23 = Math.Sin(p2 * (Hexgn.em31 * xnew + Hexgn.em32 * ynew)); double s31 = Math.Sin(p2 * (Hexgn.en11 * xnew + Hexgn.en12 * ynew)); double s32 = Math.Sin(p2 * (Hexgn.en21 * xnew + Hexgn.en22 * ynew)); double s33 = Math.Sin(p2 * (Hexgn.en31 * xnew + Hexgn.en32 * ynew)); double s3h1 = Math.Sin(p2 * (Hexgn.enh11 * xnew + Hexgn.enh12 * ynew)); double s3h2 = Math.Sin(p2 * (Hexgn.enh21 * xnew + Hexgn.enh22 * ynew)); double s3h3 = Math.Sin(p2 * (Hexgn.enh31 * xnew + Hexgn.enh32 * ynew)); double sx = (Hexgn.el11 * s11 + Hexgn.el21 * s12 + Hexgn.el31 * s13); double sy = (Hexgn.el12 * s11 + Hexgn.el22 * s12 + Hexgn.el32 * s13); xnew = Hexgn.ma * xnew + Hexgn.lambda * sx - Hexgn.omega * sy; ynew = Hexgn.ma * ynew + Hexgn.lambda * sy + Hexgn.omega * sx; xnew = xnew + Hexgn.alpha * (Hexgn.em11 * s21 + Hexgn.em21 * s22 + Hexgn.em31 * s23); ynew = ynew + Hexgn.alpha * (Hexgn.em12 * s21 + Hexgn.em22 * s22 + Hexgn.em32 * s23); xnew = xnew + Hexgn.a11 * s31 + Hexgn.a21 * s32 + Hexgn.a31 * s33; ynew = ynew + Hexgn.a12 * s31 + Hexgn.a22 * s32 + Hexgn.a32 * s33; xnew = xnew + Hexgn.ah11 * s3h1 + Hexgn.ah21 * s3h2 + Hexgn.ah31 * s3h3; by = 2 * ynew / sq3; bx = xnew - by / 2; bx = (bx - (int)bx) + 1; bx -= (int)bx; by = (by - (int)by) + 1; by -= (int)by; xnew = bx * Hexgn.k11 + by * Hexgn.k21; ynew = bx * Hexgn.k12 + by * Hexgn.k22; //tmpHit = (int)( field[(int)(bx * fieldN), (int)(by * fieldN)] += 0.1f; //if (tmpHit > MaxHitCount) MaxHitCount = tmpHit; //if (MinHitCount > tmpHit) MinHitCount = tmpHit; if (Stopwatch.ElapsedMilliseconds > 15) { stop = true; } itcount++; } tvalue.qx = bx; tvalue.qy = by; }); #endregion } else { #region Not-Threaded double bx = 0, by = 0, xnew = Hexgn.x, ynew = Hexgn.y; //for (int thisRun = 0; thisRun < itsPerFrame; thisRun++) while (!stop) { double s11 = Math.Sin(p2 * (Hexgn.el11 * xnew + Hexgn.el12 * ynew)); double s12 = Math.Sin(p2 * (Hexgn.el21 * xnew + Hexgn.el22 * ynew)); double s13 = Math.Sin(p2 * (Hexgn.el31 * xnew + Hexgn.el32 * ynew)); double s21 = Math.Sin(p2 * (Hexgn.em11 * xnew + Hexgn.em12 * ynew)); double s22 = Math.Sin(p2 * (Hexgn.em21 * xnew + Hexgn.em22 * ynew)); double s23 = Math.Sin(p2 * (Hexgn.em31 * xnew + Hexgn.em32 * ynew)); double s31 = Math.Sin(p2 * (Hexgn.en11 * xnew + Hexgn.en12 * ynew)); double s32 = Math.Sin(p2 * (Hexgn.en21 * xnew + Hexgn.en22 * ynew)); double s33 = Math.Sin(p2 * (Hexgn.en31 * xnew + Hexgn.en32 * ynew)); double s3h1 = Math.Sin(p2 * (Hexgn.enh11 * xnew + Hexgn.enh12 * ynew)); double s3h2 = Math.Sin(p2 * (Hexgn.enh21 * xnew + Hexgn.enh22 * ynew)); double s3h3 = Math.Sin(p2 * (Hexgn.enh31 * xnew + Hexgn.enh32 * ynew)); double sx = (Hexgn.el11 * s11 + Hexgn.el21 * s12 + Hexgn.el31 * s13); double sy = (Hexgn.el12 * s11 + Hexgn.el22 * s12 + Hexgn.el32 * s13); xnew = Hexgn.ma * xnew + Hexgn.lambda * sx - Hexgn.omega * sy; ynew = Hexgn.ma * ynew + Hexgn.lambda * sy + Hexgn.omega * sx; xnew = xnew + Hexgn.alpha * (Hexgn.em11 * s21 + Hexgn.em21 * s22 + Hexgn.em31 * s23); ynew = ynew + Hexgn.alpha * (Hexgn.em12 * s21 + Hexgn.em22 * s22 + Hexgn.em32 * s23); xnew = xnew + Hexgn.a11 * s31 + Hexgn.a21 * s32 + Hexgn.a31 * s33; ynew = ynew + Hexgn.a12 * s31 + Hexgn.a22 * s32 + Hexgn.a32 * s33; xnew = xnew + Hexgn.ah11 * s3h1 + Hexgn.ah21 * s3h2 + Hexgn.ah31 * s3h3; ynew = ynew + Hexgn.ah12 * s3h1 + Hexgn.ah22 * s3h2 + Hexgn.ah32 * s3h3; by = 2 * ynew / sq3; bx = xnew - by / 2; bx = (bx - (int)bx) + 1; bx -= (int)bx; by = (by - (int)by) + 1; by -= (int)by; xnew = bx * Hexgn.k11 + by * Hexgn.k21; ynew = bx * Hexgn.k12 + by * Hexgn.k22; //tmpHit = (int)( field[(int)(bx * fieldN), (int)(by * fieldN)] += 0.1f; //if (tmpHit > MaxHitCount) MaxHitCount = tmpHit; //if (MinHitCount > tmpHit) MinHitCount = tmpHit; if (Stopwatch.ElapsedMilliseconds > 15) { stop = true; } itcount++; } Hexgn.x = bx; Hexgn.y = by; #endregion } itsPerFrame = itcount; iterates += itcount; //(isThreaded ? (int)itsPerFrame * 8 : (int)itsPerFrame); }
private void IterateSquare() { bool stop = false; int itcount = 0; if (isThreaded) { #region Multitask if (FirstPass) { for (int i = 0; i < threadcount; i++) { TValues[i] = new ThreadValues(i, Quilt.x + i * 0.00127, Quilt.y + i * 0.00172); } } Parallel.ForEach(TValues, tvalue => { double x = tvalue.qx; double y = tvalue.qy; double xnew, ynew; // for (int thisRun = 0; thisRun < itsPerFrame; thisRun++) while (!stop) { double p2x = p2 * x; double p2y = p2 * y; double sx = Math.Sin(p2x); double sy = Math.Sin(p2y); xnew = (Quilt.lambda + Quilt.alpha * Math.Cos(p2y)) * sx - Quilt.omega * sy + Quilt.beta * Math.Sin(2 * p2x) + Quilt.gamma * Math.Sin(3 * p2x) * Math.Cos(2 * p2y) + Quilt.ma * x + Quilt.shift; ynew = (Quilt.lambda + Quilt.alpha * Math.Cos(p2x)) * sy + Quilt.omega * sx + Quilt.beta * Math.Sin(2 * p2y) + Quilt.gamma * Math.Sin(3 * p2y) * Math.Cos(2 * p2x) + Quilt.ma * y + Quilt.shift; xnew = (xnew - (int)xnew) + 1; xnew -= (int)xnew; ynew = (ynew - (int)ynew) + 1; ynew -= (int)ynew; //tmpHit = (int)( field[(int)(xnew * fieldN), (int)(ynew * fieldN)] += 0.1f; //if (tmpHit > MaxHitCount) MaxHitCount = tmpHit; //if (MinHitCount > tmpHit) MinHitCount = tmpHit; x = xnew; y = ynew; if (Stopwatch.ElapsedMilliseconds > 12) { stop = true; } itcount++; } tvalue.qx = x; tvalue.qy = y; TValues[tvalue.qid].running = false; }); #endregion } else { #region Singletask double x = Quilt.x; double y = Quilt.y; double xnew, ynew; //for (int thisRun = 0; thisRun < itsPerFrame; thisRun++) while (!stop) { double p2x = p2 * x; double p2y = p2 * y; double sx = Math.Sin(p2x); double sy = Math.Sin(p2y); xnew = (Quilt.lambda + Quilt.alpha * Math.Cos(p2y)) * sx - Quilt.omega * sy + Quilt.beta * Math.Sin(2 * p2x) + Quilt.gamma * Math.Sin(3 * p2x) * Math.Cos(2 * p2y) + Quilt.ma * x + Quilt.shift; ynew = (Quilt.lambda + Quilt.alpha * Math.Cos(p2x)) * sy + Quilt.omega * sx + Quilt.beta * Math.Sin(2 * p2y) + Quilt.gamma * Math.Sin(3 * p2y) * Math.Cos(2 * p2x) + Quilt.ma * y + Quilt.shift; xnew = (xnew - (int)xnew) + 1; xnew -= (int)xnew; ynew = (ynew - (int)ynew) + 1; ynew -= (int)ynew; //tmpHit = (int)( field[(int)(xnew * fieldN), (int)(ynew * fieldN)] += 0.1f; //if (tmpHit > MaxHitCount) MaxHitCount = tmpHit; //if (MinHitCount > tmpHit) MinHitCount = tmpHit; x = xnew; y = ynew; if (Stopwatch.ElapsedMilliseconds > 15) { stop = true; } itcount++; } Quilt.x = x; Quilt.y = y; #endregion } itsPerFrame = itcount; iterates += itcount; //(isThreaded ? (int)itsPerFrame * 8 : (int)itsPerFrame); }