Example #1
0
        private void CreateSplitter()
        {
            Splitter = new StreamingSplitter(SimpleShader);
            float arg = (float)(2 * Math.PI * 2 / ItemsCount + Math.PI / ItemsCount * 2);
            var   cos = MiddleRadius * (float)Math.Cos(arg);
            var   sin = MiddleRadius * (float)Math.Sin(arg);

            Splitter.Translate = new Vector2(cos, sin);
            Childrens.Add(Splitter);
        }
Example #2
0
        public InseparableCode(bool[] gx, SimpleShader simpleShader) : base(simpleShader)
        {
            // if (gx.Length != 4) throw new Exception("Неправильный размер массива");
            int gCount = gx.Length;

            streamingSource = new StreamingSource(new[] { 0, 1, 1, 0 }, simpleShader)
            {
                Translate = new Vector2(Delta * 1, Delta * 11)
            };



            #region Register
            int regCount = gx.Length - 1;
            Registers = new StreamingRegister[regCount];
            for (int i = 0; i < regCount; i++)
            {
                Registers[i] = new StreamingRegister(simpleShader)
                {
                    Translate = new Vector2(Delta * 8 + i * Delta * 8, Delta * 10)
                };
            }

            #endregion


            #region Sumators
            int sumCount = gx.Count(x => x) - 1;

            Splitters    = new StreamingSplitter[sumCount];
            Splitters[0] = new StreamingSplitter(simpleShader)
            {
                Translate = new Vector2(Delta * 7, Delta * 11)
            };
            Summators = new StreamingSummator[sumCount];
            for (int i = 1, j = 0; i < gx.Length; i++)
            {
                if (!gx[i])
                {
                    continue;
                }

                Summators[j] = new StreamingSummator(simpleShader, 2)
                {
                    Up        = true,
                    Translate = new Vector2(Delta * 5 + i * Delta * 8, Delta * 3)
                };
                j++;
                if (j >= sumCount)
                {
                    continue;
                }
                Splitters[j] = new StreamingSplitter(simpleShader)
                {
                    Translate = new Vector2(Delta * 7 + i * Delta * 8, Delta * 11)
                };
                ConnectWire(Splitters[j], 0, Summators[j - 1], 1);
            }
            for (int i = 0; i < sumCount - 1; i++)
            {
                ConnectWire(Summators[i], 0, Summators[i + 1], 0);
            }

            for (int i = 1, j = 0; i < gx.Length - 1; i++)
            {
                if (!gx[i])
                {
                    ConnectWire(Registers[i - 1], 0, Registers[i], 0);
                }
                else
                {
                    j++;
                    ConnectWire(Registers[i - 1], 0, Splitters[j], 0);
                    ConnectWire(Splitters[j], 1, Registers[i], 0);
                }
            }

            #endregion

            streamingReceiver = new StreamingReceiver(simpleShader)
            {
                Translate = new Vector2(Delta * 2 + Delta * gx.Length * 8, Delta * 5)
            };

            ConnectWire(streamingSource, 0, Splitters[0], 0);
            ConnectWire(Splitters[0], 0, Summators[0], 0,
                        new[] { new Vector2(Delta * 7, Delta * 5) });
            ConnectWire(Splitters[0], 1, Registers[0], 0);
            ConnectWire(Registers.Last(), 0, Summators.Last(), 1,
                        new[] { new Vector2(Delta * gx.Length * 8 - Delta * 1, Delta * 11) });

            ConnectWire(Summators.Last(), 0, streamingReceiver, 0);


            foreach (var reg in Registers)
            {
                Childrens.Add(reg);
            }
            foreach (var spl in Splitters)
            {
                Childrens.Add(spl);
            }
            foreach (var summ in Summators)
            {
                Childrens.Add(summ);
            }

            Childrens.Add(streamingSource);
            Childrens.Add(streamingReceiver);


            ButtonTickZero = new Button(Delta, simpleShader)
            {
                Translate = new Vector2(Delta * 4, Delta * 10)
            };
            Childrens.Add(ButtonTickZero);

            TestBit = new Glyph7x5('0', new Vector2(Delta * 3, Delta * 3), simpleShader);
            Childrens.Add(TestBit);
            ButtonTickZero.Click += (s, e) =>
            {
                TestBit.Char = TestBit.Char == '0' ? '=' : '0';
            };

            ButtonTickOne = new Button(Delta, simpleShader)
            {
                Translate = new Vector2(Delta * 2, Delta * 10)
            };
            Childrens.Add(ButtonTickOne);



            ButtonTickOne.Click += (s, e) =>
            {
                streamingSource.Start();
            };
        }