Esempio n. 1
0
        ///////////////////////////////////////////////Method\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

        /************************************************************************************************
        * Method: Wanderer()
        * Effect: Receives an object of strucure when thread is started. A random color will be chosen,
        *         and will draw pixels based on a random direction/velocity.
        * **********************************************************************************************/
        public static void Wanderer(object holder)
        {
            DrawingData info         = (DrawingData)(holder); //Unboxes structure
            Color       drawingColor = RandColor.GetColor();  //Holds random color for drawing
            Point       newPoint     = info.m_pCoor;

            drawSpace.SetBBScaledPixel(info.m_pCoor.X, info.m_pCoor.Y, drawingColor);
            drawSpace.Render();


            //Draw pixels
            for (int i = 0; i < info.m_iPixels; i++)
            {
                newPoint.X += rnd.Next(-1, 2);
                newPoint.Y += rnd.Next(-1, 2);
                newPoint.X  = (newPoint.X < 0) ? 0 : newPoint.X;
                newPoint.Y  = (newPoint.Y < 0) ? 0 : newPoint.Y;
                newPoint.X  = (newPoint.X > 799) ? 799 : newPoint.X;
                newPoint.Y  = (newPoint.Y > 599) ? 599 : newPoint.Y;

                drawSpace.SetBBScaledPixel(newPoint.X, newPoint.Y, drawingColor);
                Thread.Sleep(1);
                drawSpace.Render();
            }


            //lock gdi drawer during loop
        }
Esempio n. 2
0
        //instance ctor
        //rdm start point,clr and set raduis size in main form
        //keep balls in window
        public Ball(float rad)
        {
            radius       = rad;
            _Color       = RandColor.GetColor();
            ballCenter.X = (float)(_rdm.NextDouble() * drawer.ScaledWidth);
            ballCenter.Y = (float)(_rdm.NextDouble() * drawer.ScaledHeight);

            if (ballCenter.X < _radius)
            {
                ballCenter.X = _radius;
            }

            if (ballCenter.X > drawer.ScaledWidth - _radius)
            {
                ballCenter.X = drawer.ScaledWidth - _radius;
            }

            if (ballCenter.Y < _radius)
            {
                ballCenter.Y = _radius;
            }

            if (ballCenter.Y > drawer.ScaledHeight - _radius)
            {
                ballCenter.Y = drawer.ScaledHeight - _radius;
            }
        }
Esempio n. 3
0
        public Shape(Point SetLoc)
        {
            Location = SetLoc;
            bFalling = true;
            Color TempColour = RandColor.GetColor();

            Type = (Shapes)Block.Rand.Next(0, 7);
            switch (Type)
            {
            case Shapes.JAngle:
                Blocks.Add(new Block(this, 0, -1, TempColour));
                Blocks.Add(new Block(this, 0, 0, TempColour));
                Blocks.Add(new Block(this, 0, 1, TempColour));
                Blocks.Add(new Block(this, -1, 1, TempColour));
                break;

            case Shapes.LAngle:
                Blocks.Add(new Block(this, 0, -1, TempColour));
                Blocks.Add(new Block(this, 0, 0, TempColour));
                Blocks.Add(new Block(this, 0, 1, TempColour));
                Blocks.Add(new Block(this, 1, 1, TempColour));
                break;

            case Shapes.Line:
                Blocks.Add(new Block(this, 0, -1, TempColour));
                Blocks.Add(new Block(this, 0, 0, TempColour));
                Blocks.Add(new Block(this, 0, 1, TempColour));
                Blocks.Add(new Block(this, 0, 2, TempColour));
                break;

            case Shapes.Square:
                Blocks.Add(new Block(this, 0, 0, TempColour));
                Blocks.Add(new Block(this, 0, -1, TempColour));
                Blocks.Add(new Block(this, -1, -1, TempColour));
                Blocks.Add(new Block(this, -1, 0, TempColour));
                break;

            case Shapes.SZig:
                Blocks.Add(new Block(this, -1, -1, TempColour));
                Blocks.Add(new Block(this, 0, 0, TempColour));
                Blocks.Add(new Block(this, 0, -1, TempColour));
                Blocks.Add(new Block(this, 1, 0, TempColour));
                break;

            case Shapes.ZZig:
                Blocks.Add(new Block(this, -1, 0, TempColour));
                Blocks.Add(new Block(this, 0, 0, TempColour));
                Blocks.Add(new Block(this, 0, -1, TempColour));
                Blocks.Add(new Block(this, 1, -1, TempColour));
                break;

            case Shapes.TBone:
                Blocks.Add(new Block(this, -1, 0, TempColour));
                Blocks.Add(new Block(this, 0, 0, TempColour));
                Blocks.Add(new Block(this, 0, -1, TempColour));
                Blocks.Add(new Block(this, 1, 0, TempColour));
                break;
            }
        }
