Exemplo n.º 1
0
        void Seed()
        {
            // Add cells at random places
            for (int i = 0; i < maxcells; i++)
            {
                int cX = RandomEx.Random(this.Width);
                int cY = RandomEx.Random(this.Height);

                int   clr;
                float r = RandomEx.Random();
                if (r < 0.25)
                {
                    clr = Spore1;
                }
                else if (r < 0.5)
                {
                    clr = Spore2;
                }
                else if (r < 0.75)
                {
                    clr = Spore3;
                }
                else
                {
                    clr = Spore4;
                }

                if (this.GetPixelInt(cX, cY) == this.BgColor)
                {
                    this.SetPixelInt(cX, cY, clr);
                    cells[numcells] = new Cell(cX, cY, this);
                    numcells++;
                }
            }
        }
Exemplo n.º 2
0
 public override void UpdateCanvas()
 {
     // Run cells in random order
     for (int i = 0; i < runs_per_loop; i++)
     {
         int selected = RandomEx.Random(numcells);                 //, numcells-1);
         cells[selected].Run();
     }
 }
Exemplo n.º 3
0
            public void Init()
            {
                //x = smoke.Width/2+RandomEx.Random(-20f,20f);
                //y = RandomEx.Random((float)smoke.Height-10f,(float)smoke.Height);
                x = RandomEx.Random((float)emitter.Left, (float)emitter.Right);
                y = RandomEx.Random((float)emitter.Top, (float)emitter.Bottom);

                color = smoke.CurrentColor;                 //new Endogine.ColorEx.ColorHsb(2, 0,1,1).ToColor();

                xvel = RandomEx.Random(-1f, 1f);
                yvel = RandomEx.Random(-1f, 1f);
            }
Exemplo n.º 4
0
            public void updatepos()
            {
                float res = smoke.res;
                int   vi  = (int)(x / smoke.res);
                int   vu  = (int)(y / smoke.res);

                if (vi > 0 && vi < smoke.lwidth && vu > 0 && vu < smoke.lheight)
                {
                    smoke.v[vi][vu].addcolour(this.color);

                    float ax = (x % smoke.res) / smoke.res;
                    float ay = (y % smoke.res) / smoke.res;

                    xvel += (1 - ax) * smoke.v[vi][vu].xvel * 0.05f;
                    yvel += (1 - ay) * smoke.v[vi][vu].yvel * 0.05f;

                    xvel += ax * smoke.v[vi + 1][vu].xvel * 0.05f;
                    yvel += ax * smoke.v[vi + 1][vu].yvel * 0.05f;

                    xvel += ay * smoke.v[vi][vu + 1].xvel * 0.05f;
                    yvel += ay * smoke.v[vi][vu + 1].yvel * 0.05f;

                    smoke.v[vi][vu].yvel     -= (1 - ay) * 0.003f;
                    smoke.v[vi + 1][vu].yvel -= ax * 0.003f;

                    if (smoke.v[vi][vu].yvel < 0)
                    {
                        smoke.v[vi][vu].yvel *= 1.00025f;
                    }

                    x += xvel;
                    y += yvel;
                }
                else
                {
                    this.Init();
                }

                if (RandomEx.Random(0, 400) < 1)
                {
                    this.Init();
                }

                xvel *= 0.6f;
                yvel *= 0.6f;
            }
Exemplo n.º 5
0
 public static float Random(float from, float to)
 {
     return(RandomEx.Random(to - from) + from);
 }
Exemplo n.º 6
0
 public static int Random(int from, int to)
 {
     return(RandomEx.Random(to - from) + from);
 }
Exemplo n.º 7
0
 public Canvas() : base()
 {
     RandomEx.Init();
 }
