コード例 #1
0
        protected virtual void OnColorChanged(bool hsvToRgb)
        {
            _updating = true;

            if (hsvToRgb)
            {
                _rgba   = (ARGBPixel)_hsv;
                _rgba.A = (byte)numA.Value;
            }
            else
            {
                _hsv = (HSVPixel)_rgba;
            }

            numH.Value = _hsv.H;
            numS.Value = _hsv.S;
            numV.Value = _hsv.V;
            numR.Value = _rgba.R;
            numG.Value = _rgba.G;
            numB.Value = _rgba.B;
            numA.Value = _rgba.A;

            txtColorCode.Text = _rgba.ToRGBAColorCode();

            _updating = false;

            pnlColorBox.Invalidate();
            pnlColorBar.Invalidate();

            if (ColorChanged != null)
            {
                ColorChanged(this, null);
            }
        }
コード例 #2
0
        public Task <RGBPixel[, ]> GenPattern(ulong frame)
        {
            // Male nächste Iteration ins malbild.
            ulong schritt = frame % 100;
            float f       = schritt / 100f;

            // Bild mit modulo wiederholen (immer Quadratisch)
            int d = _startbild.GetLength(0);

            // Recycle deinen Puffer und übertrage das Bild dahin.
            for (int x = 0; x < sizex; x++)
            {
                for (int y = 0; y < sizey; y++)
                {
                    var pxl = (_zielbild[x % d, y % d] * (f)) + _startbild[x % d, y % d] * (1.0f - f);
                    pbuf[x, y] = new HSVPixel(pxl, 1, 1);
                }
            }

            // Wechsle Bilder durch alle x frames
            if (schritt == 0)
            {
                _startbild = _zielbild;
                _zielbild  = DiamondBrick(N);
            }

            return(Task.FromResult(pbuf));
        }
コード例 #3
0
        protected void OnBoxChanged(object sender, EventArgs e)
        {
            if (_updating)
            {
                return;
            }

            NumericUpDown box   = sender as NumericUpDown;
            int           value = (int)box.Value;
            int           index = (int)box.Tag;

            switch (index)
            {
            case 0: { _hsv.H = (ushort)value; break; }

            case 1: { _hsv.S = (byte)value; break; }

            case 2: { _hsv.V = (byte)value; break; }

            case 3: { _rgb.R = (byte)value; break; }

            case 4: { _rgb.G = (byte)value; break; }

            case 5: { _rgb.B = (byte)value; break; }

            case 6: { pnlAlpha.Invalidate(); break; }
            }

            if ((index > 2) && (index < 6))
            {
                _hsv = (HSVPixel)_rgb;
            }

            OnColorChanged();
        }
コード例 #4
0
        private void huePanel_Paint(object sender, PaintEventArgs e)
        {
            const float numHueColors = 6.0f;

            Rectangle r = colorSquare.ClientRectangle;

            //Draw the hue slider
            var g = e.Graphics;

            //Split the hue colors
            float p = r.Height / numHueColors / r.Height;

            _hueBrush = new LinearGradientBrush(new Rectangle(0, 0, r.Width, r.Height), Color.Red, Color.Red, LinearGradientMode.Vertical);

            //Create the hue list
            ColorBlend blend = new ColorBlend();

            blend.Colors = new Color[]
            {
                Color.Red,
                Color.Yellow,
                Color.Lime,
                Color.Cyan,
                Color.Blue,
                Color.Magenta,
                Color.Red
            };

            if (!huePanel.Enabled)
            {
                for (int i = 0; i < blend.Colors.Length; i++)
                {
                    blend.Colors[i] = blend.Colors[i].Darken(190);
                }
            }

            blend.Positions = new float[] { 0, p, p * 2, p * 3, p * 4, p * 5, 1.0f };
            _hueBrush.InterpolationColors = blend;



            g.FillRectangle(_hueBrush, r);

            Color pixel = new HSVPixel(_hsv.H, 100, 100).ToRGBA().Inverse();

            int       y = (int)(_hsv.H / 360.0f * (huePanel.Height - 1));
            Rectangle c = new Rectangle(-1, y - 2, huePanel.Width + 1, 4);

            using (Pen pen = new Pen(pixel))
                g.DrawRectangle(pen, c);

            c.Y      += 1;
            c.Height -= 2;
            pixel     = pixel.Lighten(64);

            using (Pen pen = new Pen(pixel))
                g.DrawRectangle(pen, c);
        }
