Esempio n. 1
0
        public async Task SmearAsync(PaletteType a, PaletteType b)
        {
            GammaPalette result = GammaPalette.Smear(GraphicsService.GetPalette(a), GraphicsService.GetPalette(b));

            await Context.Channel.SendImageAsync(ImageHelper.CreateGradient(result, 128, 64, AngleF.Right),
                                                 "../tmp/smear.png");
        }
Esempio n. 2
0
        public async Task RunLifeAsync(int width, int height, int duration, int delay = 100)
        {
            string               path      = $"../tmp/{Context.User.Id}_cgol.gif";
            GammaPalette         colors    = GammaPalette.Glass;
            Grid <ConwayCell>    pattern   = ConwayRenderer.GetRandomPattern(width, height);
            ConwayRenderer       simulator = new ConwayRenderer(colors[Gamma.Max], colors[Gamma.Min], null, pattern);
            List <Grid <Color> > rawFrames = simulator.Run(duration);

            MemoryStream gifStream = new MemoryStream();

            using (GifEncoder encoder = new GifEncoder(gifStream))
            {
                List <Bitmap> frames = rawFrames.Select(f => ImageHelper.CreateRgbBitmap(f.Values)).ToList();
                encoder.FrameLength = TimeSpan.FromMilliseconds(delay);

                foreach (Bitmap frame in frames)
                {
                    using (frame)
                        encoder.EncodeFrame(frame);
                }
            }

            gifStream.Position = 0;
            Image gifResult = Image.FromStream(gifStream);

            gifResult.Save(path, ImageFormat.Gif);
            await gifStream.DisposeAsync();

            await Context.Channel.SendFileAsync(path);
        }
