//static void Main(string[] args) //{ // //GameOfLifeSource golSrc = new GameOfLifeSource(1680, 1050); // GameOfLifeSource golSrc = new GameOfLifeSource(840, 525); // 1680 x 1050 / 2 // //GameOfLifeSource golSrc = new GameOfLifeSource(560, 350); // 1680 x 1050 / 3 // //GameOfLifeSource golSrc = new GameOfLifeSource(336, 210); // 1680 x 1050 / 5 // GenericDelay<Image> delayFilt = new GenericDelay<Image>(new TimeSpan(0, 0, 0, 0, 100)); // //WallpaperFilter wpFilt = new WallpaperFilter(); // DisplayFilter displayFilt = new DisplayFilter(); // golSrc.OutputPin.AttachTo(delayFilt.InputPin); // delayFilt.OutputPin.AttachTo(displayFilt.InputPin); // displayFilt.OutputPin.AttachTo(golSrc.InputPin); // PinOut<Image> golSrcOut = new PinOut<Image>(); // golSrcOut.AttachTo(golSrc.InputPin); // golSrcOut.Send(null); // //golSrcOut.Send(null); // //golSrcOut.Send(null); // //golSrcOut.Send(null); // Console.ReadLine(); //} static void Main(string[] args) { RedditSource redditSource = new RedditSource("http://www.reddit.com/r/pics/.json"); GenericFilter <Image> sizeFilt = new GenericFilter <Image>(img => 100 < img.Width && img.Width < 1000 && 100 < img.Height && img.Height < 800); BorderFilter brdInnerFilt = new BorderFilter(Color.Black, 1); BorderFilter brdOuterFilt = new BorderFilter(Color.White, 9); RotateFilter rotFilt = new RotateFilter(-30, 30); CanvasFilter cvsFilt = new CanvasFilter(); GenericDelay <Image> delayFilt = new GenericDelay <Image>(new TimeSpan(0, 0, 30)); WallpaperFilter wpFilt = new WallpaperFilter(); redditSource.OutputPin.AttachTo(sizeFilt.InputPin); sizeFilt.SuccessPin.AttachTo(brdInnerFilt.InputPin); sizeFilt.FailurePin.AttachTo(redditSource.InputPin); brdInnerFilt.OutputPin.AttachTo(brdOuterFilt.InputPin); brdOuterFilt.OutputPin.AttachTo(rotFilt.InputPin); rotFilt.OutputPin.AttachTo(cvsFilt.PictureInputPin); cvsFilt.OutputPin.AttachTo(delayFilt.InputPin); cvsFilt.OutputPin.AttachTo(cvsFilt.CanvasInputPin); delayFilt.OutputPin.AttachTo(wpFilt.InputPin); wpFilt.OutputPin.AttachTo(redditSource.InputPin); /* prime canvas */ PinOut <Image> canvasOut = new PinOut <Image>(); canvasOut.AttachTo(cvsFilt.CanvasInputPin); Image canvas; try { int bytesRead; byte[] buf = new byte[1024]; FileStream fs = new FileStream(Path.Combine(Environment.CurrentDirectory, "wall.bmp"), FileMode.Open); MemoryStream ms = new MemoryStream(); while ((bytesRead = fs.Read(buf, 0, 1024)) > 0) { ms.Write(buf, 0, bytesRead); } ms.Seek(0, SeekOrigin.Begin); fs.Close(); canvas = Image.FromStream(ms); } catch (FileNotFoundException) { Size monitorSize = SystemInformation.PrimaryMonitorSize; canvas = new Bitmap(monitorSize.Width, monitorSize.Height); } canvasOut.Send(canvas); PinOut <Image> ljSrcOut = new PinOut <Image>(); ljSrcOut.AttachTo(redditSource.InputPin); ljSrcOut.Send(null); /* only need a signal to kick off the source */ ljSrcOut.Send(null); /* put two images in the loop to test multithreading */ //ljSrcOut.Send(null); /* hell, why not three? */ //ljSrcOut.Send(null); /* we are approaching levels of insanity heretofore untold */ Console.ReadLine(); }
public void Receive(PinIn <Image> pin, Image img) { /* choose an angle */ double angle = minAngle + (maxAngle - minAngle) * random.NextDouble(); double angleRadians = -angle * Math.PI / 180; /* * * /* figure out new width and height as well as appropriate place to put rotated image */ double s = Math.Sin(angleRadians); double c = Math.Cos(angleRadians); double newWidth = img.Width * Math.Abs(c) + img.Height * Math.Abs(s); double newHeight = img.Height * Math.Abs(c) + img.Width * Math.Abs(s); double minX = Math.Min(0, Math.Min(c * img.Width, Math.Min(s * img.Height, c * img.Width + s * img.Height))); double minY = Math.Min(0, Math.Min(-s * img.Width, Math.Min(c * img.Height, c * img.Height - s * img.Width))); /* create the rotated image */ Graphics gOld = Graphics.FromImage(img); Image outImage = new Bitmap(1 + (int)newWidth, 1 + (int)newHeight, gOld); gOld.Dispose(); Graphics g = Graphics.FromImage(outImage); g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TranslateTransform(-(float)minX + 1, -(float)minY + 1); g.RotateTransform((float)angle); g.DrawImage(img, 0, 0); g.Dispose(); OutputPin.Send(outImage); }
public void Receive(PinIn <Image> pin, Image img) { lock (this) { dff.SetPicture(img); } OutputPin.Send(img); }
//static void Main(string[] args) //{ // //GameOfLifeSource golSrc = new GameOfLifeSource(1680, 1050); // GameOfLifeSource golSrc = new GameOfLifeSource(840, 525); // 1680 x 1050 / 2 // //GameOfLifeSource golSrc = new GameOfLifeSource(560, 350); // 1680 x 1050 / 3 // //GameOfLifeSource golSrc = new GameOfLifeSource(336, 210); // 1680 x 1050 / 5 // GenericDelay<Image> delayFilt = new GenericDelay<Image>(new TimeSpan(0, 0, 0, 0, 100)); // //WallpaperFilter wpFilt = new WallpaperFilter(); // DisplayFilter displayFilt = new DisplayFilter(); // golSrc.OutputPin.AttachTo(delayFilt.InputPin); // delayFilt.OutputPin.AttachTo(displayFilt.InputPin); // displayFilt.OutputPin.AttachTo(golSrc.InputPin); // PinOut<Image> golSrcOut = new PinOut<Image>(); // golSrcOut.AttachTo(golSrc.InputPin); // golSrcOut.Send(null); // //golSrcOut.Send(null); // //golSrcOut.Send(null); // //golSrcOut.Send(null); // Console.ReadLine(); //} static void Main(string[] args) { RedditSource redditSource = new RedditSource("http://www.reddit.com/r/pics/.json"); GenericFilter<Image> sizeFilt = new GenericFilter<Image>(img => 100 < img.Width && img.Width < 1000 && 100 < img.Height && img.Height < 800); BorderFilter brdInnerFilt = new BorderFilter(Color.Black, 1); BorderFilter brdOuterFilt = new BorderFilter(Color.White, 9); RotateFilter rotFilt = new RotateFilter(-30, 30); CanvasFilter cvsFilt = new CanvasFilter(); GenericDelay<Image> delayFilt = new GenericDelay<Image>(new TimeSpan(0, 0, 30)); WallpaperFilter wpFilt = new WallpaperFilter(); redditSource.OutputPin.AttachTo(sizeFilt.InputPin); sizeFilt.SuccessPin.AttachTo(brdInnerFilt.InputPin); sizeFilt.FailurePin.AttachTo(redditSource.InputPin); brdInnerFilt.OutputPin.AttachTo(brdOuterFilt.InputPin); brdOuterFilt.OutputPin.AttachTo(rotFilt.InputPin); rotFilt.OutputPin.AttachTo(cvsFilt.PictureInputPin); cvsFilt.OutputPin.AttachTo(delayFilt.InputPin); cvsFilt.OutputPin.AttachTo(cvsFilt.CanvasInputPin); delayFilt.OutputPin.AttachTo(wpFilt.InputPin); wpFilt.OutputPin.AttachTo(redditSource.InputPin); /* prime canvas */ PinOut<Image> canvasOut = new PinOut<Image>(); canvasOut.AttachTo(cvsFilt.CanvasInputPin); Image canvas; try { int bytesRead; byte[] buf = new byte[1024]; FileStream fs = new FileStream(Path.Combine(Environment.CurrentDirectory, "wall.bmp"), FileMode.Open); MemoryStream ms = new MemoryStream(); while ((bytesRead = fs.Read(buf, 0, 1024)) > 0) ms.Write(buf, 0, bytesRead); ms.Seek(0, SeekOrigin.Begin); fs.Close(); canvas = Image.FromStream(ms); } catch (FileNotFoundException) { Size monitorSize = SystemInformation.PrimaryMonitorSize; canvas = new Bitmap(monitorSize.Width, monitorSize.Height); } canvasOut.Send(canvas); PinOut<Image> ljSrcOut = new PinOut<Image>(); ljSrcOut.AttachTo(redditSource.InputPin); ljSrcOut.Send(null); /* only need a signal to kick off the source */ ljSrcOut.Send(null); /* put two images in the loop to test multithreading */ //ljSrcOut.Send(null); /* hell, why not three? */ //ljSrcOut.Send(null); /* we are approaching levels of insanity heretofore untold */ Console.ReadLine(); }
public void Receive(PinIn <Image> pin, Image img) { Graphics gOld = Graphics.FromImage(img); Bitmap outImage = new Bitmap(img.Width + 2 * borderSize, img.Height + 2 * borderSize, gOld); gOld.Dispose(); Graphics g = Graphics.FromImage(outImage); g.Clear(borderColor); g.DrawImage(img, new Point(borderSize, borderSize)); g.Dispose(); OutputPin.Send(outImage); }
public void Receive(PinIn <Image> pin, Image img) { string wallName = Path.Combine(Environment.CurrentDirectory, "wall.bmp"); lock (this) { FileStream wallStream = new FileStream(wallName, FileMode.OpenOrCreate); img.Save(wallStream, ImageFormat.Bmp); wallStream.Close(); SetWallpaper(wallName); } OutputPin.Send(img); }
public void Receive(PinIn <Image> pin, Image item) { bool timeToOutput = false; Image myPic = null; Image myCanvas = null; lock (this) { if (pin == PictureInputPin) { pic = item; } if (pin == CanvasInputPin) { canvas = item; } if (pic != null && pin != null) { timeToOutput = true; myPic = pic; myCanvas = canvas; pic = null; canvas = null; } } if (timeToOutput) { Graphics g = Graphics.FromImage(myCanvas); double X = myCanvas.Width * random.NextDouble() - myPic.Width / 2; /* [-pic.width/2, canvas.width - pic.width/2] */ double Y = myCanvas.Height * random.NextDouble() - myPic.Height / 2; /* ditto but for height */ g.DrawImage(myPic, (float)X, (float)Y); g.Dispose(); OutputPin.Send(myCanvas); } }
public void Receive(PinIn <T> pin, T item) { TimeSpan delay; lock (this) { delay = next - DateTime.Now; if (next < DateTime.Now) { next = DateTime.Now + interval; } else { next = next + interval; } } if (delay.TotalSeconds > 0) { Thread.Sleep(delay); } OutputPin.Send(item); }
public void Receive(PinIn <T> pin, T item) { PinOut <T> outPin = filterFunction(item) ? SuccessPin : FailurePin; outPin.Send(item); }
public void Receive(PinIn <T> pin, T item) { OutputPin.Send(transformFunction(item)); }