コード例 #5
0
        private void colorSquare_Paint(object sender, PaintEventArgs e)
        {
            var g = e.Graphics;

            Rectangle r = colorSquare.ClientRectangle;
            float     p = r.Height / 6.0f / r.Height;

            _mainBrush = new PathGradientBrush(new PointF[] {
                new PointF(r.Width, 0),
                new PointF(r.Width, r.Height),
                new PointF(0, r.Height),
                new PointF(0, 0),
                new PointF(r.Width, 0)
            });

            _boxColors[0]             = _boxColors[4] = new HSVPixel(_hsv.H, 100, 100).ToRGBA();
            _mainBrush.SurroundColors = _boxColors;
            _mainBrush.CenterColor    = new HSVPixel(_hsv.H, 50, 50).ToRGBA();
            _mainBrush.CenterPoint    = new PointF(r.Width / 2, r.Height / 2);

            if (!huePanel.Enabled)
            {
                for (int i = 0; i < _mainBrush.SurroundColors.Length; i++)
                {
                    _mainBrush.SurroundColors[i] = _mainBrush.SurroundColors[i].Darken(190);
                }
            }

            g.FillRectangle(_mainBrush, r);


            //Draw indicator
            int x = (int)(_hsv.V / 100.0f * colorSquare.Width);
            int y = (int)((100 - _hsv.S) / 100.0f * colorSquare.Height);

            Rectangle c = new Rectangle(x - 3, y - 3, 6, 6);

            Color pixel = _color.Inverse();

            pixel.WhiteAlpha();

            using (Pen pen = new Pen(pixel))
                g.DrawEllipse(pen, c);

            c.X      -= 1;
            c.Y      -= 1;
            c.Width  += 2;
            c.Height += 2;

            pixel = pixel.Lighten(64);

            using (Pen pen = new Pen(pixel))
                g.DrawEllipse(pen, c);
        }
コード例 #6
0
        public void Farbtests()
        {
            RGBPixel schwarz = RGBPixel.P0;
            RGBPixel weiß    = RGBPixel.P1;
            RGBPixel braun   = new RGBPixel(.36f, .18f, .09f);
            RGBPixel blau    = new RGBPixel(0, 0, 1);
            RGBPixel rot     = new RGBPixel(1, 0, 0);
            RGBPixel grün    = new RGBPixel(0, 1, 0);
            RGBPixel magenta = new RGBPixel(1, 0, 1);
            RGBPixel cyan    = new RGBPixel(0, 1, 1);
            RGBPixel orange  = new RGBPixel(1, .5f, 0);
            RGBPixel violett = new RGBPixel(.5f, 0, 1);
            RGBPixel zinober = new RGBPixel(1, 0.25f, 0);
            RGBPixel safran  = new RGBPixel(1, 0.75f, 0);

            HSVPixel schwarz1 = HSVPixel.P0;
            HSVPixel weiß1    = new HSVPixel(0, 0, 1);
            HSVPixel braun1   = new HSVPixel(20, 0.75f, 0.36f);
            HSVPixel blau1    = new HSVPixel(240, 1, 1);
            HSVPixel rot1     = new HSVPixel(0, 1, 1);
            HSVPixel grün1    = new HSVPixel(120, 1, 1);
            HSVPixel magenta1 = new HSVPixel(300, 1, 1);
            HSVPixel cyan1    = new HSVPixel(180, 1, 1);
            HSVPixel orange1  = new HSVPixel(30, 1, 1);
            HSVPixel violett1 = new HSVPixel(270, 1, 1);
            HSVPixel zinober1 = new HSVPixel(15, 1, 1);
            HSVPixel safran1  = new HSVPixel(45, 1, 1);

            Assert.Equal(schwarz1.V, HSVPixel.FromRGB(schwarz).V);
            Assert.Equal(schwarz, (RGBPixel)schwarz1);
            Assert.Equal(weiß1.V, HSVPixel.FromRGB(weiß).V);
            Assert.Equal(weiß1.S, HSVPixel.FromRGB(weiß).S);
            Assert.Equal(weiß, (RGBPixel)weiß1);
            Assert.Equal(braun1, HSVPixel.FromRGB(braun));
            Assert.Equal(braun, (RGBPixel)braun1);
            Assert.Equal(blau1, HSVPixel.FromRGB(blau));
            Assert.Equal(blau, (RGBPixel)blau1);
            Assert.Equal(rot1, HSVPixel.FromRGB(rot));
            Assert.Equal(rot, (RGBPixel)rot1);
            Assert.Equal(grün1, HSVPixel.FromRGB(grün));
            Assert.Equal(grün, (RGBPixel)grün1);
            Assert.Equal(magenta1, HSVPixel.FromRGB(magenta));
            Assert.Equal(magenta, (RGBPixel)magenta1);
            Assert.Equal(cyan1, HSVPixel.FromRGB(cyan));
            Assert.Equal(cyan, (RGBPixel)cyan1);
            Assert.Equal(orange1, HSVPixel.FromRGB(orange));
            Assert.Equal(orange, (RGBPixel)orange1);
            Assert.Equal(violett1, HSVPixel.FromRGB(violett));
            Assert.Equal(violett, (RGBPixel)violett1);
            Assert.Equal(zinober1, HSVPixel.FromRGB(zinober));
            Assert.Equal(zinober, (RGBPixel)zinober1);
            Assert.Equal(safran1, HSVPixel.FromRGB(safran));
            Assert.Equal(safran, (RGBPixel)safran1);
        }
