public override void Initialize() { m_BallRb = ball.GetComponent <Rigidbody>(); m_ResetParams = Academy.Instance.EnvironmentParameters; SetResetParameters(); }
void Render(Surface dst, Surface src, Rectangle rect) { Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); ColorBgra sourceColor; ColorBgra imageColor; ColorBgra fillColor = Amount3; if (Amount2) { fillColor.A = 0; } int margin = Amount5; int radiusMax = Math.Min(selection.Width, selection.Height) / 2 - margin; radiusValue = (Amount1 > radiusMax) ? radiusMax : Amount1; // create a rectangle that will be used to determine how the pixels should be rendered rectangleTopCoordinate = selection.Top + margin + radiusValue; rectangleBottomCoordinate = selection.Bottom - margin - 1 - radiusValue; rectangleLeftCoordinate = selection.Left + margin + radiusValue; rectangleRightCoordinate = selection.Right - margin - 1 - radiusValue; // create point for testing how each pixel should be colored System.Windows.Point pointToTest = new System.Windows.Point(); for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) { return; } for (int x = rect.Left; x < rect.Right; x++) { sourceColor = src[x, y]; imageColor = sourceColor; imageColor.A = 0; // update point's coordinates pointToTest.X = x; pointToTest.Y = y; // if point is Not outside of the radius, use original source pixel Alpha value if (!PointOutsideRadius(pointToTest, 0)) { imageColor.A = sourceColor.A; } else if (Amount4) { if (!PointOutsideRadius(pointToTest, 0.333)) { imageColor.A = (byte)(0.7 * sourceColor.A); } else if (!PointOutsideRadius(pointToTest, 0.666)) { imageColor.A = (byte)(0.4 * sourceColor.A); } else if (!PointOutsideRadius(pointToTest, 1)) { imageColor.A = (byte)(0.2 * sourceColor.A); } } // Trim the margins if (margin > 0 && (x < selection.Left + margin || x > selection.Right - margin - 1 || y < selection.Top + margin || y > selection.Bottom - margin - 1)) { imageColor.A = 0; } dst[x, y] = normalOp.Apply(fillColor, imageColor); } } }
/// <summary> /// Renders the effect over rectangular regions automatically /// determined and handled by Paint.NET for multithreading support. /// </summary> /// <param name="parameters"> /// Saved settings used to restore the GUI to the same settings it was /// saved with last time the effect was applied. /// </param> /// <param name="dstArgs">The destination canvas.</param> /// <param name="srcArgs">The source canvas.</param> /// <param name="rois"> /// A list of rectangular regions to split this effect into so it can /// be optimized by worker threads. Determined and managed by /// Paint.NET. /// </param> /// <param name="startIndex"> /// The rectangle to begin rendering with. Used in Paint.NET's effect /// multithreading process. /// </param> /// <param name="length"> /// The number of rectangles to render at once. Used in Paint.NET's /// effect multithreading process. /// </param> public override void Render( EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { //Renders the effect if the dialog is closed and accepted. if (!IsCancelRequested && !renderReady) { var src = srcArgs.Surface; var dst = dstArgs.Surface; PersistentSettings token = (PersistentSettings)dlg.EffectToken; Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Bounds).GetBoundsInt(); //Something happened, so this must be the final render. if (StaticSettings.dialogResult != StaticSettings.DialogResult.Default) { renderReady = true; } if (StaticSettings.dialogResult == StaticSettings.DialogResult.StoringFirstImage) { if (selection.Width <= 1 || selection.Height <= 1 || ((token.BmpReplacing.Width != selection.Width || token.BmpReplacing.Height != selection.Height) && (token.BmpReplacing.Width != 1 && token.BmpReplacing.Height != 1))) { MessageBox.Show("The image to replace and its " + "replacing image must be the same size, and " + "the selection must be larger than a pixel."); return; } //Copies the data into the token. token.BmpToReplace = new Bitmap(selection.Width, selection.Height); for (int i = 0; i < selection.Width; i++) { for (int j = 0; j < selection.Height; j++) { token.BmpToReplace.SetPixel(i, j, src[selection.X + i, selection.Y + j]); } } } else if (StaticSettings.dialogResult == StaticSettings.DialogResult.StoringSecondImage) { if (selection.Width <= 1 || selection.Height <= 1 || ((token.BmpToReplace.Width != selection.Width || token.BmpToReplace.Height != selection.Height) && (token.BmpToReplace.Width != 1 && token.BmpToReplace.Height != 1))) { MessageBox.Show("The image to replace and its " + "replacing image must be the same size, and " + "the selection must be larger than a pixel."); return; } //Copies the data into the token. token.BmpReplacing = new Bitmap(selection.Width, selection.Height); for (int i = 0; i < selection.Width; i++) { for (int j = 0; j < selection.Height; j++) { token.BmpReplacing.SetPixel(i, j, src[selection.X + i, selection.Y + j]); } } } else if (StaticSettings.dialogResult == StaticSettings.DialogResult.Replacing) { if (token.BmpToReplace.Width != token.BmpReplacing.Width || token.BmpToReplace.Height != token.BmpReplacing.Height || token.BmpToReplace.Width == 1 || token.BmpToReplace.Height == 1) { MessageBox.Show("Both images must be selected first."); return; } List <Point> replacedPixels = new List <Point>(); //Looks at each pixel and compares it to the top-left //corner of the first image. Skips pixels that are too //far to the right or bottom to contain the entire image. //Tracks the pixel location. When a match is found, all //its pixels are checked. If everything matches, those //pixels are replaced immediately and added to a list of //pixels to skip over. dst.CopySurface(src); for (int y = 0; y <= src.Height - token.BmpToReplace.Height; y++) { for (int x = 0; x <= src.Width - token.BmpToReplace.Width; x++) { //Skips all pixels that have been replaced. if (replacedPixels.Count > 0 && replacedPixels[0].X == x && replacedPixels[0].Y == y) { replacedPixels.RemoveAt(0); continue; } //Checks if the first pixel matches. if (ColorsMatch(ColorBgra.FromColor( token.BmpToReplace.GetPixel(0, 0)), src[x, y], token.Tolerance)) { bool totalMatch = true; //Checks if every pixel matches. for (int yy = 0; yy < token.BmpToReplace.Height; yy++) { for (int xx = 0; xx < token.BmpToReplace.Width; xx++) { if (!ColorsMatch(ColorBgra.FromColor( token.BmpToReplace.GetPixel(xx, yy)), src[x + xx, y + yy], token.Tolerance)) { totalMatch = false; break; } } if (!totalMatch) { break; } } //Replaces the matching pixels. They will be skipped. if (totalMatch) { for (int yy = 0; yy < token.BmpReplacing.Height; yy++) { for (int xx = 0; xx < token.BmpReplacing.Width; xx++) { dst[x + xx, y + yy] = ColorBgra.FromColor(token.BmpReplacing.GetPixel(xx, yy)); //All pixels except the first should be skipped. //The first has been checked already. if (xx != 0 && yy != 0) { replacedPixels.Add(new Point(x + xx, y + yy)); } } } replacedPixels.OrderBy(p => p.X).ThenBy(p => p.Y); } } } } } } StaticSettings.dialogResult = StaticSettings.DialogResult.Default; }
public override void Initialize() { m_GoalSensor = this.GetComponent <VectorSensorComponent>(); m_ResetParams = Academy.Instance.EnvironmentParameters; }
public override void Initialize() { m_ResetParams = Academy.Instance.EnvironmentParameters; }
//public override EffectConfigDialog CreateConfigDialog() //{ // return new EffectPluginConfigDialog(); //} public void RenderRI(RenderArgs dstArgs, RenderArgs srcArgs, Rectangle rois) { //EffectPluginConfigToken effectPluginConfigToken = (EffectPluginConfigToken)parameters; //int size = effectPluginConfigToken.ApertureSize; int size = Value2; PdnRegion selectionRegion = EnvironmentParameters.GetSelection(srcArgs.Bounds); // Delete any of these lines you don't need Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Bounds).GetBoundsInt(); int CenterX = ((selection.Right - selection.Left) / 2) + selection.Left; int CenterY = ((selection.Bottom - selection.Top) / 2) + selection.Top; ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor; ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor; int BrushWidth = (int)EnvironmentParameters.BrushWidth; Random TempRandom = new Random(); int[] ApetureMinX = { -(size / 2), 0, -(size / 2), 0 }; int[] ApetureMaxX = { 0, (size / 2), 0, (size / 2) }; int[] ApetureMinY = { -(size / 2), -(size / 2), 0, 0 }; int[] ApetureMaxY = { 0, 0, (size / 2), (size / 2) }; //ColorBgra CurrentPixel; //for (int w = startIndex; w < startIndex + length; ++w) //{ /* Java source from original*/ Rectangle roi = rois; //[w]; int width = roi.Width; int height = roi.Height; int size2 = (size + 1) / 2; int offset = (size - 1) / 2; int width2 = srcArgs.Width + offset; int height2 = srcArgs.Height + offset; ValueSurface means = new ValueSurface { Width = width2, Height = height2 }; //double[,] meanr = new double[width2, height2]; double[,] variancer = new double[width2, height2]; //double[,] meang = new double[width2, height2]; double[,] varianceg = new double[width2, height2]; //double[,] meanb = new double[width2, height2]; double[,] varianceb = new double[width2, height2]; int x1Start = roi.X; int y1Start = roi.Y; for (int y1 = y1Start - offset; y1 < y1Start + height; y1++) { //if ((y1%20)==0) IJ.showProgress(0.7*(y1-y1start)/height); for (int x1 = x1Start - offset; x1 < x1Start + width; x1++) { double sumr = 0; double sumr2 = 0; double sumg = 0; double sumg2 = 0; double sumb = 0; double sumb2 = 0; int n = 0; for (int x2 = x1; x2 < x1 + size2; x2++) { if (x2 < 0 || x2 >= srcArgs.Bounds.Right) { continue; } for (int y2 = y1; y2 < y1 + size2; y2++) { if (y2 < 0 || y2 >= srcArgs.Bounds.Bottom) { continue; } int vr = srcArgs.Surface[x2, y2].R; sumr += vr; sumr2 += vr * vr; int vg = srcArgs.Surface[x2, y2].G; sumg += vg; sumg2 += vg * vg; int vb = srcArgs.Surface[x2, y2].B; sumb += vb; sumb2 += vb * vb; n++; } } means[x1 + offset, y1 + offset].kolor = new Kolor(sumr / n, sumg / n, sumb / n); //meanr[x1 + offset, y1 + offset] = sumr / n; variancer[x1 + offset, y1 + offset] = sumr2 - sumr * sumr / n; //meang[x1 + offset, y1 + offset] = sumg / n; varianceg[x1 + offset, y1 + offset] = sumg2 - sumg * sumg / n; //meanb[x1 + offset, y1 + offset] = sumb / n; varianceb[x1 + offset, y1 + offset] = sumb2 - sumb * sumb / n; } } //new ImagePlus("Variance", new FloatProcessor(variance)).show(); // ImageJ 1.35b or later int xbase2 = 0; int ybase2 = 0; for (int y1 = y1Start; y1 < y1Start + height; y1++) { //if ((y1%20)==0) IJ.showProgress(0.7+0.3*(y1-y1start)/height); for (int x1 = x1Start; x1 < x1Start + width; x1++) { double minr = double.MaxValue; double ming = double.MaxValue; double minb = double.MaxValue; int xbase = x1; //double xbase; int ybase = y1; //double ybase; double varr = variancer[xbase, ybase]; double varg = varianceg[xbase, ybase]; double varb = varianceb[xbase, ybase]; if (varr < minr) { minr = varr; xbase2 = xbase; ybase2 = ybase; } if (varg < ming) { ming = varg; xbase2 = xbase; ybase2 = ybase; } if (varb < minb) { minb = varb; xbase2 = xbase; ybase2 = ybase; } xbase = x1 + offset; varr = variancer[xbase, ybase]; varg = varianceg[xbase, ybase]; varb = varianceb[xbase, ybase]; if (varr < minr) { minr = varr; xbase2 = xbase; ybase2 = ybase; } if (varg < ming) { ming = varg; xbase2 = xbase; ybase2 = ybase; } if (varb < minb) { minb = varb; xbase2 = xbase; ybase2 = ybase; } ybase = y1 + offset; varr = variancer[xbase, ybase]; varg = varianceg[xbase, ybase]; varb = varianceb[xbase, ybase]; if (varr < minr) { minr = varr; xbase2 = xbase; ybase2 = ybase; } if (varg < ming) { ming = varg; xbase2 = xbase; ybase2 = ybase; } if (varb < minb) { minb = varb; xbase2 = xbase; ybase2 = ybase; } xbase = x1; varr = variancer[xbase, ybase]; varg = varianceg[xbase, ybase]; varb = varianceb[xbase, ybase]; if (varr < minr) { minr = varr; xbase2 = xbase; ybase2 = ybase; } if (varg < ming) { ming = varg; xbase2 = xbase; ybase2 = ybase; } if (varb < minb) { minb = varb; xbase2 = xbase; ybase2 = ybase; } ColorBgra tempColorBgra = new ColorBgra(); tempColorBgra = (byte)(means[xbase2, ybase2] + 0.5); //tempColorBgra.R = (byte)(meanr[xbase2, ybase2] + 0.5); tempColorBgra.G = (byte)(meang[xbase2, ybase2] + 0.5); tempColorBgra.B = (byte)(meanb[xbase2, ybase2] + 0.5); tempColorBgra.A = (byte)255; dstArgs.Surface[x1, y1] = tempColorBgra; } } //IJ.showProgress(1.0); /* End of Java source */ // Rectangle rect = rois[w]; // for (int y = rect.Top; y < rect.Bottom; ++y) // { // for (int x = rect.Left; x < rect.Right; ++x) // { // //OutputDebugStringW("ApetureMinX[]: " + ApetureMinX[0] + "," +ApetureMinX[1] + "," +ApetureMinX[2] + "," +ApetureMinX[3]); // //OutputDebugStringW("ApetureMaxX[]: " + ApetureMaxX[0] + "," + ApetureMaxX[1] + "," + ApetureMaxX[2] + "," + ApetureMaxX[3]); // //OutputDebugStringW("ApetureMinY[]: " + ApetureMinY[0] + "," + ApetureMinY[1] + "," + ApetureMinY[2] + "," + ApetureMinY[3]); // //OutputDebugStringW("ApetureMinX[]: " + ApetureMaxY[0] + "," + ApetureMaxY[1] + "," + ApetureMaxY[2] + "," + ApetureMaxY[3]); // //for (int y = selection.Top; y < selection.Bottom; y++) // //{ // // //OutputDebugStringW("Y position: " + y); // // for (int x = selection.Left; x < selection.Right; x++) // // { // CurrentPixel = srcArgs.Surface[x, y]; // ColorBgra NewPixel = new ColorBgra(); //dstArgs.Surface[x, y]; // int[] RValues = { 0, 0, 0, 0 }; // int[] GValues = { 0, 0, 0, 0 }; // int[] BValues = { 0, 0, 0, 0 }; // int[] NumPixels = { 0, 0, 0, 0 }; // int[] MaxRValue = { 0, 0, 0, 0 }; // int[] MaxGValue = { 0, 0, 0, 0 }; // int[] MaxBValue = { 0, 0, 0, 0 }; // int[] MinRValue = { 255, 255, 255, 255 }; // int[] MinGValue = { 255, 255, 255, 255 }; // int[] MinBValue = { 255, 255, 255, 255 }; // for (int i = 0; i < 4; ++i) // { // for (int x2 = ApetureMinX[i]; x2 < ApetureMaxX[i]; ++x2) // { // //if (y == selection.Top && x == selection.Left) // //{ // // OutputDebugStringW("x2: " + x2 + ", x: " + x + ", i: " + i + ", ApetureMinX[i]: " + ApetureMinX[i] + ", ApetureMaxX[i]: " + ApetureMaxX[i]); // //} // int TempX = x + x2; // // MessageBox.Show( // //"y = " + y.ToString() + "; " + // //"x = " + x.ToString() + "; " + // //"i = " + i.ToString() + "; " + // //"x2 = " + x2.ToString() + "; " + // //"ApetureMinX[i] = " + ApetureMinX[i].ToString() + "; " + // //"ApetureMaxX[i] = " + ApetureMaxX[i].ToString() + "; " + // // "TempX = " + TempX.ToString() + "; " + // // "selection.Width = " + selection.Width.ToString() + "; " // // ); // if (TempX >= 0 && TempX < selection.Left + selection.Width) // { // for (int y2 = ApetureMinY[i]; y2 < ApetureMaxY[i]; ++y2) // { // int TempY = y + y2; // //OutputDebugStringW("TempY = " + TempY.ToString() + "; " + // // "selection.Height = " + selection.Height.ToString() + "; " // // ); // if (TempY >= 0 && TempY < selection.Bottom + selection.Height) // { // //Color TempColor = src.GetPixel(TempX, TempY); // //MessageBox.Show( // // "R = " + CurrentPixel.R.ToString() + "; " + // // "G = " + CurrentPixel.G.ToString() + "; " + // // "B = " + CurrentPixel.B.ToString() + "; " + // //"MaxRValue[i] = " + MaxRValue[i].ToString() + "; " + // //"MinRValue[i] = " + MinRValue[i].ToString() + "; " + // //"MaxGValue[i] = " + MaxGValue[i].ToString() + "; " + // //"MinGValue[i] = " + MinGValue[i].ToString() + "; " + // //"MaxBValue[i] = " + MaxBValue[i].ToString() + "; " + // //"MinBValue[i] = " + MinBValue[i].ToString() + "; " // // ); // //Color TempColor = TempBitmap.GetPixel(TempX, TempY); // NewPixel = srcArgs.Surface[x, y]; // RValues[i] += NewPixel.R; //TempColor.R; // GValues[i] += NewPixel.G; //TempColor.G; // BValues[i] += NewPixel.B; //TempColor.B; // if (NewPixel.R > MaxRValue[i]) // { // MaxRValue[i] = NewPixel.R; // } // else if (NewPixel.R < MinRValue[i]) // { // MinRValue[i] = NewPixel.R; // } // if (NewPixel.G > MaxGValue[i]) // { // MaxGValue[i] = NewPixel.G; // } // else if (NewPixel.G < MinGValue[i]) // { // MinGValue[i] = NewPixel.G; // } // if (NewPixel.B > MaxBValue[i]) // { // MaxBValue[i] = NewPixel.B; // } // else if (NewPixel.B < MinBValue[i]) // { // MinBValue[i] = NewPixel.B; // } // ++NumPixels[i]; // } // } // } // } // } // int j = 0; // int MinDifference = 10000; // for (int i = 0; i < 4; ++i) // { // int CurrentDifference = (MaxRValue[i] - MinRValue[i]) + (MaxGValue[i] - MinGValue[i]) + (MaxBValue[i] - MinBValue[i]); // if (CurrentDifference < MinDifference && NumPixels[i] > 0) // { // j = i; // MinDifference = CurrentDifference; // } // } // //MessageBox.Show( // // "NumPixels[j] = " + NumPixels[j].ToString() + "; " + // // "RValues[j] = " + RValues[j].ToString() + "; " + // // "GValues[j] = " + GValues[j].ToString() + "; " + // //"BValues[j] = " + BValues[j].ToString() + "; " + // //"(byte)255 = " + (byte)255 + "; " // // ); // ColorBgra MeanPixel = new ColorBgra(); // MeanPixel.R = NumPixels[j] == 0 ? (byte)RValues[j] : (byte)(RValues[j] / NumPixels[j]); // MeanPixel.G = NumPixels[j] == 0 ? (byte)GValues[j] : (byte)(GValues[j] / NumPixels[j]); // MeanPixel.B = NumPixels[j] == 0 ? (byte)BValues[j] : (byte)(BValues[j] / NumPixels[j]); // MeanPixel.A = (byte)255; // //NewBitmap.SetPixel(x, y, MeanPixel); // // TODO: Add pixel processing code here // // Access RGBA values this way, for example: // // CurrentPixel.R = (byte)PrimaryColor.R; // // CurrentPixel.G = (byte)PrimaryColor.G; // // CurrentPixel.B = (byte)PrimaryColor.B; // // CurrentPixel.A = (byte)PrimaryColor.A; // dstArgs.Surface[x, y] = MeanPixel; // // } // //} // } // } //} }
private void Awake() { rbAgent = GetComponent <Rigidbody>(); EnvironmentParameters = Academy.Instance.EnvironmentParameters; Academy.Instance.OnEnvironmentReset += EnvironmentReset; }
public override void Initialize() { startQuaternion = transform.rotation; m_ResetParams = Academy.Instance.EnvironmentParameters; SetResetParameters(); }
public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { ConfigToken token = (ConfigToken)parameters; PdnRegion selection = EnvironmentParameters.GetSelectionAsPdnRegion(); if (changed) { changed = false; if (dialog != null) { dialog.SetProgressBarMaximum(token.effects.Count, tilesPerCpu * renderingThreadCount); dialog.EnableOKButton(false); } using (Surface scratch = new Surface(srcArgs.Size)) { scratch.CopySurface(srcArgs.Surface); for (int i = 0; i < token.effects.Count; ++i) { ScriptStep step = token.effects[i]; Type type = step.EffectType; if (type == null) { if (dialog != null) { dialog.IncrementProgressBarValue(i, 1); } } else { Effect effect = (Effect)(type.GetConstructor(Type.EmptyTypes).Invoke(new object[0])); effect.Services = Services; effect.EnvironmentParameters = new EffectEnvironmentParameters( step.PrimaryColor, step.SecondaryColor, EnvironmentParameters.BrushWidth, selection, EnvironmentParameters.SourceSurface); BackgroundEffectRenderer ber = new BackgroundEffectRenderer(effect, step.Token, dstArgs, new RenderArgs(scratch), selection, null, tilesPerCpu * renderingThreadCount, renderingThreadCount); ber.RenderedTile += (sender, e) => RenderedTile((BackgroundEffectRenderer)sender, i, e.TileCount); ber.Start(); ber.Join(); scratch.CopySurface(dstArgs.Surface); } if (IsCancelRequested) { return; } } if (dialog != null) { dialog.ClearProgressBars(); dialog.EnableOKButton(true); } } } }