Esempio n. 1
0
 private void btnStartOrPause_Click(object sender, EventArgs e)
 {
     if (animation == DEFINE.EAnimation.Start)
     {
         double sizeDir = Math.Sqrt(r.Direction.X * r.Direction.X + r.Direction.Y * r.Direction.Y);
         r.Velocity = new Point(DEFINE.Round(tbVelocity.Value * (speedMoveBase * r.Direction.X / sizeDir)),
                                -1 * DEFINE.Round(tbVelocity.Value * (speedMoveBase * r.Direction.Y / sizeDir)));
         timer1.Interval = 30;
         animation       = DEFINE.EAnimation.Running;
         timer1.Start();
         btnStartOrPause.Text   = "Pause";
         btnClearOrStop.Text    = "Stop";
         btnClearOrStop.Enabled = true;
     }
     else if (animation == DEFINE.EAnimation.Running)
     {
         animation            = DEFINE.EAnimation.Pause;
         btnStartOrPause.Text = "Resume";
     }
     else if (animation == DEFINE.EAnimation.Pause)
     {
         animation            = DEFINE.EAnimation.Running;
         btnStartOrPause.Text = "Pause";
     }
 }
Esempio n. 2
0
        private static void ShadedY(int x1, int y1, int x2, int y2, Color color, ref Bitmap bm)
        {
            int dx = Math.Abs(x2 - x1);
            int dy = Math.Abs(y2 - y1);
            int h  = 2 * dx;
            int w  = h - 2 * dy;
            int d  = h - dy;
            int x  = x1;
            int y  = y1;
            int xend;
            int yend;

            if (y1 > y2)
            {
                x    = x2;
                y    = y2;
                xend = x1;
                yend = y1;
            }
            else
            {
                x    = x1;
                y    = y1;
                xend = x2;
                yend = y2;
            }
            int deltaX = -1;

            if (x < xend)
            {
                deltaX = 1;
            }
            int alpha = 255;
            int y0    = y;

            for (; y < yend; y++)
            {
                double doMo = (yend - y) / (yend - y0 * 1.0);
                if (y1 == yend)
                {
                    doMo = 1 - (yend - y) / (yend - y0 * 1.0);
                }
                SetPixel(x, y, Color.FromArgb(DEFINE.Round(alpha * doMo), color), ref bm);
                if (d < 0)
                {
                    d += h;
                }
                else
                {
                    d += w;
                    x += deltaX;
                }
            }
        }
Esempio n. 3
0
        private static void ShadedX(int x1, int y1, int x2, int y2, Color color, ref Bitmap bm)
        {
            int dx = Math.Abs(x2 - x1);
            int dy = Math.Abs(y2 - y1);
            int h  = 2 * dy;
            int w  = h - 2 * dx;
            int d  = h - dx;
            int x  = x1;
            int y  = y1;
            int xend;
            int yend;

            if (x1 > x2)
            {
                x    = x2;
                y    = y2;
                xend = x1;
                yend = y1;
            }
            else
            {
                x    = x1;
                y    = y1;
                xend = x2;
                yend = y2;
            }
            int deltaY = -1;

            if (y < yend)
            {
                deltaY = 1;
            }
            int alpha = 255;
            int x0    = x;

            for (; x < xend; x++)
            {
                double doMo = (xend - x) / (xend - x0 * 1.0);
                if (x1 == xend)
                {
                    doMo = 1 - (xend - x) / (xend - x0 * 1.0);
                }
                SetPixel(x, y, Color.FromArgb(DEFINE.Round(alpha * doMo), color), ref bm);
                if (d < 0)
                {
                    d += h;
                }
                else
                {
                    d += w;
                    y += deltaY;
                }
            }
        }
Esempio n. 4
0
        private static void Decac(int xI, int yI, int r, Color color, ref Bitmap bm)
        {
            double y_real;
            int    x;
            int    y;

            for (x = 0; x <= r * Math.Cos(45 * Math.PI / 180.0) + 0.5; x++)
            {
                y_real = Math.Sqrt(1.0 * r * r - x * x);
                y      = DEFINE.Round(y_real);
                SetPixel(x + xI, y + yI, color, ref bm);
                SetPixel(y + xI, x + yI, color, ref bm);
                SetPixel(y + xI, -x + yI, color, ref bm);
                SetPixel(x + xI, -y + yI, color, ref bm);
                SetPixel(-x + xI, -y + yI, color, ref bm);
                SetPixel(-y + xI, -x + yI, color, ref bm);
                SetPixel(-y + xI, x + yI, color, ref bm);
                SetPixel(-x + xI, y + yI, color, ref bm);
            }
        }