Esempio n. 3
0
 public GammaPalette Build()
 {
     if (Secondary.HasValue)
     {
         return(Method switch
         {
             PaletteMixMethod.Merge => GammaPalette.Merge(GraphicsService.GetPalette(Primary), GraphicsService.GetPalette(Secondary.Value), 0.5f),
             _ => GammaPalette.Smear(GraphicsService.GetPalette(Primary), GraphicsService.GetPalette(Secondary.Value))
         });
Esempio n. 4
0
        public async Task CycleTimeAsync(int framesPerHour = 1, int delay = 150, int?loop = null)
        {
            string   path = $"../tmp/{Context.User.Id}_time.gif";
            FontFace font = JsonHandler.Load <FontFace>(@"../assets/fonts/orikos.json");

            char[][][][] charMap = JsonHandler.Load <char[][][][]>(@"../assets/char_map.json", new JsonCharArrayConverter());
            var          config  = TextFactoryConfig.Default;

            config.CharMap = charMap;

            var frames     = new List <Stream>();
            var properties = new ImageProperties
            {
                TrimEmptyPixels = true,
                Padding         = new Padding(2),
                Width           = 47
            };

            float t = 0.00f;

            using (var factory = new TextFactory(config))
            {
                factory.SetFont(font);

                for (float h = 0; h < 24 * framesPerHour; h++)
                {
                    GammaPalette colors = TimeCycle.FromHour(t);
                    properties.Matte = colors[Gamma.Min];

                    frames.Add(DrawFrame(factory, t.ToString("00.00H"), colors[Gamma.Max], properties));

                    t += (1.00f / framesPerHour);
                }
            }

            var gifStream = new MemoryStream();

            using (var encoder = new GifEncoder(gifStream, repeatCount: loop))
            {
                encoder.FrameLength = TimeSpan.FromMilliseconds(delay);

                foreach (Stream frame in frames)
                {
                    await using (frame)
                        encoder.EncodeFrame(Image.FromStream(frame));
                }
            }

            gifStream.Position = 0;
            Image gifResult = Image.FromStream(gifStream);

            gifResult.Save(path, ImageFormat.Gif);
            await gifStream.DisposeAsync();

            await Context.Channel.SendFileAsync(path);
        }
Esempio n. 5
0
        public static Bitmap DrawMap(string id, HuskBrain brain, GammaPalette palette)
        {
            Map          map    = GetMap(id, brain);
            var          result = new Drawable(map.Source.Width, map.Source.Height);
            Grid <Color> mask   = CreateMapMask(map.Progression, Color.Transparent, GammaPalette.Default[Gamma.Min]);

            result.Palette = palette;
            result.AddLayer(new BitmapLayer(ImageHelper.CreateArgbBitmap(mask.Values)));

            return(result.BuildAndDispose());
        }
Esempio n. 6
0
        public async Task RunLifeDecayAsync(int width, int height, int duration, ulong decayLength, int delay = 100)
        {// int width, int height,
            string            path    = $"../tmp/{Context.User.Id}_cgol.gif";
            GammaPalette      colors  = GammaPalette.Alconia;
            Grid <ConwayCell> pattern = ConwayRenderer.GetRandomPattern(width, height);
            var simulator             = new ConwayRenderer(GammaPalette.GammaGreen[Gamma.Standard], colors[Gamma.Min], decayLength, pattern);

            simulator.ActiveColor = GammaPalette.GammaGreen[Gamma.Max];
            List <Grid <Color> > rawFrames = simulator.Run(duration);

            await SendGifAsync(path, rawFrames, delay);
        }
Esempio n. 7
0
        public async Task GetTimeAsync()
        {
            try
            {
                string       path    = $"../tmp/{Context.User.Id}_time.png";
                GammaPalette palette = TimeCycle.FromUtcNow();

                using var graphics = new GraphicsService();
                Bitmap bmp = graphics.DrawText(DateTime.UtcNow.ToString("hh:mm tt").ToUpper(), Gamma.Max, palette);
                await Context.Channel.SendImageAsync(bmp, path);
            }
            catch (Exception ex)
            {
                await Context.Channel.CatchAsync(ex);
            }
        }
Esempio n. 8
0
        public static GammaPalette FromHour(float hour) // TODO: Incorporate offsets, and incorporate Range.Markers (when ready).
        {
            TimeCycle cycle = Utc;

            if (hour <= cycle.NightEnd || hour > cycle.NightStart)
            {
                return(NightPalette);
            }

            if (hour > cycle.NightEnd && hour <= cycle.Dawn)
            {
                return(GammaPalette.Merge(NightPalette, SunrisePalette, GetHourStrength(cycle.NightEnd, cycle.Dawn, hour)));
            }

            if (hour > cycle.Dawn && hour <= cycle.Sunrise)
            {
                return(GammaPalette.Merge(SunrisePalette, DuskPalette, GetHourStrength(cycle.Dawn, cycle.Sunrise, hour)));
            }

            if (hour > cycle.Sunrise && hour <= cycle.Meridian)
            {
                return(GammaPalette.Merge(DuskPalette, MeridianPalette, GetHourStrength(cycle.Sunrise, cycle.Meridian, hour)));
            }

            if (hour > cycle.Meridian && hour <= cycle.Sunset)
            {
                return(GammaPalette.Merge(MeridianPalette, DuskPalette, GetHourStrength(cycle.Meridian, cycle.Sunset, hour)));
            }

            if (hour > cycle.Sunset && hour <= cycle.Dusk)
            {
                return(GammaPalette.Merge(DuskPalette, SunrisePalette, GetHourStrength(cycle.Sunset, cycle.Dusk, hour)));
            }

            if (hour > cycle.Dusk && hour <= cycle.NightStart)
            {
                return(GammaPalette.Merge(SunrisePalette, NightPalette, GetHourStrength(cycle.Dusk, cycle.NightStart, hour)));
            }

            throw new Exception("The hour float value given is out of range.");
        }
Esempio n. 9
0
        public async Task GetTimeAsync(float hour)
        {
            if (hour > 23.00f || hour < 0.00f)
            {
                await Context.Channel.SendMessageAsync("hour out of range");

                return;
            }

            try
            {
                string path = $"../tmp/{Context.User.Id}_time.png";
                var    font = JsonHandler.Load <FontFace>(@"../assets/fonts/orikos.json");
                // new OutlineProperties(1, new OriColor(0x44B29B)): Too taxing on performance as of now
                char[][][][] charMap = JsonHandler.Load <char[][][][]>(@"../assets/char_map.json", new JsonCharArrayConverter());
                GammaPalette colors  = TimeCycle.FromHour(hour);
                var          config  = TextFactoryConfig.Default;
                config.CharMap = charMap;
                var properties = new ImageProperties
                {
                    TrimEmptyPixels = true,
                    Padding         = new Padding(2),
                    Matte           = colors[Gamma.Min]
                };

                using (var factory = new TextFactory(config))
                    using (Bitmap bmp = factory.DrawText(hour.ToString("00.00H").ToUpper(), font, properties))
                        ImageHelper.Save(bmp, path, ImageFormat.Png);

                await Context.Channel.SendFileAsync(path);
            }
            catch (Exception ex)
            {
                await Context.Channel.CatchAsync(ex);
            }
        }
Esempio n. 10
0
        // TODO: Move to GraphicsHandler
        public Bitmap Render(DialogTone tone, GammaPalette palette)
        {
            Bitmap result = new Bitmap(72, 64);

            using (Graphics g = Graphics.FromImage(result))
            {
                // replace this with the interior images provided from a Location.
                using (Bitmap bg = new Bitmap("../assets/npcs/npc_frame.png"))
                    ImageHelper.ClipAndDrawImage(g, bg, new Point(0, 0));

                using (Bitmap body = Body.Value.GetImage())
                    ImageHelper.ClipAndDrawImage(g, body, Body.GetOffset());

                using (Bitmap head = Head.Value.GetImage())
                    ImageHelper.ClipAndDrawImage(g, head, Head.GetOffset());

                using (Bitmap face = GetReactionOrDefault(tone).Value.GetImage())
                    ImageHelper.ClipAndDrawImage(g, face, DefaultFaceOffset);
            }

            result = ImageHelper.SetColorMap(result, GammaPalette.Default, palette);
            result = ImageHelper.Scale(result, 2, 2);
            return(result);
        }