Esempio n. 1
0
 public Sifteo.Color GetSifteoColor()
 {
     try
     {
         Sifteo.Color c = new Sifteo.Color(r, g, b);
         return c;
     }
     catch (Exception e)
     {
         throw new Exception("something went wrong when trying to deal with the color (" + r + ", " + g + ", " + b + ")");
     }
 }
Esempio n. 2
0
        /*
         * Consturctor
         */
        public DominoPainter(Cube cube, int number, System.Drawing.Color color)
        {
            Log.Debug ("DominoPainter {0}", number);
            mCube = cube;
            //System.Drawing.Color.FromArgb (color.Data);
            //String rtn = String.Empty;

            //rtn = "#" + color.R.ToString ("X2") + color.G.ToString ("X2") + color.B.ToString ("X2");
            //rtn = "RGB(" + color.R.ToString () + "," + color.G.ToString () + "," + color.B.ToString () + ")";
            //Log.Debug (rtn);
            mRectColor = new Sifteo.Color (Convert.ToInt32 (color.R.ToString ()), Convert.ToInt32 (color.G.ToString ()), Convert.ToInt32 (color.B.ToString ()));
            //mRectColor = new Sifteo.Color (Convert.ToInt32 (color.R.ToString ("X2")), Convert.ToInt32 (color.G.ToString ("X2")), Convert.ToInt32 (color.B.ToString ("X2")));

            switch (number) {
            case 1:
                one ();
                break;
            case 2:
                two ();
                break;
            case 3:
                three ();
                break;
            case 4:
                four ();
                break;
            case 5:
                five ();
                break;
            case 6:
                six ();
                break;
            case 7:
                seven ();
                break;
            case 8:
                eight ();
                break;
            case 9:
                nine ();
                break;
            default:

                if (number == 0) {
                    //Do Nothing
                } else if (number > 9) {
                    tilePaint2 (number);
                }

                break;

            }
        }
 /// <summary>
 /// Convets Bitmaps to color Sifteo.Color array.
 /// </summary>
 /// <returns>
 /// The to color array.
 /// </returns>
 /// <param name='bitmap'>
 /// Bitmap.
 /// </param>
 public Sifteo.Color[,]  bitmapToColorArray (System.Drawing.Bitmap bitmap)
 {
     Sifteo.Color[,]  colors = new Sifteo.Color[bitmap.Width,bitmap.Height];
     for (int i =0; i < bitmap.Width; i++)
     {
         for (int j=0; j < bitmap.Height; j++) 
         {
             System.Drawing.Color c = bitmap.GetPixel (i, j);
             colors [i,j] = new Sifteo.Color (c.R, c.G, c.B);    
         }
     }
     return colors;
 }
 /// <summary>
 /// Convets Bitmaps to color Sifteo.Color array.
 /// </summary>
 /// <returns>
 /// The to color array.
 /// </returns>
 /// <param name='bitmap'>
 /// Bitmap.
 /// </param>
 public Sifteo.Color[,]  bitmapToColorArray(System.Drawing.Bitmap bitmap)
 {
     Sifteo.Color[,]  colors = new Sifteo.Color[bitmap.Width, bitmap.Height];
     for (int i = 0; i < bitmap.Width; i++)
     {
         for (int j = 0; j < bitmap.Height; j++)
         {
             System.Drawing.Color c = bitmap.GetPixel(i, j);
             colors [i, j] = new Sifteo.Color(c.R, c.G, c.B);
         }
     }
     return(colors);
 }
        /// <summary>
        /// Builds the histogram of Sifteo.Colors.
        /// </summary>
        /// <returns>
        /// The histogram.
        /// </returns>
        /// <param name='colors'>
        /// Colors.
        /// </param>
        /// <param name='rect'>
        /// Area to build a histogram for
        /// </param>
        public Dictionary <byte, int> buildHistogram(Sifteo.Color[,]  colors,
                                                     Rectangle rect)
        {
            Dictionary <byte, int> histo = new Dictionary <byte, int> ();

            for (int i = rect.Left; i < rect.Right; i++)
            {
                for (int j = rect.Top; j < rect.Bottom; j++)
                {
                    Sifteo.Color c = colors [i, j];

                    if (!histo.ContainsKey(c.Data))
                    {
                        histo [c.Data] = 1;
                    }
                    else
                    {
                        histo [c.Data] = histo [c.Data] + 1;
                    }
                }
            }
            return(histo);
        }
Esempio n. 6
0
 public void setColor(Sifteo.Color c)
 {
     mColor = c;
 }