コード例 #7
0
        public void Grautests()
        {
            var px1 = new HSVPixel(32, 1, 0.4f);

            Assert.Equal(new HSVPixel(32, 0, 0.4f), px1.Grau());
            var px2 = new HSVPixel(75, 1, 0);

            Assert.Equal(new HSVPixel(75, 0, 0), px2.Grau());
            var px3 = new HSVPixel(0, 1, 1.4f);

            Assert.Equal(new HSVPixel(0, 0, 1.4f), px3.Grau());
        }
コード例 #8
0
        public Task <RGBPixel[, ]> Filter(RGBPixel[,] pixels, ulong frame)
        {
            (int w, int h) = pixels.EnsureArray2D(ref _res);
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    HSVPixel hsv = pixels[x, y];
                    _res[x, y] = hsv.Grau();
                }
            }

            return(Task.FromResult(_res));
        }
コード例 #9
0
        protected virtual void OnColorChanged(bool hsvToRgb)
        {
            colorSquare.Invalidate();
            huePanel.Invalidate();

            if (hsvToRgb)
            {
                _color = _hsv.ToRGBA();
            }
            else
            {
                _hsv = HSVPixel.FromRGBA(_color);
            }

            if (ColorChanged != null)
            {
                ColorChanged(this, null);
            }
        }
コード例 #10
0
ファイル: Feuer.cs プロジェクト: Robertofon/LEDerZaumzeug
        /// <summary>
        /// Algorithmus verwendet keine Partikeltechnik.
        /// Stattdessen wird einfach nur in der untersten Y-Zeile mit random
        /// verschiedene Rot+Gelbtöne gezündelt. Diese werden dann von oben her
        /// nach oben vererbt und ausgeblendet mit f*f, f&lt;1.
        /// </summary>
        public Task <RGBPixel[, ]> GenPattern(ulong frame)
        {
            // Vererbe alle Zeilen von oben kommend eins hoch mal Ausblendfaktor
            for (int x = 0; x < sizex; x++)
            {
                for (int y = 0; y < sizey - 1; y++)
                {
                    pbuf[x, y] = pbuf[x, y + 1] * _f;
                }
            }

            // Jetzt unterste Zeile neu befeuern:
            for (int x = 0; x < sizex; x++)
            {
                // nehme die farben rot (0°) bis gelb (60°) und intensitäten 0.3-1
                pbuf[x, sizey - 1] = new HSVPixel((float)rnd.NextDouble() * 60f, 1, (float)rnd.NextDouble() * .3f + .7f);
            }

            return(Task.FromResult(pbuf));
        }
コード例 #11
0
        public Task <RGBPixel[, ]> GenPattern(ulong frame)
        {
            // Recycle deinen Puffer
            // Winkel berechnen in rad
            double wr    = (this.Winkel + (frame * this.RotRate)) / 180d * Math.PI;
            double sinwr = Math.Sin(wr);
            double coswr = Math.Cos(wr);

            for (int x = 0; x < sizex; x++)
            {
                for (int y = 0; y < sizey; y++)
                {
                    float fb = (frame * Geschwindigkeit) +
                               ((float)(y * sinwr + x * coswr) * 360f / Lambda);
                    pbuf[x, y] = new HSVPixel(fb, .9f, .9f);
                }
            }

            return(Task.FromResult(pbuf));
        }
