public void Mutate(ThreadSafeRandom rd, GAProjectProperties prop) { for (int j = 0; j < rd.Next(prop.MaxPolygonChanges) + 1; j++) { int tochange = rd.Next(Shapes.Count); int type = rd.Next(10); if ((type == 0) && (prop.AllowAdditionalShapes) && ((!prop.LimitPolygons) || (Shapes.Count < prop.PolygonLimit))) { // New Shape AddShape(rd, prop, tochange); } else if ((type == 1) && (prop.AllowShapeRemoval) && (Shapes.Count > 1)) { // Delete Shape RemoveShape(tochange); } else if ((type == 2) && (Shapes.Count > 1)) { // Swap Two Shapes (Drawing Order) SwapShapes(rd, tochange); } else { // Change a Shape Shapes[tochange].Mutate(rd, prop); } } }
private void MutateRandomPoint(ThreadSafeRandom rd, GAProjectProperties prop) { int tochange = rd.Next(PolyPoints.Count); PointF pt = PolyPoints[tochange]; switch (rd.Next(3)) { case 0: //Change X pt.X += positionnudge(rd, prop); pt.X = limit(pt.X, Owner.MaxX, 0); break; case 1: // Change Y pt.Y += positionnudge(rd, prop); pt.Y = limit(pt.Y, Owner.MaxY, 0); break; case 2: //Change X + Y pt.X += positionnudge(rd, prop); pt.X = limit(pt.X, Owner.MaxX, 0); pt.Y += positionnudge(rd, prop); pt.Y = limit(pt.Y, Owner.MaxY, 0); break; } PolyPoints[tochange] = pt; }
public void Randomize(Random rd, GAProjectProperties prop) { PolyPoints.Clear(); Point p; for (int i = 0; i < 4; i++) { p = new Point(rd.Next(Owner.MaxX), rd.Next(Owner.MaxY)); PolyPoints.Add(p); } PolyColor = Color.FromArgb(rd.Next(255), rd.Next(255), rd.Next(255), rd.Next(255)); int type = rd.Next(3); if ((type == 0) && (prop.UseFilledPolygons)) { Type = GAShapeType.Polygon; } else if ((type == 1) && (prop.UseFilledPolycurves)) { Type = GAShapeType.PolyCurve; } else if ((type == 2) && (prop.UseLines)) { Type = GAShapeType.Line; } }
public void Load() { FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read); try { BinaryReader br = new BinaryReader(fs); string header = br.ReadString(); if (header == "GAVECTORPROJECT") { byte major = br.ReadByte(); byte minor = br.ReadByte(); if ((major < VERSIONMAJOR) || ((major == VERSIONMAJOR) && (minor <= VERSIONMINOR))) { GZipStream gz = new GZipStream(fs, CompressionMode.Decompress); br = new BinaryReader(gz); //Load The Image to a MemoryStream float resx = br.ReadSingle(); float resy = br.ReadSingle(); int bmlength = br.ReadInt32(); byte[] buffer = br.ReadBytes(bmlength); MemoryStream ms = new MemoryStream(buffer); Bitmap bt = new Bitmap(ms); bt.SetResolution(resx, resy); ms.Close(); buffer = null; // Draw the Bitmap onto a 24bpp canvas SourceImage = new FastBitmap(bt.Width, bt.Height, PixelFormat.Format24bppRgb); Graphics gp = Graphics.FromImage(SourceImage.GetBitmap()); gp.DrawImage(bt, PointF.Empty); gp.Dispose(); Properties = new GAProjectProperties(br); BestYet = new GARepresentation(br); BestComparison = br.ReadDouble(); } else { throw new Exception("Version incorrect, this version " + VERSIONMAJOR.ToString() + "." + VERSIONMINOR.ToString() + ", file version " + major.ToString() + "." + minor.ToString()); } } else { throw new Exception("Not a GAVector Project File"); } } catch (IOException) { throw new Exception("File is Corrupt"); } finally { fs.Close(); } }
private void AddShape(ThreadSafeRandom rd, GAProjectProperties prop, int tochange) { GAShape gap = GAShape.CreateRandom(rd, prop, this); Shapes.Insert(tochange, gap); OpShapeAdd++; }
public void MatrixSeed(Bitmap seed, GAProjectProperties prop) { Shapes.Clear(); int plug = prop.Granularity / 2; for (int x = 0; x < MaxX; x += prop.Granularity) { for (int y = 0; y < MaxY; y += prop.Granularity) { GAShapeFilledPolycurve gap = new GAShapeFilledPolycurve(this); Color c = seed.GetPixel(Math.Min(x + plug, MaxX - 1), Math.Min(y + plug, MaxY - 1)); gap.ShapeColour = Color.FromArgb(128, c.R, c.G, c.B); if ((gap.ShapeColour.ToArgb() & 0xFFFFFF) != (BackgroundColour.ToArgb() & 0xFFFFFF)) { if (prop.MatrixSeedingType == GAMatrixSeedingType.Blocks) { InitSeedBlocks(prop.Granularity, x, y, gap); } if (prop.MatrixSeedingType == GAMatrixSeedingType.Circles) { InitSeedCircles(prop.Granularity, x, y, gap); } Shapes.Add(gap); } } } UpdateTotalPoints(); }
public void GenericSeed(ThreadSafeRandom rd, GAProjectProperties prop) { Shapes.Clear(); AddShape(rd, prop, 0); UpdateTotalPoints(); }
private void LoadInit(MsgCommand mc) { Best = mc.Best; BestComparison = mc.BestComparison; Properties = mc.Properties; Img = mc.Img; WorkingImg = new FastBitmap(Img.Width, Img.Height, PixelFormat.Format24bppRgb); Entropy = mc.Entropy; }
protected float positionnudge(ThreadSafeRandom rd, GAProjectProperties prop) { float diff = NextFloat(rd, prop.MaxPointMovement) + 1; if (rd.Next(2) == 0) { diff *= -1; } return(diff); }
public int positionnudge(Random rd, GAProjectProperties prop) { int diff = rd.Next(prop.MaxPointMovement) + 1; if (rd.Next(2) == 0) { diff *= -1; } return(diff); }
public int colournudge(Random rd, GAProjectProperties prop) { int diff = rd.Next(prop.MaxColorMovement) + 1; if (rd.Next(2) == 0) { diff *= -1; } return(diff); }
private int sizenudge(ThreadSafeRandom rd, GAProjectProperties prop) { int diff = rd.Next(prop.MaxPointMovement) + 1; if (rd.Next(2) == 0) { diff *= -1; } return(diff); }
public override void Mutate(ThreadSafeRandom rd, GAProjectProperties prop) { for (int i = 0; i < rd.Next(prop.MaxPointChanges) + 1; i++) { int type = rd.Next(10); if ((type == 0) && (PolyPoints.Count < 256) && ((!prop.LimitPoints) || (PolyPoints.Count <= prop.PointLimit)) && (Type != GAShapeType.Line)) { // Add A Circle AddRandomPoint(rd, prop); Owner.OpPointAdded++; } else if ((type == 1) && (PolyPoints.Count > 3)) { // Remove A Circle RemoveRandomPoint(rd); Owner.OpPointRemove++; } else if (type == 2) { // Change Colour MutateColour(rd, prop); Owner.OpChangeColour++; } else if ((type == 3) && (prop.AllowPointSwapping) && (PolyPoints.Count > 3)) { // Swap Points SwapPoints(rd); Owner.OpSwapPoints++; } else if (type == 4) { // Change Tension Tension += positionnudge(rd, prop) / 10; } else if (type == 5) { // Change Fillmode if (ShapeFillMode == FillMode.Alternate) { ShapeFillMode = FillMode.Winding; } else { ShapeFillMode = FillMode.Alternate; } } else { MutateRandomPoint(rd, prop); Owner.OpPointMoved++; } } }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { Properties = null; BestYet = null; SourceImage.Dispose(); } _disposed = true; } }
public GAProjectProperties GetProperties() { GAProjectProperties prop = new GAProjectProperties(); if (rb_randomseed.Checked) { prop.Seeding = GASeeding.RandomSeed; } if (rb_matrixseed.Checked) { prop.Seeding = GASeeding.MatrixSeed; } if (rb_matrix_seed_circles.Checked) { prop.MatrixSeedingType = GAMatrixSeedingType.Circles; } if (rb_matrix_seed_blocks.Checked) { prop.MatrixSeedingType = GAMatrixSeedingType.Blocks; } prop.Granularity = (int)nud_matrix_granularity.Value; prop.UsePoints = cb_points.Checked; prop.UseLines = cb_lines.Checked; prop.UseCurves = cb_curves.Checked; prop.UseFilledPolygons = cb_filledpolygons.Checked; prop.UseFilledPolycurves = cb_filledcurves.Checked; prop.UsePaths = cb_paths.Checked; prop.BackgroundColorFromHistogram = cb_bghistogram.Checked; prop.LimitPolygons = cb_limitpolygons.Checked; prop.PolygonLimit = (int)nud_polylimit.Value; prop.LimitPoints = cb_limitpoints.Checked; prop.PointLimit = (int)nud_pointlimit.Value; prop.ThreadLimit = (Int16)nud_threadlimit.Value; prop.MaxPolygonChanges = (int)nud_polychanges.Value; prop.MaxPointChanges = (int)nud_pointchanges.Value; prop.MaxPointMovement = (int)nud_pointmovement.Value; prop.MaxColorMovement = (int)nud_colourmovement.Value; prop.AllowAdditionalShapes = cbx_additionalshapes.Checked; prop.AllowShapeRemoval = cbx_shaperemoval.Checked; prop.AllowPointSwapping = cbx_allowpointswapping.Checked; prop.AllowShapeMerging = cbx_shapemerging.Checked; prop.AllowShapeSplitting = cbx_shapesplit.Checked; return(prop); }
public override void Randomize(ThreadSafeRandom rd, GAProjectProperties prop) { PolyPoints.Clear(); PointF p; for (int i = 0; i < 3; i++) { p = new PointF(NextFloat(rd, Owner.MaxX), NextFloat(rd, Owner.MaxY)); PolyPoints.Add(p); } ShapeColour = Color.FromArgb(rd.Next(255), rd.Next(255), rd.Next(255), rd.Next(255)); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { Properties = null; Best = null; Img.Dispose(); WorkingImg.Dispose(); Entropy = null; } _disposed = true; } }
public void MutateSize(ThreadSafeRandom rd, GAProjectProperties prop) { int maxsize = Math.Max(Owner.MaxX, Owner.MaxY); if (Size == 1) { Size = 2; return; } else if (Size == maxsize) { Size = maxsize - 1; } else { Size += sizenudge(rd, prop); } Size = limit(Size, maxsize, 1); }
public void Mutate(Random rd, GAProjectProperties prop) { for (int i = 0; i < rd.Next(prop.MaxPointChanges) + 1; i++) { int type = rd.Next(20); if ((type == 0) && (PolyPoints.Count < 256) && ((!prop.LimitPoints) || (PolyPoints.Count <= prop.PointLimit)) && (Type != GAShapeType.Line)) { // Add A Point AddRandomPoint(rd, prop); Owner.OpPointAdded++; } else if ((type == 1) && (PolyPoints.Count > 4)) { // Remove A Point RemoveRandomPoint(rd); Owner.OpPointRemove++; } else if (type == 2) { // Change Colour MutateColour(rd, prop); Owner.OpChangeColour++; } else if ((type == 3) && (prop.AllowPointSwapping) && (PolyPoints.Count > 3)) { // Swap Points SwapPoints(rd); Owner.OpSwapPoints++; } else if ((type == 4) && (prop.AllowShapeSplitting) && (PolyPoints.Count > 5)) { // Split Polygon Split(rd); Owner.OpShapeSplit++; } else { MutateRandomPoint(rd, prop); Owner.OpPointMoved++; } } }
public override void Mutate(ThreadSafeRandom rd, GAProjectProperties prop) { for (int i = 0; i < rd.Next(prop.MaxPointChanges) + 1; i++) { int type = rd.Next(10); if ((type == 0) && (PolyPoints.Count < 256) && ((!prop.LimitPoints) || (PolyPoints.Count <= prop.PointLimit))) { // Add A Line AddRandomPoint(rd, prop); Owner.OpPointAdded++; } else if ((type == 1) && (PolyPoints.Count > 2)) { // Remove A Line RemoveRandomPoint(rd); Owner.OpPointRemove++; } else if (type == 2) { // Change Colour MutateColour(rd, prop); Owner.OpChangeColour++; } else if ((type == 3) && (prop.AllowPointSwapping) && (PolyPoints.Count > 3)) { // Swap Points SwapPoints(rd); Owner.OpSwapPoints++; } else if (type == 4) { // Change Width Width += positionnudge(rd, prop); } else { MutateRandomPoint(rd, prop); Owner.OpPointMoved++; } } }
public override void Mutate(ThreadSafeRandom rd, GAProjectProperties prop) { for (int i = 0; i < rd.Next(prop.MaxPointChanges) + 1; i++) { switch (rd.Next(3)) { case 0: MutateColour(rd, prop); break; case 1: MutatePosition(rd, prop); break; case 2: MutateSize(rd, prop); break; } } }
public void MutatePosition(ThreadSafeRandom rd, GAProjectProperties prop) { PointF pt = PolyPoints[0]; switch (rd.Next(2)) { case 0: pt.X += positionnudge(rd, prop); break; case 1: pt.Y += positionnudge(rd, prop); break; } pt.X = limit(pt.X, Owner.MaxX, 0); pt.Y = limit(pt.Y, Owner.MaxY, 0); PolyPoints[0] = pt; }
public virtual PointF GetRandomPoint(ThreadSafeRandom rd, GAProjectProperties prop) { float maxX = 0, maxY = 0, minX = Owner.MaxX, minY = Owner.MaxY; // Find Outer Limits foreach (PointF p in PolyPoints) { if (maxX < p.X) { maxX = p.X; } if (maxY < p.Y) { maxY = p.Y; } if (minX > p.X) { minX = p.X; } if (minY > p.Y) { minY = p.Y; } } maxX = limit(maxX + prop.MaxPointMovement, Owner.MaxX, 0); maxY = limit(maxY + prop.MaxPointMovement, Owner.MaxY, 0); minX = limit(minX - prop.MaxPointMovement, Owner.MaxX, 0); minY = limit(minY - prop.MaxPointMovement, Owner.MaxY, 0); return(new PointF(minX + NextFloat(rd, maxX - minX), minY + NextFloat(rd, maxY - minY))); //return new Circle(NextFloat(Entropy,Owner.MaxX),NextFloat(Entropy,Owner.MaxY)); }
private Point GetRandomPoint(Random rd, GAProjectProperties prop) { int maxX = 0, maxY = 0, minX = Owner.MaxX, minY = Owner.MaxY; // Find Outer Limits foreach (Point p in PolyPoints) { if (maxX < p.X) { maxX = p.X; } if (maxY < p.Y) { maxY = p.Y; } if (minX > p.X) { minX = p.X; } if (minY > p.Y) { minY = p.Y; } } maxX = limit(maxX + prop.MaxPointMovement, Owner.MaxX, 0); maxY = limit(maxY + prop.MaxPointMovement, Owner.MaxY, 0); minX = limit(minX - prop.MaxPointMovement, Owner.MaxX, 0); minY = limit(minY - prop.MaxPointMovement, Owner.MaxY, 0); return(new Point(minX + rd.Next(maxX - minX), minY + rd.Next(maxY - minY))); }
private void MutateColour(Random rd, GAProjectProperties prop) { int r, b, g, a = 0; r = PolyColor.R; g = PolyColor.G; b = PolyColor.B; a = PolyColor.A; switch (rd.Next(4)) { case 0: //Change Red r += colournudge(rd, prop); break; case 1: // Change Green g += colournudge(rd, prop); break; case 2: // Change Blue b += colournudge(rd, prop); break; case 3: // Change Transarency a += colournudge(rd, prop); break; } r = limit(r, 255, 0); g = limit(g, 255, 0); b = limit(b, 255, 0); a = limit(a, 255, 0); PolyColor = Color.FromArgb(a, r, g, b); }
public void LoadProperties(GAProjectProperties prop) { rb_randomseed.Checked = (prop.Seeding == GASeeding.RandomSeed); rb_matrixseed.Checked = (prop.Seeding == GASeeding.MatrixSeed); rb_matrix_seed_circles.Checked = (prop.MatrixSeedingType == GAMatrixSeedingType.Circles); rb_matrix_seed_blocks.Checked = (prop.MatrixSeedingType == GAMatrixSeedingType.Blocks); nud_matrix_granularity.Value = prop.Granularity; cb_points.Checked = prop.UsePoints; cb_lines.Checked = prop.UseLines; cb_curves.Checked = prop.UseCurves; cb_filledpolygons.Checked = prop.UseFilledPolygons; cb_filledcurves.Checked = prop.UseFilledPolycurves; cb_paths.Checked = prop.UsePaths; cb_bghistogram.Checked = prop.BackgroundColorFromHistogram; cb_limitpolygons.Checked = prop.LimitPolygons; nud_polylimit.Value = prop.PolygonLimit; cb_limitpoints.Checked = prop.LimitPoints; nud_pointlimit.Value = prop.PointLimit; nud_threadlimit.Value = prop.ThreadLimit; nud_polychanges.Value = prop.MaxPolygonChanges; nud_pointchanges.Value = prop.MaxPointChanges; nud_pointmovement.Value = prop.MaxPointMovement; nud_colourmovement.Value = prop.MaxColorMovement; cbx_additionalshapes.Checked = prop.AllowAdditionalShapes; cbx_shaperemoval.Checked = prop.AllowShapeRemoval; cbx_allowpointswapping.Checked = prop.AllowPointSwapping; cbx_shapesplit.Checked = prop.AllowShapeSplitting; cbx_shapemerging.Checked = prop.AllowShapeMerging; CheckMatrixSeedingPanel(); }
public override PointF GetRandomPoint(ThreadSafeRandom rd, GAProjectProperties prop) { return(new PointF(NextFloat(rd, Owner.MaxX), NextFloat(rd, Owner.MaxY))); }
public static GAShape CreateRandom(ThreadSafeRandom rd, GAProjectProperties prop, GARepresentation owner) { List <GAShapeType> lt = new List <GAShapeType>(); if (prop.UsePoints) { lt.Add(GAShapeType.Circle); } if (prop.UseLines) { lt.Add(GAShapeType.Line); } if (prop.UseCurves) { lt.Add(GAShapeType.Curve); } if (prop.UseFilledPolygons) { lt.Add(GAShapeType.FilledPolygon); } if (prop.UseFilledPolycurves) { lt.Add(GAShapeType.FilledPolycurve); } //if (prop.UsePaths) lt.Add(GAShapeType.Path); if (lt.Count == 0) { throw new Exception("GASHape.CreateRandom - No Shapes Allowed"); } GAShape output = null; switch (lt[rd.Next(lt.Count)]) { case GAShapeType.Circle: output = new GAShapeCircle(owner); break; case GAShapeType.Line: output = new GAShapeLine(owner); break; case GAShapeType.Curve: output = new GAShapeCurve(owner); break; case GAShapeType.FilledPolygon: output = new GAShapeFilledPolygon(owner); break; case GAShapeType.FilledPolycurve: output = new GAShapeFilledPolycurve(owner); break; case GAShapeType.Path: output = new GAShapePath(owner); break; } output.Randomize(rd, prop); return(output); }
public abstract void Mutate(ThreadSafeRandom rd, GAProjectProperties prop);
private void AddRandomPoint(ThreadSafeRandom rd, GAProjectProperties prop) { PointF p = GetRandomPoint(rd, prop); PolyPoints.Insert(rd.Next(PolyPoints.Count), p); }