Exemplo n.º 1
0
        private int Threaded_Draw(int start, int end, Engine.Threading.ParamList paramList)
        {
            int y = (int)paramList.Get("y").Value;

            int offset = Engine.Surface.Ops.GetGridOffset(start, y, t_imageSource.Width, t_imageSource.Height);

            for (int x = start; x < end; x++)
            {
                b1_1[offset] = t_buffer_1.GetFluidAmount(x - 1, y, PixelRetrievalOptions.ReturnEdgePixel);
                b1_2[offset] = t_buffer_1.GetFluidAmount(x + 1, y, PixelRetrievalOptions.ReturnEdgePixel);
                b1_3[offset] = t_buffer_1.GetFluidAmount(x, y - 1, PixelRetrievalOptions.ReturnEdgePixel);
                b1_4[offset] = t_buffer_1.GetFluidAmount(x, y + 1, PixelRetrievalOptions.ReturnEdgePixel);
                b2_1[offset] = t_buffer_2.GetFluidAmount(x, y, PixelRetrievalOptions.ReturnEdgePixel);

                /*sum[offset] = t_buffer_1.GetFluidAmount(x - 1, y, PixelRetrievalOptions.ReturnEdgePixel) +
                 *  t_buffer_1.GetFluidAmount(x + 1, y, PixelRetrievalOptions.ReturnEdgePixel) +
                 *  t_buffer_1.GetFluidAmount(x, y - 1, PixelRetrievalOptions.ReturnEdgePixel) +
                 *  t_buffer_1.GetFluidAmount(x, y + 1, PixelRetrievalOptions.ReturnEdgePixel);
                 * sum[offset] /= 4d;
                 * sum[offset] -= t_buffer_2.GetFluidAmount(x, y, PixelRetrievalOptions.ReturnEdgePixel);
                 *
                 * t_buffer_2.SetFluidAmount(sum[offset] * t_dampening, x, y, PixelSetOptions.Ignore);*/
                offset++;
            }

            return(0);
        }
Exemplo n.º 2
0
        private int Threaded_Process(int start, int end, Engine.Threading.ParamList paramList)
        {
            Engine.Effects.Noise.IModule module = (Engine.Effects.Noise.IModule)paramList.Get(paramName_module).Value;

            double value = 0;

            // loop block : source and info at : https://libnoisedotnet.codeplex.com/downloads/get/720936
            // and http://libnoise.sourceforge.net/tutorials/tutorial8.html

            for (int y = start; y < end; y++)
            {
                for (int x = 0; x < t_imageProcessed.Width - 1; x++)
                {
                    value = (module.GetValue(x, y, 10) + 1) / 2.0;

                    if (value < 0)
                    {
                        value = 0;
                    }
                    if (value > 1.0)
                    {
                        value = 1.0;
                    }
                    byte intensity      = (byte)(value * 255.0);
                    Engine.Color.Cell c = Engine.Color.Cell.ShadeOfGray(intensity);

                    t_imageProcessed.SetPixel(c, x, y, PixelSetOptions.Ignore);
                }
            }

            return(0);
        }
Exemplo n.º 3
0
        private int Threaded_Draw(int start, int end, Engine.Threading.ParamList paramList)
        {
            t_colorVariance.Step();

            int x = (int)paramList.Get("x").Value;
            int y = (int)paramList.Get("y").Value;

            for (int i = start; i < end; i++)
            {
                t_particles[i].Update(t_attractor);

                Engine.Color.Cell px;

                if (t_useColorFromImage)
                {
                    px = t_imageSource.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnEdgePixel);
                }
                else
                {
                    px = t_colorVariance.ColorVariation;
                }

                px.Alpha = t_alpha;
                t_particles[i].Draw(t_imageSource, px);
            }

            return(0);
        }
Exemplo n.º 4
0
        private int Threaded_SetGrid(int start, int end, Engine.Threading.ParamList paramList)
        {
            int numCol = (int)paramList.Get("numCol").Value;

            for (int x = start; x < end; x++)
            {
                for (int y = 0; y < numCol; y++)
                {
                    t_cells[x, y] = new PressureGridCell(t_gridCellWidth, t_gridCellHeight);
                    t_cells[x, y].CalculateAveragePressure(t_flowField, x * t_gridCellWidth, y * t_gridCellHeight);
                }
            }

            return(0);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        private int ParticleFlow(int start, int end, Engine.Threading.ParamList lst)
        {
            Engine.Color.ColorVariance cv = new Color.ColorVariance(t_particles[0].Pixel);
            cv.SetFrequencies(500);
            cv.SetRanges(30);

            double life = 0;

            do
            {
                life = 0;

                for (int i = start; i < end; i++)
                {
                    t_particles[i].Pixel = cv.ColorVariation;
                    t_particles[i].Draw(t_imageProcessed);

                    if (t_particles[i].Life < 0)
                    {
                        continue;
                    }

                    Engine.Calc.Vector pos = t_particles[i].Position;

                    if (pos.X < 0 || pos.X >= t_imageProcessed.Width)
                    {
                        t_particles[i].Die();
                        continue;
                    }

                    if (pos.Y < 0 || pos.Y >= t_imageProcessed.Height)
                    {
                        t_particles[i].Die();
                        continue;
                    }

                    t_particles[i].Move(t_flowField[(int)t_particles[i].Position.X, (int)t_particles[i].Position.Y]);
                    life += t_particles[i].Life;
                }
            } while (life > t_particleLife);

            return(0);
        }
Exemplo n.º 6
0
        private int Threaded_CreateFlowField(int start, int end, Engine.Threading.ParamList paramList)
        {
            for (int y = start; y < end; y++)
            {
                for (int x = 0; x < t_imageSource.Width; x++)
                {
                    // initialize vectors with basic to-the-right direction
                    t_flowField[x, y] = new Engine.Calc.Vector(1, 0);

                    Engine.Color.Cell c     = t_imagePerlin.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnEdgePixel);
                    double            lum   = (double)Engine.Calc.Color.Luminance(c);
                    double            angle = (lum * 360 / 255);

                    double rad = angle * Engine.Calc.Math.DEG_TO_RAD;

                    t_flowField[x, y].X = (float)System.Math.Cos(rad);
                    t_flowField[x, y].Y = (float)System.Math.Sin(rad);
                }
            }

            return(0);
        }
Exemplo n.º 7
0
        private int Threaded_ParticleFlow(int start, int end, Engine.Threading.ParamList paramList)
        {
            int    x            = (int)paramList.Get(paramName_X).Value;
            double divSpread255 = (double)paramList.Get(paramName_divSpread255).Value;
            double divSpread2f  = (double)paramList.Get(paramName_divSpread2f).Value;

            for (int y = start; y < end; y++)
            {
                Engine.Color.Cell c     = t_imagePerlin.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnEdgePixel);
                double            lum   = (double)Engine.Calc.Color.Luminance(c);
                double            angle = (lum * divSpread255) - divSpread2f; // reduce to range from 0 to 90 (degrees) then shift to get -45 to 45 (degrees)

                double rad = angle * Engine.Calc.Math.DEG_TO_RAD;

                t_flowField[x, y].X = (float)System.Math.Cos(rad);
                t_flowField[x, y].Y = (float)System.Math.Sin(rad);

                t_particles[y].Move(t_flowField[x, y]);
            }

            return(0);
        }