Пример #1
0
        public Bitmap Draw(ResistorStyle style)
        {
            List <Bitmap> resistors = Resistors.Select(x => x.Draw(style)).ToList();

            Bitmap bitmap = new Bitmap(resistors.Max(x => x.Width) + style.WireLength * 2, resistors.Sum(x => x.Height + style.WireLength) - style.WireLength, PixelFormat.Format32bppArgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.FillRectangle(new SolidBrush(style.BackColor), 0, 0, bitmap.Width, bitmap.Height);

                int sum = 0;

                Pen pen = new Pen(new SolidBrush(style.WireColor), style.WireThickness);

                resistors.ForEach(res =>
                {
                    g.DrawLine(pen, 0, sum + res.Height / 2, bitmap.Width - style.WireLength - style.WireThickness, sum + res.Height / 2);
                    g.DrawImage(res, (bitmap.Width - res.Width) / 2, sum);
                    sum += res.Height + style.WireLength;
                });

                g.DrawLine(pen, 0, resistors[0].Height / 2, 0, sum - style.WireLength - resistors.Last().Height / 2);
                g.DrawLine(pen, bitmap.Width - style.WireLength - style.WireThickness, resistors[0].Height / 2, bitmap.Width - style.WireLength - style.WireThickness, sum - style.WireLength - resistors.Last().Height / 2);
                g.DrawLine(pen, bitmap.Width - style.WireThickness, bitmap.Height / 2, bitmap.Width - style.WireLength - style.WireThickness, sum - style.WireLength - bitmap.Height / 2);
            }

            return(bitmap);
        }
Пример #2
0
        public Bitmap Draw(ResistorStyle style)
        {
            List <Bitmap> resistors = Resistors.Select(x => x.Draw(style)).ToList();

            Bitmap bitmap = new Bitmap(resistors.Sum(x => x.Width), resistors.Max(x => x.Height), PixelFormat.Format32bppArgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.FillRectangle(new SolidBrush(style.BackColor), 0, 0, bitmap.Width, bitmap.Height);

                int sum = 0;

                resistors.ForEach(res =>
                {
                    g.DrawImage(res, sum, (bitmap.Height - res.Height) / 2);
                    sum += res.Width;
                });
            }

            return(bitmap);
        }
Пример #3
0
 public object Clone() => new ParallelResistor
 {
     Resistors = Resistors.Select(x => (IResistor)x.Clone()).ToList()
 };