Ejemplo n.º 1
0
 public EasyDrawComponent(DrawFunction func)
     : base(GameEntityComponent.UpdateLines.Draw)
 {
     m_layoutC       = null;
     m_lastDrawModel = null;
     m_drawFunc      = func;
 }
Ejemplo n.º 2
0
        public void Draw(int x, int y, int width, int height, DrawFunction draw, char chr = '█')
        {
            void SetPixel(int xc, int yc, char ch, ConsoleColor co)
            {
                // A typical font aspect ratio is ~ 2x1
                // so we double up the drawn coordinate to make it ~ 2x2
                var xx = x + xc * 2;
                var yy = y + yc;

                //
                _app.Buffer.SetColor(xx + 0, yy, co);
                _app.Buffer.SetColor(xx + 1, yy, co);
                _app.Buffer.SetCharacter(xx + 0, yy, ch);
                _app.Buffer.SetCharacter(xx + 1, yy, ch);
            }

            //
            foreach (var(xc, yc) in RasterizeRectangle(width, height))
            {
                if (draw(xc, yc, out var col))
                {
                    SetPixel(xc, yc, chr, col);
                }
            }
        }
        private void init(Control ctrl, bool printDialog)
        {
            _ctrl           = ctrl;
            _usePrintDialog = printDialog;
            _drawFunc       = printRenderFunction;
#if BITMAPONLY
            _drawFunc = printDrawFunction;
#endif
        }
Ejemplo n.º 4
0
 internal void DrawWithDebugRenderState(
     ScriptableRenderContext context,
     CommandBuffer cmd,
     ref RenderingData renderingData,
     ref DrawingSettings drawingSettings,
     ref FilteringSettings filteringSettings,
     ref RenderStateBlock renderStateBlock,
     DrawFunction func)
 {
     foreach (DebugRenderSetup debugRenderSetup in CreateDebugRenderSetupEnumerable(context, cmd))
     {
         DrawingSettings  debugDrawingSettings  = debugRenderSetup.CreateDrawingSettings(drawingSettings);
         RenderStateBlock debugRenderStateBlock = debugRenderSetup.GetRenderStateBlock(renderStateBlock);
         func(context, ref renderingData, ref debugDrawingSettings, ref filteringSettings, ref debugRenderStateBlock);
     }
 }