Esempio n. 4
0
        public void raiseWanderer()
        {
            Wanderer w = new Wanderer(click, RandColor.GetColor(), canvas, this);
            Thread   t = new Thread(w.wander);

            t.IsBackground = true;
            t.Start();
        }
Esempio n. 5
0
 public Shape() //Default ctor Randomificates
 {
     Location = new PointF(Random.Next(CanvasWidth),
                           Random.Next(CanvasHeight));
     Velocity = new PointF((float)Random.NextDouble() * 2 * MaxSpeed - MaxSpeed,
                           (float)Random.NextDouble() * 2 * MaxSpeed - MaxSpeed);
     Color = RandColor.GetColor();
 }
Esempio n. 6
0
 public ball(Point center)
 {
     _location  = center;
     ballRadius = 40;
     opacity    = 128;
     _ballColor = RandColor.GetColor();
     XVel       = _rdm.Next(-10, 11);
     YVel       = _rdm.Next(-10, 11);
 }
 public Ball(Point p)
 {
     BallColor = RandColor.GetColor();
     Ballrad   = 40;
     velX      = rand.Next(-11, 11);
     velY      = rand.Next(-11, 11);
     BallOpa   = 128;
     pLocation = p;
 }
Esempio n. 8
0
 //instance ctor
 public Block(int blockSize)
 {
     _Color           = RandColor.GetColor();
     size             = blockSize;
     rectangle.X      = _rdm.Next(0, drawer.ScaledWidth - _size);//no overlap??
     rectangle.Y      = _rdm.Next(0, drawer.ScaledHeight - _size);
     rectangle.Width  = _size;
     rectangle.Height = _size;
 }
Esempio n. 9
0
 //instance ctor
 //get rdm ball color, set rdm postion,and rdm velocity
 public Ball()
 {
     _ballColor = RandColor.GetColor();
     XVel       = _rdm.Next(-10, 11);
     YVel       = _rdm.Next(-10, 11);
     // initalize location to rdm point
     _location.X = _rdm.Next(0 + _radius, _drawer.ScaledWidth - _radius);
     _location.Y = _rdm.Next(0 + _radius, _drawer.ScaledHeight - _radius);
 }
Esempio n. 10
0
        static void SBlocks()
        {
            CDrawer can = new CDrawer(800, 600, false);

            for (int i = 0; i < 500; ++i)
            {
                can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1, RandColor.GetColor());
                can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1);
                can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor());
                can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800));

                can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1, RandColor.GetColor());
                can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1);
                can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor());
                can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800));

                try
                {
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor(), 1, RandColor.GetColor());
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor(), 1);
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor());
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2);
                    can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64));
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }

                try
                {
                    can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor(), 1, RandColor.GetColor());
                    can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor(), 1);
                    can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor());
                    can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610));
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }

                try
                {
                    can.AddText("Rats", s_rnd.Next(0, 100), s_rnd.Next(0, 800), s_rnd.Next(0, 600), s_rnd.Next(0, 200), s_rnd.Next(0, 200), RandColor.GetColor());
                    can.AddText("Rats", s_rnd.Next(0, 100), s_rnd.Next(0, 800), s_rnd.Next(0, 600), s_rnd.Next(0, 200), s_rnd.Next(0, 200));
                    can.AddText("Rats", s_rnd.Next(0, 100), RandColor.GetColor());
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }
            }

            can.Render();
            Console.ReadKey();
        }
