public static void drawPlot(Panel xRedrawPanel, object xAnswer, double[] xPixel) { //DRAW PLOT FROM TEST DATA Bitmap bitmap = new Bitmap(NetMain.Net.SizeNet.Width, NetMain.Net.SizeNet.Height); int index = 0; for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; ++x) { switch (NetMain.Net.Mode) { case MODE.PIXEL: bitmap.SetPixel(x, y, Color.FromArgb((int)xPixel[index], (int)xPixel[index], (int)xPixel[index])); break; case MODE.HSENSOR: if (Mod_Check.isEven(y) && xPixel[y] * bitmap.Width > x) { bitmap.SetPixel(x, y, Color.Black); } break; } index++; } } //DISPLAY BITMAP bitmap = (Bitmap)ScaleUp(bitmap); bitmap = drawAnswer(bitmap, xAnswer); xRedrawPanel.BackgroundImage = bitmap; }
private bool isAlive(Color xColor, int x, int y) { //CHECK IS ALIVE if (x == 0 && y == 0) { Black = false; FrameCounter++; } else if (!Black && !Mod_Check.isGray(xColor, 150)) { Black = true; } if (Black) { Color after = xColor; if (xColor.R != 255 && xColor.G != 255 && xColor.B != 255) { after = Color.FromArgb(xColor.A, xColor.R + 1, xColor.G + 1, xColor.B + 1); } Color before = xColor; if (xColor.R != 0 && xColor.G != 0 && xColor.B != 0) { before = Color.FromArgb(xColor.A, xColor.R - 1, xColor.G - 1, xColor.B - 1); } Color last = LastFrameCam.GetPixel(x, y); if (last != xColor && last != after && last != before) { FrameCounter = 0; return(true); } else { return(false); } } //FRAME FREEZE if (FrameCounter > FrameFreeze) { return(false); } else { return(true); } }
public static double getAbsMax(double[,] xDoubleMatrix) { //ABBRUCH if (Mod_Check.checkParams(MethodBase.GetCurrentMethod(), xDoubleMatrix)) { return(0); } //GET MAXIMUM FROM DOUBLE MATRIX double max = double.MinValue; foreach (double item in xDoubleMatrix) { if (Math.Abs(item) > max) { max = Math.Abs(item); } } return(max); }
private void ModeHSensor(Bitmap xBmp, PaintEventArgs e) { //HSENSOR MODE Graphics g = e.Graphics; //GENERATE SENSOR DATA double max = xBmp.Width; double[] sensor = new double[xBmp.Height]; for (int y = 0; y < xBmp.Height; y++) { int count = 0; for (int x = 0; x < xBmp.Width; x++) { Color getColor = xBmp.GetPixel(x, y); if (Mod_Check.isGray(getColor, 200)) { count++; } else { if (Mod_Check.isEven(y)) //DISPLAY EVERY SECOND SENSOR { g.DrawLine(Pen, new Point(0, y), new Point(count, y)); //DRAW SENSOR TO CAMERA Graphics.FromImage(xBmp).DrawLine(Pen, new Point(0, y), new Point(count, y)); //DRAW SENSOR TO SCREEN } sensor[y] = count / max; count = 0; break; } } } //SET BINARY IMAGE NetMain.PanelBinary.BackgroundImage = NetDraw.ScaleUp(new Bitmap(xBmp)); LastSensor = sensor; g.Dispose(); }
public void Plot(Graphics g) { Pool = Main.Mario.Pool; //ABBRUCH if (Pool == null) { return; } //RECALCULATE NEUROEVOLUTION RecalculateNeuroevolution(Pool); //GET SPCIES LIST List <newSpecies> spciesList = Pool.species; for (int i = 0; i < spciesList.Count; i++) { float width = PanelLeft[2] + getScoreWidth(spciesList[i].topFitness); float average = PanelLeft[2] + getScoreWidth(spciesList[i].averageFitness); float height = PanelTop[0] + i * PenPositive.Width; //DRAW NUMBER g.DrawString((i + 1) + ".", Mod_Convert.FontSize(Fonts.MainFont, PenText.Width), PenText.Brush, new PointF(PanelLeft[1], height - PenPositive.Width / 2)); //DRAW SCORE if (Mod_Check.isEven(i)) { g.DrawLine(PenNegative, new PointF(PanelLeft[2], height), new PointF(width, height)); } else { g.DrawLine(PenPositive, new PointF(PanelLeft[2], height), new PointF(width, height)); } //DRAW STALE for (int l = 0; l < Pool.species[i].staleness; l++) { g.FillEllipse(new SolidBrush(Colors.MainLight), PanelLeft[2] + 1f + l * PenPositive.Width, height, PenPositive.Width / 2, PenPositive.Width / 2); } //DRAW AVERAGE g.DrawLine(new Pen(Colors.MainDominant, 1), new PointF(average, height), new PointF(average, height + PenPositive.Width / 2)); } //INFORMATIONS newSpecies currSpecies = Pool.species[Pool.currentSpecies]; //GET CURRENT SPECIES newGenome currGenome = currSpecies.genomes[Pool.currentGenome]; //GET CURRENT GENOME float left = PanelLeft[0]; Font infoFont = Mod_Convert.FontSize(Fonts.MainFont, 9); g.DrawString("Generation:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString(Pool.generation.ToString(), infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Species:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString((Pool.currentSpecies + 1) + "/" + Pool.species.Count, infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Genome:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString((Pool.currentGenome + 1) + "/" + currSpecies.genomes.Count, infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Stale:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString(currSpecies.staleness + "/" + (NetMario.StaleSpecies - 1), infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Fitness:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString(currGenome.fitness + " (" + Pool.maxFitness + ", " + currSpecies.averageFitness + ")", infoFont, PenText.Brush, new PointF(left, PanelTop[2])); left += PanelLeft[0] * 2.5f; g.DrawString("Measure:", infoFont, PenNegative.Brush, new PointF(left, PanelTop[1])); g.DrawString(Pool.measured + " %", infoFont, PenText.Brush, new PointF(left, PanelTop[2])); }