/// <summary>
        /// Draws an entire bitmap to a grid of NeoPixels
        /// </summary>
        /// <param name="bm">the bitmap to draw</param>
        /// <param name="GetIndexFunc">a "function pointer" so the user can specify how the grid is arranged. for generic arrangements, try using "GridArrangement" instead</param>
        public void Write(Bitmap bm, GetIndexDelegate GetIndexFunc)
        {
            // note: top left corner of a bitmap is (0,0)

            int count = bm.Width * bm.Height;

            byte[] barr = new byte[count * 3];
            for (int x = 0; x < bm.Width; x++)
            {
                for (int y = 0; y < bm.Height; y++)
                {
                    Color c   = bm.GetPixel(x, y);
                    int   idx = GetIndexFunc(x, y, bm.Width, bm.Height);
                    barr[idx * 3 + 0] = ColorUtility.GetGValue(c);
                    barr[idx * 3 + 1] = ColorUtility.GetRValue(c);
                    barr[idx * 3 + 2] = ColorUtility.GetBValue(c);
                }
            }
            NeoPixelNative.Write(barr, count, (UInt32)pin);

            /* // this is what the code would've looked like if I didn't care about RAM memory so much
             * Color[] pix = new Color[bm.Width * bm.Height];
             * for (int x = 0; x < bm.Width; x++)
             * {
             *  for (int y = 0; y < bm.Height; y++)
             *  {
             *      Color c = bm.GetPixel(x, y);
             *      int idx = GetIndexFunc(x, y, bm.Width, bm.Height);
             *      pix[idx] = c;
             *  }
             * }
             *
             * Write(pix);
             * //*/
        }
Exemplo n.º 2
0
        public static MathExpr Create(string formula, GetIndexDelegate var)
        {
            MathExpr expr = new MathExpr();

            string[] colWords = SplitWords.Split(formula);

            var mathFuncs = new[] {
                "cos", "sin", "tan", "cot", "abs", "sgn",
                "sqrt", "log", "exp", "asin", "acos", "atan",
                "acot", "sinh", "cosh", "tanh", "coth", "log10",
                "step"
            };


            foreach (string s  in  colWords)
            {
                var word = (s ?? "").Trim();
                if (string.IsNullOrEmpty(word))
                {
                    continue;
                }

                if (!PatNumber.IsMatch(word))   // if it isn't a number
                // its a word
                {
                    if (Array.IndexOf(mathFuncs, word.ToLower()) == -1)
                    {
                        Variable variable = expr.jeb.AddVariable(word, 0.0d);
                        expr.variables[variable] = var(word);
                    }
                    else // it's a function
                    {
                        // it's an upper case function, convert to lower case
                        if (!word.Equals(word.ToLower()))
                        {
                            formula = formula.Replace(word, word.ToLower());
                        }
                    }
                }
            }

            try {
                expr.jeb.Parse(formula);
            }
            catch (ParseException) {
                return(null);
            }

            return(expr);
        }
Exemplo n.º 3
0
        public ContinuousRasterHelper(IContinuousRaster <VertexType> raster)
            : base(raster)
        {
            if (raster == null)
            {
                throw new ArgumentNullException("raster");
            }

            Raster = raster;

            IRasterVertexHandle <VertexType> vertexHandle = Raster.CreateVertexHandle();

            GetIndexDelegate getVertexIndexDelegate = delegate(int[] position) { return(vertexHandle.MoveTo(position).Vertex.RowIndex); };

            SetGetIndexDelegate(getVertexIndexDelegate);
        }
Exemplo n.º 4
0
        protected void SetGetIndexDelegate(GetIndexDelegate getIndexDelegate)
        {
            m_getIndexDelegate = getIndexDelegate;

            DetermineTileGeometry();
        }