Esempio n. 11
0
        private void BallThread(object ThreadData)
        {
            Random R = new Random();

            for (int i = 0; i < 500; ++i)
            {
                int x = R.Next(Canvas.DrawerWindowSize.Width);
                int y = R.Next(Canvas.DrawerWindowSize.Height);

                Canvas.AddEllipse(x, y, (int)ThreadData, (int)ThreadData, RandColor.GetColor());
                Thread.Sleep(50);
            }
        }
Esempio n. 12
0
        //********************************************************************************************
        //Method:     private void Wander(object obj)
        //Purpose:    thread operation/ get new x,y/ get rdm color
        //            displays SizeLabel to size selected in MYSizeDialog
        //Parameters: object obj - is inital coordinates
        //                         pixels amount set by trackbar
        //*********************************************************************************************
        private void Wander(object obj)
        {
            Random rdmVel = new Random(); // create a rdm generator for velocity x,y posistions
            int    xPos;                  // hold x cordinates
            int    yPos;                  // hold y cordinates

            // if object is in struct start running program
            if (obj is WanderData)
            {
                // create struct varaible
                WanderData wan = (WanderData)obj;

                // coordinates to be passed through from starting point
                xPos = wan.x;
                yPos = wan.y;

                // get radom colors for thread
                Color pickOne = RandColor.GetColor();

                // loop thruogh as many pixels as diceid from trackbar value
                for (int x = 0; x < wan.pCount; x++)
                {
                    // draw within gdi window
                    if (xPos >= 0 && xPos <= WIDTH - 1 && yPos >= 0 && yPos <= HEIGHT - 1)
                    {
                        //send parameters through deleagete to
                        try
                        {
                            Invoke(new delColor(changePixel), xPos, yPos, pickOne);
                            Thread.Sleep(1);
                        }
                        // if obj is dispoed, error
                        catch (ObjectDisposedException error)
                        {
                            MessageBox.Show(error.Message, "ahhh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    // if positioning outside if window
                    //keep running until its insdie of window
                    else
                    {
                        x--;
                    }
                    // get rdm locations for x and y velocitys for next loop
                    xPos += rdmVel.Next(-1, 2);
                    yPos += rdmVel.Next(-1, 2);
                }
            }
        }
Esempio n. 13
0
        private void BallThread(object ThreadData)
        {
            Random R = new Random();
            //Choose a random # of balls to spawn before thread dies
            int ballQuota = R.Next(10, 100);

            for (int i = 0; i < ballQuota; ++i)
            {
                int x = R.Next(Canvas.DrawerWindowSize.Width);
                int y = R.Next(Canvas.DrawerWindowSize.Height);

                Canvas.AddEllipse(x, y, (int)ThreadData, (int)ThreadData, RandColor.GetColor());
                Thread.Sleep(100);
            }
        }
Esempio n. 14
0
        //
        public shape(Point bLocal)
        {
            isFalling = true;
            myColor   = RandColor.GetColor();
            _sLocal   = bLocal;

            //assign rdm enum type
            sahpeType = (sType)_rdm.Next(0, 4);

            //origin
            blocks.Add(new block(bLocal, new Point(0, 0), myColor));
            //based on type create and add blocks
            switch (sahpeType)
            {
            case sType.square:
                //add blocks to make shape
                blocks.Add(new block(bLocal, leftOffdet, myColor));
                blocks.Add(new block(bLocal, downOffdet, myColor));
                blocks.Add(new block(bLocal, new Point(-1, 1), myColor));
                break;

            case sType.line:
                // add shape
                blocks.Add(new block(bLocal, downOffdet, myColor));
                blocks.Add(new block(bLocal, new Point(0, 2), myColor));
                blocks.Add(new block(bLocal, new Point(0, 3), myColor));
                break;

            case sType.lBlock:
                // add shape
                blocks.Add(new block(bLocal, downOffdet, myColor));
                blocks.Add(new block(bLocal, new Point(0, 2), myColor));
                blocks.Add(new block(bLocal, rightOffdet, myColor));
                break;

            case sType.Tblock:
                blocks.Add(new block(bLocal, leftOffdet, myColor));
                blocks.Add(new block(bLocal, downOffdet, myColor));
                blocks.Add(new block(bLocal, rightOffdet, myColor));
                break;

            default:
                //error here
                break;
            }
        }
Esempio n. 15
0
        static void SLines()
        {
            CDrawer can = new CDrawer(800, 600, false);

            can.AddLine(10, 10, 790, 590, Color.Red, 2);

            for (double d = 0; d < Math.PI * 2; d += Math.PI / 32)
            {
                can.AddLine(new Point(400, 300), 50 * d, d);
            }

            for (int x = 0; x < 600; x += 5)
            {
                can.AddLine(0, 600 - x, x, 0, RandColor.GetColor(), 1);
            }

            can.Render();
            Console.ReadKey();
        }
Esempio n. 16
0
        static public void DrawSky(CDrawer gdi, bool[,] stars)
        {
            int row    = 0;
            int column = 0;

            for (row = 0; row < stars.GetLength(0); row++)
            {
                for (column = 0; column < stars.GetLength(1); column++)
                {
                    if (stars[row, column])
                    {
                        gdi.SetBBPixel(column, row, RandColor.GetColor());
                    }
                    else
                    {
                        gdi.SetBBPixel(column, row, Color.Black);
                    }
                }
            }
            gdi.Render();
            Console.Clear();
            Console.WriteLine("\t\t\tSky updated\n");
        }
Esempio n. 17
0
        private void Form_KeyDown(object sender, KeyEventArgs e)
        {
            Random _Randomer = new Random();

            // call default trek constructor
            if (e.KeyCode == Keys.F1)
            {
                _trekLampsList.Add(new TrekLamps());
            }

            // call custom constructor: clr orange, 180 threshold,border n/a
            if (e.KeyCode == Keys.F2)
            {
                _trekLampsList.Add(new TrekLamps(180, Color.Orange, 2));
            }

            // custom constructor with rdm color,rdm #60-220, border 4
            if (e.KeyCode == Keys.F3)
            {
                _trekLampsList.Add(new TrekLamps((byte)_Randomer.Next(20, 221), RandColor.GetColor(), 4));
            }

            //remove the last added treklight
            if (e.KeyCode == Keys.Escape)
            {
                //if have squares-> remove them else do nothing
                if (_trekLampsList.Count > 0)
                {
                    _trekLampsList.RemoveAt(_trekLampsList.Count - 1);
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 18
0
 public Sheeple()
 {
     _totalItem   = _rng.Next(2, 6);
     _currentItem = _totalItem;
     _Color       = RandColor.GetColor().ToArgb();
 }
Esempio n. 19
0
        static void Main(string[] args)
        {
            CDrawer dr = new CDrawer();

            dr.BBColour = Color.White;
            Random rnd = new Random();

            dr.Scale = 20; // adjust scale to test ScaledWidth/ScaledHeight

            // Disable continuous update
            dr.ContinuousUpdate = false;
            // perform lengthy/high object count operation
            for (int i = 0; i < 1000; ++i)
            {
                dr.AddEllipse(rnd.Next(dr.ScaledWidth), rnd.Next(dr.ScaledHeight), 1, 1, RandColor.GetColor());
                dr.Render(); // tell drawer to show now, all elements have been added
            }


            int iNum = 0;

            iNum++;



            Point pCoord;          // coords to accept mouse click pos
            int   iNumClicks  = 0; // count number of clicks accepted
            int   iFalseAlarm = 0; // count the number of poll calls

            do
            {
                bool bRes = dr.GetLastMouseLeftClick(out pCoord); // poll
                if (bRes)                                         // new coords?
                {
                    ++iNumClicks;
                    dr.AddEllipse(pCoord.X - 10, pCoord.Y - 10, 20, 20);
                }
                else
                {
                    iFalseAlarm++;                      // not new coords
                }
            }while (iNumClicks < 10);

            Console.WriteLine("Checked for coordinates " + iFalseAlarm.ToString() + " times!");


            Console.ReadKey();

            /*
             * {
             *  FileStream foo = new FileStream("snot", FileMode.Create);
             *  MemoryStream ms = new MemoryStream();
             *  BinaryFormatter bf = new BinaryFormatter();
             *
             *  SThing temp = new SThing();
             *  temp.i = 42;
             *
             *  bf.Serialize(ms, temp);
             *  foo.Write(ms.GetBuffer(), 0, (int)ms.Length);
             *  foo.Close();
             * }
             *
             * {
             *  FileStream foo = new FileStream("snot", FileMode.Open);
             *  BinaryFormatter bf = new BinaryFormatter();
             *
             *  object o = bf.Deserialize(foo);
             *  if (o is SThing)
             *  {
             *      SThing temp = (SThing)o;
             *      Console.WriteLine (temp.i.ToString());
             *  }
             * }
             *
             * Console.ReadKey();
             */
        }
Esempio n. 20
0
        static void CenteredRectangleTest()
        {
            CDrawer can = new CDrawer(800, 600, false);

            can.AddCenteredRectangle(400, 300, 796, 596, Color.Red);
            for (int i = 0; i < 500; ++i)
            {
                can.AddCenteredRectangle(s_rnd.Next(100, 700), s_rnd.Next(100, 500), s_rnd.Next(5, 190), s_rnd.Next(5, 190), RandColor.GetColor(), s_rnd.Next(6), RandColor.GetColor());
            }
            can.Render();
            Console.ReadKey();
        }
Esempio n. 21
0
        public List <Block> _lBlocks = new List <Block>();  //contains the blocks that make the shape.

        //Function name:    Shape
        //Description:      Instance constructor for Shape objects.
        //Returns:          none (CTOR)
        //Arguments:        Point shapeBaseLocation - draw the core block here.
        public Shape(Point shapeBaseLocation)
        {
            _bFalling = true;                                        //Object is falling by default
            Color c = RandColor.GetColor();                          //Object gets a random color

            this._pCoreLocation = shapeBaseLocation;                 //core block is drawn at the base location
            this._ShapeType     = (ShapeType)Block._rGen.Next(0, 7); //Object gets a random shape type

            switch (_ShapeType)                                      //Add blocks to each shape type differently.
            {
            case ShapeType.I:
                for (int i = 0; i < 3; i++)
                {
                    _lBlocks.Add(new Block(this, i, 0, c));
                }
                _lBlocks.Add(new Block(this, -1, 0, c));
                break;

            case ShapeType.J:
                _lBlocks.Add(new Block(this, 0, 0, c));
                _lBlocks.Add(new Block(this, -1, 0, c));
                for (int i = 0; i < 2; i++)
                {
                    _lBlocks.Add(new Block(this, 1, i, c));
                }
                break;

            case ShapeType.L:
                _lBlocks.Add(new Block(this, 0, 0, c));
                _lBlocks.Add(new Block(this, 1, 0, c));
                for (int i = 0; i < 2; i++)
                {
                    _lBlocks.Add(new Block(this, -1, i, c));
                }
                break;

            case ShapeType.O:
                for (int i = 0; i < 2; i++)
                {
                    _lBlocks.Add(new Block(this, 0, -i, c));
                }
                for (int i = 0; i < 2; i++)
                {
                    _lBlocks.Add(new Block(this, -1, -i, c));
                }
                break;

            case ShapeType.S:
                for (int i = 0; i < 2; i++)
                {
                    _lBlocks.Add(new Block(this, 0, i, c));
                }
                _lBlocks.Add(new Block(this, 1, 0, c));
                _lBlocks.Add(new Block(this, -1, 1, c));
                break;

            case ShapeType.T:
                for (int i = 0; i < 2; i++)
                {
                    _lBlocks.Add(new Block(this, 0, i, c));
                }
                _lBlocks.Add(new Block(this, -1, 0, c));
                _lBlocks.Add(new Block(this, 1, 0, c));
                break;

            case ShapeType.Z:
                for (int i = 0; i < 2; i++)
                {
                    _lBlocks.Add(new Block(this, 0, i, c));
                }
                _lBlocks.Add(new Block(this, -1, 0, c));
                _lBlocks.Add(new Block(this, 1, 1, c));
                break;
            }
        }
Esempio n. 22
0
 /// <summary>
 /// default ctor
 /// generate random number of items to be queued between min and max
 /// set current total to set random total
 /// and generate a random color for each item
 /// </summary>
 public sheeple()
 {
     TotalItems   = _rdm.Next(MIN, MAX + 1);//inclusive?
     currentItems = TotalItems;
     sheepColor   = RandColor.GetColor();
 }
Esempio n. 23
0
 //default consturctor
 public TrekLamps() : this(64, RandColor.GetColor(), 6)
 {
 }