internal void Init(DnaDrawing drawing, JobInfo info) { Points = new List<DnaPoint>(); //int count = info.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(drawing, info); if (drawing.Polygons.Count < 1) { origin.X = info.SourceImage.Width / 2; origin.Y = info.SourceImage.Height / 2; } for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++) { var point = new DnaPoint { X = Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)), info.SourceImage.Width), Y = Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)), info.SourceImage.Height) }; Points.Add(point); } Brush = new DnaBrush(); Brush.Init(info); }
internal void Init(DnaDrawing drawing, JobInfo info) { Points = new List <DnaPoint>(); //int count = info.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(drawing, info); if (drawing.Polygons.Count < 1) { origin.X = info.SourceImage.Width / 2; origin.Y = info.SourceImage.Height / 2; } for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++) { var point = new DnaPoint { X = Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)), info.SourceImage.Width), Y = Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)), info.SourceImage.Height) }; Points.Add(point); } Brush = new DnaBrush(); Brush.Init(info); }
public bool ccw(DnaPoint p1, DnaPoint p2, DnaPoint p3) { double dx1 = p2.X - p1.X; double dy1 = p2.Y - p1.Y; double dx2 = p3.X - p2.X; double dy2 = p3.Y - p2.Y; return(dy1 * dx2 < dy2 * dx1); }
public void Init() { Center = new DnaPoint(); Center.Init(); // TODO: Test random number Radius = Tools.GetRandomNumber(0, Tools.MaxWidth); Brush = new DnaBrush(); Brush.Init(); }
public void Init(DnaDrawing drawing, JobInfo info) { Points = new List <DnaPoint>(); //int count = info.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(drawing, info); if (drawing.Polygons.Count < 1) { origin.X = info.SourceImage.Width / 2; origin.Y = info.SourceImage.Height / 2; } for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++) { var point = new DnaPoint { X = Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)), info.SourceImage.Width), Y = Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)), info.SourceImage.Height) }; Points.Add(point); } bool findNew = true; if (info.Settings.MuteCurvePolygon && info.Settings.MuteLinePolygon && info.Settings.MuteCurveFillPolygon && info.Settings.MuteLineFillPolygon) { findNew = false; } Width = info.GetRandomNumber(1, 8); while (findNew) { bool splines = (info.GetRandomNumber(0, 2) == 1) ? true : false; bool filled = (info.GetRandomNumber(0, 2) == 1) ? true : false; findNew = !SetSplinesAndFilled(info.Settings, splines, filled); } Brush = new DnaBrush(); Brush.Init(info); }
public void Init(DnaDrawing drawing, JobInfo info) { Points = new List<DnaPoint>(); //int count = info.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(drawing, info); if (drawing.Polygons.Count < 1) { origin.X = info.SourceImage.Width / 2; origin.Y = info.SourceImage.Height / 2; } for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++) { var point = new DnaPoint { X = Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)), info.SourceImage.Width), Y = Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)), info.SourceImage.Height) }; Points.Add(point); } bool findNew = true; if (info.Settings.MuteCurvePolygon && info.Settings.MuteLinePolygon && info.Settings.MuteCurveFillPolygon && info.Settings.MuteLineFillPolygon) findNew = false; Width = info.GetRandomNumber(1, 8); while (findNew) { bool splines = (info.GetRandomNumber(0, 2) == 1) ? true : false; bool filled = (info.GetRandomNumber(0, 2) == 1) ? true : false; findNew = !SetSplinesAndFilled(info.Settings, splines, filled); } Brush = new DnaBrush(); Brush.Init(info); }
internal DnaPolygon Clone() { var newPolygon = new DnaPolygon { Points = new List <DnaPoint>(), Brush = Brush.Clone() }; unchecked { for (int i = 0; i < Points.Count; i++) { DnaPoint point = Points[i]; newPolygon.Points.Add(point.Clone()); } } return(newPolygon); }
public void Init() { Points = new List <DnaPoint>(); //int count = Tools.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(); for (int i = 0; i < Settings.ActivePointsPerPolygonMin; i++) { var point = new DnaPoint(); point.X = Math.Min(Math.Max(0, origin.X + Tools.GetRandomNumber(-3, 3)), Tools.MaxWidth); point.Y = Math.Min(Math.Max(0, origin.Y + Tools.GetRandomNumber(-3, 3)), Tools.MaxHeight); Points.Add(point); } Brush = new DnaBrush(); Brush.Init(); }
private void AddPoint(DnaDrawing drawing, JobInfo info) { if (Points.Count < info.Settings.PointsPerPolygonMax) { var newPoint = new DnaPoint(); int index = info.GetRandomNumber(1, Points.Count - 1); DnaPoint prev = Points[index - 1]; DnaPoint next = Points[index]; newPoint.X = (prev.X + next.X) / 2; newPoint.Y = (prev.Y + next.Y) / 2; Points.Insert(index, newPoint); drawing.SetDirty(); } }
public void Init() { Points = new List<DnaPoint>(); //int count = Tools.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(); for (int i = 0; i < Settings.ActivePointsPerPolygonMin; i++) { var point = new DnaPoint(); point.X = Math.Min(Math.Max(0, origin.X + Tools.GetRandomNumber(-3, 3)), Tools.MaxWidth); point.Y = Math.Min(Math.Max(0, origin.Y + Tools.GetRandomNumber(-3, 3)), Tools.MaxHeight); Points.Add(point); } Brush = new DnaBrush(); Brush.Init(); }
public void Init() { Points = new List<DnaPoint>(); //int count = Tools.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(); for (int i = 0; i < Settings.ActivePointsPerPolygonMin; i++) //adds the minimum (3) number of points to the polygon, and gives them random positions { var point = new DnaPoint(); point.X = Math.Min(Math.Max(0, origin.X + Tools.GetRandomNumber(-3, 3)), Tools.MaxWidth); point.Y = Math.Min(Math.Max(0, origin.Y + Tools.GetRandomNumber(-3, 3)), Tools.MaxHeight); Points.Add(point); } Brush = new DnaBrush(); //gives the shape some colour Brush.Init(); }
private void AddPoint(DnaDrawing drawing) { if (Points.Count < Settings.ActivePointsPerPolygonMax) { if (drawing.PointCount < Settings.ActivePointsMax) { var newPoint = new DnaPoint(); int index = Tools.GetRandomNumber(1, Points.Count - 1); DnaPoint prev = Points[index - 1]; DnaPoint next = Points[index]; newPoint.X = (prev.X + next.X)/2; newPoint.Y = (prev.Y + next.Y)/2; Points.Insert(index, newPoint); drawing.SetDirty(); } } }
private void AddPoint(IDnaDrawing drawing) { if (Points.Count < Settings.ActivePointsPerPolygonMax) { if (drawing.PointCount < Settings.ActivePointsMax) { var newPoint = new DnaPoint(); int index = Tools.GetRandomNumber(1, Points.Count - 1); DnaPoint prev = Points[index - 1]; DnaPoint next = Points[index]; newPoint.X = (prev.X + next.X) / 2; newPoint.Y = (prev.Y + next.Y) / 2; Points.Insert(index, newPoint); drawing.SetDirty(); } } }
public bool ccw(DnaPoint p1, DnaPoint p2, DnaPoint p3) { double dx1 = p2.X - p1.X; double dy1 = p2.Y - p1.Y; double dx2 = p3.X - p2.X; double dy2 = p3.Y - p2.Y; return dy1 * dx2 < dy2 * dx1; }
/// <summary> /// Convert DnaPoint to System.Windows Point /// </summary> private static System.Windows.Point GetSysWinPoint(DnaPoint p) { return new Point(p.X, p.Y); }
public void decompress() { QuickLZ qlz = new QuickLZ(); byte[] decompressed = qlz.Decompress(File.ReadAllBytes(InputFile)); Console.WriteLine("dec" + decompressed.Length.ToString()); BitArray bits = new BitArray(decompressed); Console.WriteLine("bits" + bits.Length.ToString()); int progress = 0; BitArray width = new BitArray(16); //Max width bitArrayCopy(bits, progress, width, 0, 16); Tools.MaxWidth = unwritebits(width); //create maxwidth progress += 16; BitArray height = new BitArray(16); //Max height bitArrayCopy(bits, progress, height, 0, 16); Tools.MaxHeight = unwritebits(height); //create maxheight progress += 16; BitArray avgreds = new BitArray(8); //red colour average bitArrayCopy(bits, progress, avgreds, 0, 8); int avgred = unwritebits(avgreds); progress += 8; BitArray avggreens = new BitArray(8); //green colour average bitArrayCopy(bits, progress, avggreens, 0, 8); int avggreen = unwritebits(avggreens); progress += 8; BitArray avgblues = new BitArray(8); //blue colour average bitArrayCopy(bits, progress, avgblues, 0, 8); int avgblue = unwritebits(avgblues); progress += 8; Tools.avgColour = System.Drawing.Color.FromArgb(avgred, avggreen, avgblue); //create average colour DnaDrawing newDrawing = new DnaDrawing(); //Create dnadrawing //newDrawing.Init(); BitArray polynumbers = new BitArray(10); //number of polygons bitArrayCopy(bits, progress, polynumbers, 0, 10); int polynumber = unwritebits(polynumbers); progress += 10; newDrawing.Polygons = new List<DnaPolygon>(); for (int i = 0; i < polynumber; i++) { Console.WriteLine(i); DnaPolygon polygon = new DnaPolygon(); //create dnapolygon polygon.Points = new List<DnaPoint>(); BitArray pointnumbers = new BitArray(5); //number of points bitArrayCopy(bits, progress, pointnumbers, 0, 5); int pointnumber = unwritebits(pointnumbers); progress += 5; BitArray alphas = new BitArray(8); //alpha colour bitArrayCopy(bits, progress, alphas, 0, 8); int alpha = unwritebits(alphas); progress += 8; BitArray reds = new BitArray(8); //red colour bitArrayCopy(bits, progress, reds, 0, 8); int red = unwritebits(reds); progress += 8; BitArray greens = new BitArray(8); //green colour bitArrayCopy(bits, progress, greens, 0, 8); int green = unwritebits(greens); progress += 8; BitArray blues = new BitArray(8); //blue colour bitArrayCopy(bits, progress, blues, 0, 8); int blue = unwritebits(blues); progress += 8; DnaBrush brush = new DnaBrush(); //create dnabrush brush.Alpha=alpha; brush.Red = red; brush.Green = green; brush.Blue=blue; polygon.Brush=brush; //assign brush for (int j = 0; j < pointnumber; j++) { DnaPoint point = new DnaPoint(); BitArray Xs = new BitArray(12); //x position bitArrayCopy(bits, progress, Xs, 0, 12); int x = unwritebits(Xs); progress += 12; point.X = x; BitArray Ys = new BitArray(12); //y position bitArrayCopy(bits, progress, Ys, 0, 12); int y = unwritebits(Ys); progress += 12; point.Y = y; polygon.Points.Add(point); } newDrawing.Polygons.Add(polygon); } int[,] DiffArray = new int[Tools.MaxWidth * Tools.MaxWidth, 4]; int[,] refArray = new int[Tools.MaxWidth * Tools.MaxWidth, 5]; for (int i = 0; i < Tools.MaxWidth * Tools.MaxWidth; i++) { BitArray firsts = new BitArray(1); //normal or reference bitArrayCopy(bits, progress, firsts, 0, 1); int first = unwritebits(firsts); progress += 1; if (first == 1) { BitArray reffs = new BitArray(11); //reference number bitArrayCopy(bits, progress, reffs, 0, 11); int reff = unwritebits(reffs); progress += 11; refArray[i,4]=reff; } else { //BitArray asizes = new BitArray(3); //alpha size //bitArrayCopy(bits, progress, asizes, 0, 3); int asize = 9;//unwritebits(asizes); //progress += 3; //BitArray rsizes = new BitArray(3); //red size //bitArrayCopy(bits, progress, rsizes, 0, 3); int rsize = 9;//unwritebits(rsizes); //progress += 3; //BitArray gsizes = new BitArray(3); //green size //bitArrayCopy(bits, progress, gsizes, 0, 3); int gsize = 9;//unwritebits(gsizes); //progress += 3; //BitArray bsizes = new BitArray(3); //blue size //bitArrayCopy(bits, progress, bsizes, 0, 3); int bsize = 9;//unwritebits(bsizes); //progress += 3; BitArray a = new BitArray(asize); //alpha bitArrayCopy(bits, progress, a, 0, asize); int alpha = unwritebits(a); progress += asize; DiffArray[i, 0] = alpha-256; BitArray r = new BitArray(rsize); //red bitArrayCopy(bits, progress, r, 0, rsize); int red = unwritebits(r); progress += rsize; DiffArray[i, 1] = red-256; BitArray g = new BitArray(gsize); //green bitArrayCopy(bits, progress, g, 0, gsize); int green = unwritebits(g); progress += gsize; DiffArray[i, 2] = green-256; BitArray b = new BitArray(bsize); //blue bitArrayCopy(bits, progress, b, 0, bsize); int blue = unwritebits(b); progress += bsize; DiffArray[i, 3] = blue-256; } } //int[,] fullArray = (int[,]) refArray.Clone(); for (int k = 0; k < refArray.Length / 5; k++) { if (refArray[k, 4] != 0) { DiffArray[k, 0] = refArray[k - refArray[k, 4], 0]; DiffArray[k, 1] = refArray[k - refArray[k, 4], 1]; DiffArray[k, 2] = refArray[k - refArray[k, 4], 2]; DiffArray[k, 3] = refArray[k - refArray[k, 4], 3]; Console.WriteLine(refArray[k, 1]); } } Console.WriteLine(newDrawing.Polygons.Count); Console.WriteLine("done with drawing"); Bitmap _bmp; Graphics _g; _bmp = new System.Drawing.Bitmap(Tools.MaxWidth, Tools.MaxHeight); _g = Graphics.FromImage(_bmp); Renderer.Render(newDrawing, _g, 1); BitmapData bd = _bmp.LockBits(new System.Drawing.Rectangle(0, 0, Tools.MaxWidth, Tools.MaxHeight), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _bmp.Save("finally.png", System.Drawing.Imaging.ImageFormat.Png); _bmp.UnlockBits(bd); Bitmap _bmp2 = new System.Drawing.Bitmap(Tools.MaxWidth, Tools.MaxHeight); int arraycounter2 = 0; for (int y = 0; y < Tools.MaxHeight; y++) { for (int x = 0; x < Tools.MaxWidth; x++) { System.Drawing.Color c1 = _bmp.GetPixel(x, y); int a = c1.A + DiffArray[arraycounter2, 0]; int r = c1.R + DiffArray[arraycounter2, 1]; int g = c1.G + DiffArray[arraycounter2, 2]; int b = c1.B + DiffArray[arraycounter2, 3]; System.Drawing.Color c3 = System.Drawing.Color.FromArgb(a, r, g, b); _bmp2.SetPixel(x, y, c3); arraycounter2++; } } _bmp2.Save("success.png", System.Drawing.Imaging.ImageFormat.Png); System.Diagnostics.Process.Start(@"success.png"); }