public void Draw(float delta) { PSprite last = null; Parallel.For(completed, completed + imagesPerFrame + 1, i => { if (i < imageCount) { var input = PSprite.FromFilePath(@"E\image-" + (i + 1).ToString("00000") + ".png"); input = Convert(input); input.Save(@"E\out-" + i.ToString("00000") + ".png"); last = input; } else { Console.WriteLine("A"); } }); if (last != null) { Art.DrawImage(last, 0, 0, Width, Height); } completed += imagesPerFrame; }
public void Setup() { var i = 1; var name = "image-" + i.ToString("00000") + ".png"; while (File.Exists(@"E\" + name)) { imageCount++; i++; name = "image-" + i.ToString("00000") + ".png"; } Art.DrawImage(Convert(PSprite.FromFilePath("b.png")), 0, 0, Width, Height); }
public PixelParticles(string[] args) { var mode = ""; foreach (var a in args) { if (a.Trim() == string.Empty) { continue; } if (a.StartsWith("-")) { mode = a.Substring(1); } else { switch (mode) { case "s": StartImagePath = a; break; case "e": EndImagePath = a; break; case "f": OutputImagesFolderPath = a; break; case "o": OutputVideoPath = a; break; case "t": TimeToTakeSeconds = float.Parse(a); break; case "p": PixelLength = int.Parse(a); break; case "b": BufferFrames = int.Parse(a); break; case "x": ExportMode = a; break; case "r": FrameRateTarget = int.Parse(a); break; case "i": BackgroundImage = PSprite.FromFilePath(a); break; } } if (a == "-count") { Count = true; } } CreateCanvas(1920, 1080, FrameRateTarget); }
public void Draw(float delta) { var spritePath = Images[i]; var sprite = PSprite.FromFilePath(spritePath); var pixels = sprite.Art.GetPixels(); //for (var i = 0; i < Width * Height; i++) //{ // var index = (i * 4) + 2; // pixels[index] = 0; //} var max = Width * Height * 4; for (var index = 2; index < max; index += 4) { pixels[index] = 0; } sprite.Art.SetPixels(pixels); sprite.Save($@"LargestStar\OutImages\{i:000000}.png"); Art.DrawImage(sprite, 0, 0, Width, Height); i++; }
public void Setup() { StartImage = PSprite.FromFilePath(StartImagePath); EndImage = PSprite.FromFilePath(EndImagePath); if (Count) { var startCount = 0; var endCount = 0; for (var y = 0; y < Height; y++) { for (var x = 0; x < Width; x++) { if (StartImage.Art.GetPixel(x, y).A > 0) { startCount++; } if (EndImage.Art.GetPixel(x, y).A > 0) { endCount++; } } } Console.WriteLine("Start: " + startCount); Console.WriteLine("End: " + endCount); Console.ReadLine(); return; } var startPixels = StartImage.Art.GetPixels(); AvailablePositions = new OrderedDictionary(); pixels = new List <Pixel>(Width * Height); CalculateStart(Width, Height); var imagePixels = EndImage.Art.GetPixels(); var totalDone = 0; var width = Width; var height = Height; var generating = false; var count = 0; var distance = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var b = (x + (y * width)) * 4; var c = PColor.FromPixels(imagePixels, b); if (c.A > 0) { if (AvailablePositions.Count == 0) { if (generating) { while (generating) { } goto b; } generating = true; CalculateStart(width, height); generating = false; } b :; var pos = (-1, -1); distance -= 2; if (distance < 0) { distance = 0; } goto endWhile; // To Skip do { //for (var y2 = y - distance; y2 < y + distance + 1; y2++) //{ // for (var x2 = x - distance; x2 < x + distance + 1; x2++) // { // if (x2 > 0 && x2 < width && y2 > 0 && y2 < height) // { // pos = Check(x2, y2); // if (pos != (-1, -1)) { goto endWhile; } // } // } //} for (var y2 = (int)PMath.Clamp(y - distance, 0, height - 1); y2 < (int)PMath.Clamp(y + distance + 1, 0, height - 1); y2++) { var minus = (int)PMath.Clamp(x - distance, 0, width - 1); var tempPos = (minus, y2); pos = Available2[minus, y2] ? tempPos : (-1, -1); if (pos != (-1, -1)) { goto endWhile; } var plus = (int)PMath.Clamp(x + distance, 0, width - 1); tempPos = (plus, y2); pos = Available2[plus, y2] ? tempPos : (-1, -1); if (pos != (-1, -1)) { goto endWhile; } } for (var x2 = (int)PMath.Clamp(x - distance, 0, width - 1); x2 < (int)PMath.Clamp(x + distance + 1, 0, width - 1); x2++) { var minus = (int)PMath.Clamp(y - distance, 0, height - 1); var tempPos = (x2, minus); pos = Available2[x2, minus] ? tempPos : (-1, -1); if (pos != (-1, -1)) { goto endWhile; } var plus = (int)PMath.Clamp(y + distance, 0, height - 1); tempPos = (x2, plus); pos = Available2[x2, plus] ? tempPos : (-1, -1); if (pos != (-1, -1)) { goto endWhile; } } if (distance > width) { CalculateStart(width, height); distance = 0; } distance++; }while (pos == (-1, -1)); endWhile :; pos = ((int, int))AvailablePositions[0]; AvailablePositions.RemoveAt(0); //AvailablePositions.Remove(pos); Available2[pos.Item1, pos.Item2] = false; var b2 = (pos.Item1 + (pos.Item2 * width)) * 4; pixels.Add(new Pixel() { StartColor = PColor.FromPixels(startPixels, b2), EndColor = c, StartPos = pos, EndPos = (x, y), Offset = PMath.Random(0, Offset) });