コード例 #12
0
ファイル: Linien.cs プロジェクト: Robertofon/LEDerZaumzeug
        public Task <RGBPixel[, ]> GenPattern(ulong frame)
        {
            Color fb = this.Farbe;

            // Male nächste Iteration ins malbild.

            switch (this.Art)
            {
            case LinienTyp.Kreuz:
            {
                ulong  w  = (ulong)(frame * Geschwindigkeit) % 100;
                double wr = w / 100d * Math.PI;
                double ph = 2 * Math.PI / Anzahl;
                PointF mp = new PointF(sizex / 2f, sizey / 2f);
                _malbild.Mutate((IImageProcessingContext i) =>
                    {
                        try
                        {
                            i.Fill(Color.Black);
                            for (int l = 0; l < this.Anzahl; l++)
                            {
                                PointF pointF = new PointF(mp.X + (float)Math.Cos(wr + ph * l) * sizex, mp.Y + (float)Math.Sin(wr + ph * l) * sizey);
                                i.DrawLines(new ShapeGraphicsOptions()
                                {
                                    GraphicsOptions = { Antialias = false }
                                }, fb, this.N,
                                            mp, pointF);
                            }
                        }
                        catch (Exception e)
                        {
                            //HACK, TODO, geht nicht, wegen Bug in Bib.
                        }
                    });
            }
            break;

            case LinienTyp.Raute:
            {
                float w = 0.01f * ((ulong)(frame * Geschwindigkeit) % 100);
                _malbild.Mutate(i =>
                    {
                        i.Clear(Color.Black);
                        i.DrawLines(new ShapeGraphicsOptions()
                        {
                            GraphicsOptions = { Antialias = false }
                        }, fb, this.N,
                                    new PointF(sizex * w, 0),
                                    new PointF(sizex, sizey * w),
                                    new PointF(sizex * (1 - w), sizey),
                                    new PointF(0, sizey * (1 - w)),
                                    new PointF(sizex * w, 0));
                    });
            }
            break;

            default:
            case LinienTyp.RadarLR:
            case LinienTyp.RadarRL:
            {
                ulong koo = (ulong)(frame * Geschwindigkeit) % sizex;
                koo = (this.Art == LinienTyp.RadarRL)? sizex - koo - 1 : koo;
                _malbild.Mutate(i =>
                    {
                        i.Clear(Color.Black);
                        i.DrawLines(new ShapeGraphicsOptions()
                        {
                            GraphicsOptions = { Antialias = false }
                        },
                                    fb, this.N, new PointF((float)koo, 0), new PointF((float)koo, sizey - 1));
                    });
            }
            break;

            case LinienTyp.RadarRLR:
            {
                ulong koo = (ulong)(frame * Geschwindigkeit) % (sizex * 2);
                koo = (koo >= sizex)? sizex - (koo % sizex) - 1 : koo % sizex;
                ILineSegment s = new LinearLineSegment(new PointF((float)koo, 0), new PointF((float)koo, sizey - 1));
                IPath        p = new SixLabors.ImageSharp.Drawing.Path(s);
                _malbild.Mutate(i =>
                    {
                        i.Clear(Color.Black);
                        i.Draw(new ShapeGraphicsOptions()
                        {
                            GraphicsOptions = { Antialias = false }
                        },
                               fb, N, p);
                    });
            }
            break;

            case LinienTyp.RadarVO:
            case LinienTyp.RadarOV:
            case LinienTyp.RadarVOV:
                throw new NotImplementedException();
                break;
            }
            // Recycle deinen Puffer und übertrage das Bild dahin.
            for (int x = 0; x < sizex; x++)
            {
                for (int y = 0; y < sizey; y++)
                {
                    var pxl = _malbild[x, y];
                    pbuf[x, y] = new RGBPixel(pxl.R, pxl.G, pxl.B);
                }
            }

            if (this.Farbwechsel)
            {
                HSVPixel h = this.Farbe;
                h.H       += 1;
                this.Farbe = h;
            }
            return(Task.FromResult(pbuf));
        }