Exemplo n.º 8
0
            // Perform action based on surroundings
            public void Run()
            {
                cv.AssertPoint(ref x, ref y);

                // Cell instructions
                int myColor = cv.GetPixel(x, y);

                if (myColor == cv.Spore1)
                {
                    if (cv.GetPixel(x - 1, y + 1) == cv.BgColor && cv.GetPixel(x + 1, y + 1) == cv.BgColor && cv.GetPixel(x, y + 1) == cv.BgColor)
                    {
                        Move(0, 1);
                    }
                    else if (cv.GetPixel(x - 1, y) == cv.Spore2 && cv.GetPixel(x - 1, y - 1) != cv.BgColor)
                    {
                        Move(0, -1);
                    }
                    else if (cv.GetPixel(x - 1, y) == cv.Spore2 && cv.GetPixel(x - 1, y - 1) == cv.BgColor)
                    {
                        Move(-1, -1);
                    }
                    else if (cv.GetPixel(x + 1, y) == cv.Spore1 && cv.GetPixel(x + 1, y - 1) != cv.BgColor)
                    {
                        Move(0, -1);
                    }
                    else if (cv.GetPixel(x + 1, y) == cv.Spore1 && cv.GetPixel(x + 1, y - 1) == cv.BgColor)
                    {
                        Move(1, -1);
                    }
                    else
                    {
                        Move(RandomEx.Random(3) - 1, 0);
                    }
                }
                else if (myColor == cv.Spore2)
                {
                    if (cv.GetPixel(x - 1, y + 1) == cv.BgColor && cv.GetPixel(x + 1, y + 1) == cv.BgColor && cv.GetPixel(x, y + 1) == cv.BgColor)
                    {
                        Move(0, 1);
                    }
                    else if (cv.GetPixel(x + 1, y) == cv.Spore1 && cv.GetPixel(x + 1, y - 1) != cv.BgColor)
                    {
                        Move(0, -1);
                    }
                    else if (cv.GetPixel(x + 1, y) == cv.Spore1 && cv.GetPixel(x + 1, y - 1) == cv.BgColor)
                    {
                        Move(1, -1);
                    }
                    else if (cv.GetPixel(x - 1, y) == cv.Spore2 && cv.GetPixel(x - 1, y - 1) != cv.BgColor)
                    {
                        Move(0, -1);
                    }
                    else if (cv.GetPixel(x - 1, y) == cv.Spore2 && cv.GetPixel(x - 1, y - 1) == cv.BgColor)
                    {
                        Move(-1, -1);
                    }
                    else
                    {
                        Move(RandomEx.Random(3) - 1, 0);
                    }
                }
                else if (myColor == cv.Spore3)
                {
                    if (cv.GetPixel(x - 1, y - 1) == cv.BgColor && cv.GetPixel(x + 1, y - 1) == cv.BgColor && cv.GetPixel(x, y - 1) == cv.BgColor)
                    {
                        Move(0, -1);
                    }
                    else if (cv.GetPixel(x - 1, y) == cv.Spore4 && cv.GetPixel(x - 1, y + 1) != cv.BgColor)
                    {
                        Move(0, 1);
                    }
                    else if (cv.GetPixel(x - 1, y) == cv.Spore4 && cv.GetPixel(x - 1, y + 1) == cv.BgColor)
                    {
                        Move(-1, 1);
                    }
                    else if (cv.GetPixel(x + 1, y) == cv.Spore3 && cv.GetPixel(x + 1, y + 1) != cv.BgColor)
                    {
                        Move(0, 1);
                    }
                    else if (cv.GetPixel(x + 1, y) == cv.Spore3 && cv.GetPixel(x + 1, y + 1) == cv.BgColor)
                    {
                        Move(1, 1);
                    }
                    else
                    {
                        Move(RandomEx.Random(3) - 1, 0);
                    }
                }
                else if (myColor == cv.Spore4)
                {
                    if (cv.GetPixel(x - 1, y - 1) == cv.BgColor && cv.GetPixel(x + 1, y - 1) == cv.BgColor && cv.GetPixel(x, y - 1) == cv.BgColor)
                    {
                        Move(0, -1);
                    }
                    else if (cv.GetPixel(x + 1, y) == cv.Spore3 && cv.GetPixel(x + 1, y + 1) != cv.BgColor)
                    {
                        Move(0, 1);
                    }
                    else if (cv.GetPixel(x + 1, y) == cv.Spore3 && cv.GetPixel(x + 1, y + 1) == cv.BgColor)
                    {
                        Move(1, 1);
                    }
                    else if (cv.GetPixel(x - 1, y) == cv.Spore4 && cv.GetPixel(x - 1, y + 1) != cv.BgColor)
                    {
                        Move(0, 1);
                    }
                    else if (cv.GetPixel(x - 1, y) == cv.Spore4 && cv.GetPixel(x - 1, y + 1) == cv.BgColor)
                    {
                        Move(-1, 1);
                    }
                    else
                    {
                        Move(RandomEx.Random(3) - 1, 0);
                    }
                }
            }
Exemplo n.º 9
0
        public override void UpdateCanvas()
        {
            Endogine.ColorEx.ColorHsb clr = new Endogine.ColorEx.ColorHsb(CurrentColor);
            clr.H += 1f;
            if (clr.H > 360)
            {
                clr.H -= 360;
            }
            CurrentColor = clr.ColorRGBA;

            this.Clear(Color.Black);
            int axvel = this.MouseLoc.X - this.MouseLastLoc.X;
            int ayvel = this.MouseLoc.Y - this.MouseLastLoc.Y;

            mouseXvel = (axvel != mouseXvel) ? axvel : 0;
            mouseYvel = (ayvel != mouseYvel) ? ayvel : 0;

            if (RandomGust.Alive)
            {
                RandomGust.Update();
            }
            else
            {
                if (RandomEx.Random(0, 10) == 0)
                {
                    RandomGust.SetLife(RandomEx.Random(1, 20));
                    RandomGust.Loc = new EPointF(RandomEx.Random(0f, (float)this.Width),
                                                 RandomEx.Random(0f, this.Height - 10)); //TODO above emitter, not fixed value!

                    float   fact = 0.3f * this.Width / 200;
                    EPointF vel  = new EPointF(RandomEx.Random(0f, 8f) * fact, RandomEx.Random(-2f, 1f) * fact);
                    if (RandomGust.Loc.X > this.Width / 2)
                    {
                        vel.X *= -1;
                    }
                    RandomGust.Vel = vel;

                    RandomGust.Size = RandomEx.Random(0f, 50f) * this.Width / 200;
                }
                //randomGust--;
            }

            for (int i = 0; i < lwidth; i++)
            {
                for (int u = 0; u < lheight; u++)
                {
                    vbuf[i][u].updatebuf(i, u);
                    v[i][u].Refresh();
                }
            }
            for (int i = 0; i < pnum - 1; i++)
            {
                p[i].updatepos();
            }
            for (int i = 0; i < lwidth; i++)
            {
                for (int u = 0; u < lheight; u++)
                {
                    v[i][u].addbuffer(i, u);
                    v[i][u].updatevels(mouseXvel, mouseYvel);
                    v[i][u].display(i, u);
                }
            }
            //randomGust = 0;
        }