Esempio n. 7
0
        /*
         * Constructor with Side
         */
        public DominoPainter(Cube cube, int number, Cube.Side side, System.Drawing.Color color)
        {
            Log.Debug ("DominoPainter {0}", number);
            mCube = cube;
            mRectColor = new Sifteo.Color (Convert.ToInt32 (color.R.ToString ()), Convert.ToInt32 (color.G.ToString ()), Convert.ToInt32 (color.B.ToString ()));

            Cube.Side mSide = side;

            //Left Side
            if (mSide == Cube.Side.LEFT) {
                x = Constants.kSidedWallPadding;
                y = Cube.SCREEN_HEIGHT / 2;

                //Negative
                xOffset = (((Constants.kSidedCubeSide * 1) + (Constants.kSidedWallPadding * 1)) * -1);
                yOffset = 0;

            } else if (mSide == Cube.Side.RIGHT) {
                //Right side
                x = Cube.SCREEN_WIDTH - Constants.kSidedWallPadding - Constants.kSidedCubeSide;
                y = Cube.SCREEN_HEIGHT / 2;

                //Positive
                xOffset = (Constants.kSidedCubeSide + (Constants.kSidedWallPadding * 1));
                yOffset = 0;

            } else if (mSide == Cube.Side.TOP) {
                x = Constants.kSidedWallPadding;
                y = Cube.SCREEN_HEIGHT / 2;

                //Negative
                xOffset = (((Constants.kSidedCubeSide * 1) + (Constants.kSidedWallPadding * 1)) * -1);
                yOffset = 0;

                //mSide = Cube.Side.Left ();

                //Top Side
                //x = Cube.SCREEN_WIDTH / 2;
                //y = Constants.kSidedWallPadding;

            } else if (mSide == Cube.Side.BOTTOM) {
                //Force it
                //Right side
                x = Cube.SCREEN_WIDTH - Constants.kSidedWallPadding - Constants.kSidedCubeSide;
                y = Cube.SCREEN_HEIGHT / 2;

                //Positive
                xOffset = (Constants.kSidedCubeSide + (Constants.kSidedWallPadding * 1));
                yOffset = 0;

                //mSide = Cube.Side.RIGHT;

                //Bottom Side
                //x = Cube.SCREEN_WIDTH / 2;
                //y = Cube.SCREEN_HEIGHT - Constants.kSidedWallPadding - Constants.kSidedCubeSide;
            }

            x = 59;
            y = 64;

            switch (number) {
            case 1:
                one (mSide);
                break;
            case 2:
                two (mSide);
                break;
            case 3:
                three (mSide);
                break;
            case 4:
                four (mSide);
                break;
            case 5:
                five (mSide);
                break;
            case 6:
                six (mSide);
                break;
            case 7:
                seven (mSide);
                break;
            case 8:
                eight (mSide);
                break;
            case 9:
                nine (mSide);
                break;
            default:
                Log.Debug ("Error");
                break;

            }
        }
        /// <summary>
        /// Blits the colors.
        /// </summary>
        /// <param name='cube'>
        /// A Cube.
        /// </param>
        /// <param name='colors'>
        /// The colors to paint to the cube.
        /// </param>
        /// <param name='lastColorsSent'>
        /// Can be null.  If provided the cube only updates the changed colors.
        /// </param>
        /// <param name='rect'>
        /// Update area.
        /// </param>
        private void blitColors(Cube cube,
                                Sifteo.Color [,] colors,
                                Sifteo.Color [,] lastColorsSent,
                                Rectangle rect)
        {
            Sifteo.Color lastSentColor = Sifteo.Color.Mask;
            bool         changedOnly   = lastColorsSent != null;

            int lastStart = 0;
            int length    = 0;
            int fillRects = 0;

            if (changedOnly)
            {
                //only set the changed colors
                //but try to reduce sets by writing in lines once
                //you find a single pixel that needs changed.
                for (int i = rect.Left; i < rect.Right; i++)
                {
                    length = -1;
                    for (int j = rect.Top; j < rect.Bottom; j++)
                    {
                        Sifteo.Color c = colors[i, j];

                        //is this is different than the last color sent to this position?
                        bool newColorToImage = c.Data != lastColorsSent[i, j].Data;

                        //are we already making a line of this color?
                        bool sameColorInLine = length > -1 && c.Data == lastSentColor.Data;

                        if (newColorToImage && !sameColorInLine)
                        {
                            //are we already sending some data?
                            if (length > -1)
                            {
                                fillRects++;
                                cube.FillRect(lastSentColor, i, lastStart, 1, length);
                            }
                            //start here for the next color
                            lastStart     = j;
                            length        = 1;
                            lastSentColor = c;
                        }
                        else if (sameColorInLine)
                        {
                            length++;
                        }
                        else
                        {
                            if (length > -1)
                            {
                                fillRects++;
                                cube.FillRect(lastSentColor, i, lastStart, 1, length);
                            }
                            //not a new color, not a line. nothing going on
                            length = -1;
                        }
                    }
                    if (length > -1)
                    {
                        fillRects++;
                        cube.FillRect(lastSentColor, i, lastStart, 1, length);
                    }
                }
                totalFilLRects += fillRects;
            }
            else
            {
                Sifteo.Color background = Sifteo.Color.Black;

                //if we don't have any last sent colors
                //fill the background with the most frequent color
                byte         mostFrequent = getMostFrequentColor(colors, rect);
                Sifteo.Color color        = getColor(colors, mostFrequent);
                background    = color;
                lastSentColor = color;
                cube.FillRect(color, rect.Left, rect.Top, rect.Right, rect.Bottom);

                for (int i = rect.Left; i < rect.Right; i++)
                {
                    length = -1;
                    for (int j = rect.Top; j < rect.Bottom; j++)
                    {
                        Sifteo.Color c = colors[i, j];

                        //are we already making a line of this color?
                        bool sameColorInLine = length > -1 && c.Data == lastSentColor.Data;
                        bool newColor        = c.Data != lastSentColor.Data;

                        //start a line if this is not the background color.
                        //and we did not already start a line.
                        if ((newColor || lastSentColor.Data != background.Data) && !sameColorInLine)
                        {
                            if (length > -1)
                            {
                                cube.FillRect(lastSentColor, i, lastStart, 1, length);
                                fillRects++;
                            }
                            lastStart     = j;
                            length        = 1;
                            lastSentColor = c;
                        }
                        else if (sameColorInLine)
                        {
                            length++;
                        }
                        else
                        {
                            lastSentColor = c;
                            length        = -1;
                        }
                    }
                    if (length > -1)
                    {
                        fillRects++;
                        cube.FillRect(lastSentColor, i, lastStart, 1, length);
                    }
                }
                totalFilLRects += fillRects;
            }
        }