Esempio n. 5
0
        private static void ToaDoCuc(int xI, int yI, int r, Color color, ref Bitmap bm)
        {
            double scale = r / 60.0;
            int    alpha0 = DEFINE.Round(90 * scale);
            int    alphaEnd = DEFINE.Round(45 * scale);
            int    x, y;

            for (; alpha0 >= alphaEnd; alpha0--)
            {
                x = DEFINE.Round(r * Math.Cos(alpha0 * Math.PI / 180 / scale));
                y = DEFINE.Round(r * Math.Sin(alpha0 * Math.PI / 180 / scale));
                SetPixel(x + xI, y + yI, color, ref bm);
                SetPixel(y + xI, x + yI, color, ref bm);
                SetPixel(y + xI, -x + yI, color, ref bm);
                SetPixel(x + xI, -y + yI, color, ref bm);
                SetPixel(-x + xI, -y + yI, color, ref bm);
                SetPixel(-y + xI, -x + yI, color, ref bm);
                SetPixel(-y + xI, x + yI, color, ref bm);
                SetPixel(-x + xI, y + yI, color, ref bm);
            }
        }
Esempio n. 6
0
        private static void Elip(int xI, int yI, int a, int b, Color color, ref Bitmap bm)
        {
            int x = 0;
            int y = b;
            int d = DEFINE.Round(b * b - a * a * b + a * a * 0.25);

            for (; (2 * b * b * x) < (2 * a * a * y); x++) // y
            {
                SetPixel(x + xI, y + yI, color, ref bm);
                SetPixel(x + xI, -y + yI, color, ref bm);
                SetPixel(-x + xI, -y + yI, color, ref bm);
                SetPixel(-x + xI, y + yI, color, ref bm);
                if (d < 0)
                {
                    d += b * b * (2 * x + 3);
                }
                else
                {
                    d += b * b * (2 * x + 3) + a * a * (-2 * y + 2);
                    y--;
                }
            }
            d = DEFINE.Round(b * b * (x + 0.5) * (x + 0.5) + a * a * (y - 1) * (y - 1) - a * a * b * b);
            for (; y >= 0; y--)
            {
                SetPixel(x + xI, y + yI, color, ref bm);
                SetPixel(x + xI, -y + yI, color, ref bm);
                SetPixel(-x + xI, -y + yI, color, ref bm);
                SetPixel(-x + xI, y + yI, color, ref bm);
                if (d >= 0)
                {
                    d += a * a * (-2 * y + 3);
                }
                else
                {
                    d += b * b * (2 * x + 2) + a * a * (-2 * y + 3);
                    x++;
                }
            }
        }
Esempio n. 7
0
 public ucRectangleMove()
 {
     InitializeComponent();
     bm  = new Bitmap(pbDraw.Size.Width, pbDraw.Size.Height);
     Oxy = new Model.Oxy(ref bm)
     {
         Position = new Point(DEFINE.Round(pbDraw.Width / 2), DEFINE.Round(pbDraw.Height / 2)),
         Color    = Color.Red
     };
     r = new Model.Rectangle(ref bm)
     {
         Position  = new Point(Oxy.Position.X, Oxy.Position.Y),
         Color     = Color.Red,
         Direction = new Point(100, 0),
         Height    = 60,
         Width     = 30,
         Velocity  = new Point(speedMoveBase * tbVelocity.Value, 0)
     };
     r.Draw();
     Oxy.Draw();
     pbDraw.Image = bm;
 }
Esempio n. 8
0
        private static void DDA(int x1, int y1, int x2, int y2, Color color, ref Bitmap bm)
        {
            //get board
            //calculating

            double m        = -3;
            int    infinity = 0;

            if (x1 != x2)
            {
                infinity = 1;
                m        = (y2 - y1) / (x2 - x1 * 1.0); // hệ số m
            }
            // tăng theo x
            if (((m <= 1 && m >= 0) || (m >= -1 && m < 0)) && x2 > x1)
            {
                double y = y1;
                int    iy;
                for (int x = x1; x <= x2; x++)
                {
                    iy = DEFINE.Round(y);
                    //putPixel(x, iy);
                    SetPixel(x, iy, color, ref bm);
                    y += m;
                }
            }
            //tăng theo y
            else if ((m > 1 || m < -1) && y2 > y1)
            {
                double x = x1;
                int    ix;
                for (int y = y1; y <= y2; y++)
                {
                    ix = DEFINE.Round(x);
                    //putPixel(x, iy);
                    SetPixel(ix, y, color, ref bm);
                    x += (1 * infinity / m);
                }
            }
            // giảm theo x
            else if (((m >= -1 && m <= 0) || (m > 0 && m <= 1)) && x1 > x2)
            {
                double y = y1;
                int    iy;
                for (int x = x1; x >= x2; x--)
                {
                    iy = DEFINE.Round(y);
                    //putPixel(x, iy);
                    SetPixel(x, iy, color, ref bm);
                    y -= m;
                }
            }
            // giảm theo y
            else if ((m > 1 || m < -1) && y1 > y2)
            {
                double x = x1;
                int    ix;
                for (int y = y1; y >= y2; y--)
                {
                    ix = DEFINE.Round(x);
                    SetPixel(ix, y, color, ref bm);
                    x -= (1 * infinity / m);
                }
            }
        }