Пример #1
0
        public void CreateBuffer()
        {
            Body = new DigitalComponent(Shader)
            {
                PinsCount = 1,
                Delta     = Delta,
                Position  = new Vector2(X, Y)
            };
            Body.CreateBuffer();

            for (int i = 0; i < Word.Length; i++)
            {
                var letter = Word[i];
                var glyph  = new Glyph7x5(letter, new Vector2(X + Delta * (2 + i), Y + Delta * 0.4f), Shader);
                GlyphWord.Add(glyph);
            }
            MemoryGlyph = new Glyph7x5('0', new Vector2(X + Delta * 2.5f, Y + Delta * 2.0f), Shader);

            Visuals.Add(MemoryGlyph);
            Visuals.Add(Body);
            Visuals.AddRange(GlyphWord);
        }
Пример #2
0
        public MatrixToVisual(bool[,] matrix, SimpleShader simpleShader)
        {
            Matrix = matrix;
            int icount = matrix.GetLength(0);
            int jcount = matrix.GetLength(1);

            WiresInputs  = new Wire[icount];
            WiresOutputs = new Wire[jcount];
            DigitalComponent[] logicalXors = new DigitalComponent[jcount];

            InOutPins = new DrawingVisual(simpleShader);

            var delta     = 10;
            var x0        = delta * 5;
            var y0        = delta * 5;
            var bigStep   = delta * 4;
            var xRight    = x0 + 60 * delta;
            var circleR   = delta;
            var xLineLeft = x0 + circleR;

            InOutPins.Shape = Round(Vector2.Zero, circleR, 4.0f, 50);



            for (int i = 0; i < icount; i++)
            {
                WiresInputs[i]             = new Wire(simpleShader);
                WiresInputs[i].Thickness   = 2.0f;
                WiresInputs[i].PointRadius = 3.0f;
            }

            float xBase = xLineLeft;

            var pinsCounts = new int[jcount];

            for (int i = 0; i < icount; i++)
            {
                for (int j = 0; j < jcount; j++)
                {
                    if (matrix[i, j])
                    {
                        pinsCounts[j]++;
                    }
                }
            }



            for (int j = 0; j < jcount; j++)
            {
                float xorX = xBase + delta * pinsCounts[j] * 2 + delta;

                int pinNum = 0;

                logicalXors[j] = new DigitalComponent(simpleShader);

                var rectHalfHeight = pinsCounts[j] * delta;

                //logicalXors[j].X = xorX;

                logicalXors[j].Delta     = delta;
                logicalXors[j].PinsCount = pinsCounts[j];
                logicalXors[j].CreateBuffer();

                xBase = xorX + logicalXors[j].Width;

                WiresOutputs[j]             = new Wire(simpleShader);
                WiresOutputs[j].Color       = Color4.Red;
                WiresOutputs[j].Thickness   = 2.0f;
                WiresOutputs[j].PointRadius = 3.0f;
                // WiresOutputs[j].AddLine(lineV1, lineV2);
                // WiresOutputs[j].AddPoint(pointOutPin, circleR - 4);
                WiresOutputs[j].CreateBuffer();
            }
            xBase += delta * 2;
            for (int i = 0; i < icount; i++)
            {
                var y = y0 + (icount - i - 1 + jcount) * bigStep;

                WiresInputs[i].AddLine(new Vector2(xLineLeft, y), new Vector2(xBase, y));
                WiresInputs[i].AddPoint(new Vector2(x0, y), circleR - 4);
                WiresInputs[i].AddPoint(new Vector2(xBase + circleR, y), circleR - 4);

                InOutPins.InstasingList.Add(
                    new VisualUniforms(Color.Black)
                {
                    Translate = new Vector2(x0, y)
                }
                    );
            }

            for (int i = 0; i < matrix.GetLength(1) + matrix.GetLength(0); i++)
            {
                var y = y0 + (icount - i - 1 + jcount) * bigStep;
                // vertices.AddRange(Round(new Vector2(xRight+circleR, y), circleR, 2.0f, 50, 0.1f));
                InOutPins.InstasingList.Add(
                    new VisualUniforms(Color.Black)
                {
                    Translate = new Vector2(xBase + circleR, y)
                }
                    );
            }

            for (int i = 0; i < icount; i++)
            {
                WiresInputs[i].CreateBuffer();
            }

            Visuals.AddRange(WiresInputs);
            Visuals.AddRange(WiresOutputs);
            Visuals.AddRange(logicalXors);
            Visuals.Add(InOutPins);
        }