Ejemplo n.º 5
0
        public static void CircleBrush <T>(Stroke stroke, int mapSize, T[,] map, DrawFunction <T> drawFunction)
        {
            int minSPY, maxSPY, minSPX, maxSPX;

            FindStrokePixelBoundaries(stroke, mapSize, out minSPY, out maxSPY, out minSPX, out maxSPX);
            for (stroke.CurrentPixel.y = minSPY; stroke.CurrentPixel.y <= maxSPY; stroke.CurrentPixel.y++)
            {
                int sY2 = stroke.CurrentPixel.y * stroke.CurrentPixel.y;
                for (stroke.CurrentPixel.x = minSPX; stroke.CurrentPixel.x <= maxSPX; stroke.CurrentPixel.x++)
                {
                    stroke.CurrentPixel.distanceToCenter = Mathf.Sqrt(stroke.CurrentPixel.x * stroke.CurrentPixel.x + sY2);
                    if (stroke.CurrentPixel.distanceToCenter <= stroke.halfSize)
                    {
                        int mX = stroke.CurrentPixel.GetMapX(),
                            mY = stroke.CurrentPixel.GetMapY();
                        map[mX, mY] = drawFunction(stroke, map[mX, mY]);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public async void StartSOM(DrawFunction drawSOM, ProgressBar progressBar)
        {
            WorkingStatus = true;

            double somLearningRate = LearningRate;
            double tmpLearningRate = LearningRate;

            int    sigma  = NeuronCount / 2;
            double lambda = IterationCount / Math.Log(sigma);
            int    neighborhoodReductionStep = IterationCount / NeighborhoodRadius;

            // Progress bar
            som_progressBar         = progressBar;
            som_progressBar.Maximum = IterationCount;

            timer.Interval = 1;
            timer.Tick    += TimerTick;

            for (int i = 0; i < IterationCount; i++)
            {
                IterationNumber = i + 1;

                // Reduction of neighborhood radius
                if ((i + 1) % neighborhoodReductionStep == 0)
                {
                    NeighborhoodRadius--;
                }

                Point randomPoint = shape.RandomPointIn();

                // Calculation of distance between points
                List <double> distances = new List <double>();
                foreach (Point neuron in NeuronsList)
                {
                    double sum = DistanceBetweenPoints(randomPoint, neuron);
                    distances.Add(sum);
                }

                // Set the neuron index of the nearest selected point and radius of neighbors
                int nearestIndex = distances.IndexOf(distances.Min());
                int firstIndex   = 0;
                int lastIndex    = 0;

                if (nearestIndex - NeighborhoodRadius < 0)
                {
                    firstIndex = 0;
                }
                else
                {
                    firstIndex = nearestIndex - NeighborhoodRadius;
                }

                if (nearestIndex + NeighborhoodRadius > NeuronCount)
                {
                    lastIndex = NeuronCount;
                }
                else
                {
                    lastIndex = nearestIndex + NeighborhoodRadius;
                }

                NeuronsList[nearestIndex] = NeuronsList[nearestIndex] + somLearningRate * (randomPoint - NeuronsList[nearestIndex]);

                // Moving neurons
                for (int j = firstIndex; j < lastIndex; j++)
                {
                    if (j == nearestIndex)
                    {
                        continue;
                    }
                    NeuronsList[j] = NeuronsList[j] + somLearningRate / Math.Abs(nearestIndex - j) * (randomPoint - NeuronsList[j]);
                }

                timer.Start();
                await Task.Run(() => {
                    while (timer.Enabled)
                    {
                    }
                });

                // Decreasing learning rate
                double x = Math.Exp(-(i + 1) / lambda);
                somLearningRate = tmpLearningRate * x;
                LearningRate    = somLearningRate;

                // Update pictureBox
                drawSOM(randomPoint);

                // Update progressBar
                ProgressTick();

                //
                if (i == IterationCount - 1)
                {
                    WorkingStatus = false;
                }
            }
        }
Ejemplo n.º 7
0
 public void AddTab(DrawFunction tabFunction, string tabName)
 {
     tabs.Add(tabFunction);
     tabNames.Add(tabName);
 }
Ejemplo n.º 8
0
 public void AddOverlay(DrawFunction overlayFunction, Rect overlayRect)
 {
     overlayFunctions.Add(overlayFunction);
     overlayRects.Add(overlayRect);
 }
Ejemplo n.º 9
0
 private void DrawMember(MemberReference member, ShowInInspectorAttribute attribute, DrawFunction drawFunction)
 {
     this.DrawMember(member, attribute, drawFunction, false);
 }
Ejemplo n.º 10
0
        private void DrawMember(MemberReference memberReference, ShowInInspectorAttribute attribute, DrawFunction drawFunction, bool forceReadOnly)
        {
            var newValue = drawFunction(this.GetName(memberReference, attribute), memberReference.GetValue(this.Target), null);

            if (GUI.changed && memberReference.CanWrite && !forceReadOnly)
            {
                memberReference.SetValue(this.Target, newValue);
            }
        }
 private void radioButton2_CheckedChanged(object sender, EventArgs e)
 {
     drawFunction = Math.Cos;
 }
        public static bool GetDrawFunction(Type type, MemberReference memberReference, ShowInInspectorAttribute attribute, out DrawFunction drawFunction)
        {
            if (_drawFunctions.TryGetValue(type, out drawFunction))
            {
                return(true);
            }

            DrawFunctionGenerator generator;

            if (_drawFunctionGenerators.TryGetValue(type, out generator))
            {
                drawFunction = generator(memberReference, attribute);
                return(true);
            }

            if (type.IsEnum)
            {
                drawFunction = (n, v, o) => EditorGUILayout.EnumPopup(n, (Enum)v, o);
                return(true);
            }
            else if (typeof(UnityObject).IsAssignableFrom(type))
            {
                drawFunction = (n, v, o) => EditorGUILayout.ObjectField(n, (UnityObject)v, type, true, o);
                return(true);
            }
            else if (type.IsArray)
            {
                Type         elementType = type.GetElementType();
                DrawFunction elementDrawFunction;
                if (InternalPropertyDrawer.GetDrawFunction(elementType, out elementDrawFunction))
                {
                    drawFunction = (label, value, parameters) =>
                    {
                        const int IndentationAmount = 20;
                        Array     array             = (Array)value;

                        // draw the name of the array
                        EditorGUILayout.LabelField(label, EditorStyles.boldLabel);

                        // draw the length (and '+' & '-' buttons)
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(IndentationAmount);
                        int newLength = EditorGUILayout.IntField("Length", array.Length);
                        if (GUILayout.Button("+", GUILayout.Width(24)))
                        {
                            newLength++;
                        }
                        else if (GUILayout.Button("-", GUILayout.Width(24)))
                        {
                            newLength = FlaiMath.Max(0, newLength - 1);
                        }
                        EditorGUILayout.EndHorizontal();

                        // if the size has been changed, then update it
                        if (newLength != array.Length && newLength > 0)
                        {
                            Array newArray = (Array)Activator.CreateInstance(array.GetType(), newLength);
                            if (array.Length > 0)
                            {
                                for (int i = 0; i < newArray.Length; i++)
                                {
                                    var elementValue = (i >= array.Length) ? array.GetValue(array.Length - 1) : array.GetValue(i);
                                    newArray.SetValue(elementValue, i);
                                }
                            }

                            array = newArray;
                        }

                        // draw all the elements
                        for (int i = 0; i < array.Length; i++)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(IndentationAmount);
                            array.SetValue(elementDrawFunction("Element " + i, array.GetValue(i), null), i);
                            EditorGUILayout.EndHorizontal();
                        }

                        return(array);
                    };

                    return(true);
                }
            }

            return(false);
        }
 public static bool GetDrawFunction(Type type, out DrawFunction drawFunction)
 {
     return(GetDrawFunction(type, MemberReference.Empty, null, out drawFunction));
 }
 public static bool GetDrawFunction <T>(out DrawFunction drawFunction)
 {
     return(InternalPropertyDrawer.GetDrawFunction(typeof(T), out drawFunction));
 }
        public static bool GetDrawFunction(MemberReference member, ShowInInspectorAttribute attribute, out DrawFunction drawFunction)
        {
            if (InternalPropertyDrawer.GetDrawFunction(member.InnerType, member, attribute, out drawFunction))
            {
                return(true);
            }

            drawFunction = null;
            return(false);
        }