Exemple #1
0
    public void addColor(float x, float y, colorP5 drawColor, float colorMult)
    {
        int index = fluidSolver.getIndexForNormalizedPosition(x, y);

        fluidSolver.rOld [index] += red(drawColor) * colorMult;
        fluidSolver.gOld [index] += green(drawColor) * colorMult;
        fluidSolver.bOld [index] += blue(drawColor) * colorMult;
    }
Exemple #2
0
    public void addForceCircle(float x, float y, float force, colorP5 drawColor, int particleNum, float forceRange)
    {
        float speed = force * force + force * force * aspectRatio2;

        if (speed > 0)
        {
            int     _NX     = fluidSolver._NX;
            int     _NY     = fluidSolver._NY;
            float[] u       = fluidSolver.u;
            float[] v       = fluidSolver.v;
            float   marginW = 1.0f / (float)(_NX + 2);
            float   marginH = 1.0f / (float)(_NY + 2);

            float colorMult    = 0.1f;
            float velocityMult = 1.5f;

            Vector2 forcePt = new Vector2(x, y / aspectRatio);
            for (int i = 2; i < _NX; i++)
            {
                for (int j = 2; j < _NY; j++)
                {
                    int index = fluidSolver.FLUID_IX(i, j);

                    Vector2 pt   = new Vector2(marginW * i, marginH * j / aspectRatio);
                    float   dist = Vector2.Distance(forcePt, pt);
                    if (dist > 0.01f && dist < forceRange)
                    {
                        Vector2 direction = pt - forcePt;
                        direction = direction.normalized;

                        fluidSolver.uOld [index] += force * direction.x * velocityMult * (1 - dist / forceRange);
                        fluidSolver.vOld [index] += force * direction.y * velocityMult * (1 - dist / forceRange);
                    }
                    else
                    {
                        fluidSolver.uOld [index] *= 0.9f;
                        fluidSolver.vOld [index] *= 0.9f;
                    }
                }
            }

            if (force > 0)
            {
                int indexColorEmit = fluidSolver.getIndexForNormalizedPosition(x, y);
                fluidSolver.rOld [indexColorEmit] += red(drawColor) * colorMult;
                fluidSolver.gOld [indexColorEmit] += green(drawColor) * colorMult;
                fluidSolver.bOld [indexColorEmit] += blue(drawColor) * colorMult;

                float   range     = Random.Range(5, 10) * 2.0f;           // 0-60
                Vector2 randomPos = Random.insideUnitCircle * 0.05f;
                p5particleSystem.addParticles((x + randomPos.x) * width, (y + randomPos.y) * height, particleNum, drawColor.m_color, range);
            }
        }
    }
Exemple #3
0
    public void addForceCircle2(float x, float y, float force, colorP5 drawColor, int particleNum)
    {
        float speed = force * force + force * force * aspectRatio2;

        if (speed > 0)
        {
            float range     = 0.15f;
            float split     = 18;
            float distSplit = 2;

            float splitRad  = Mathf.PI * 2 / split;
            float splitDist = range / distSplit;

            //float offsetRad = Random.value * Mathf.PI*2;
            float offsetRad = Time.time * 0.1f;
            for (int i = 0; i < split; i++)
            {
                for (int j = 1; j < distSplit; j++)
                {
                    float rndForce = force * Random.value;
                    float rad      = splitRad * i + offsetRad;

                    float dist = splitDist * j;
                    float tx   = x + dist * Mathf.Cos(rad);
                    float ty   = y + dist * Mathf.Sin(rad);

                    float tdx = rndForce * Mathf.Cos(rad);
                    float tdy = rndForce * Mathf.Sin(rad) * aspectRatio;
                    addForce(tx, ty, tdx, tdy, drawColor, 0);                     // no Particle emit;
                }
            }

            if (force > 0)
            {
                float colorMult      = 5;
                int   indexColorEmit = fluidSolver.getIndexForNormalizedPosition(x, y);
                fluidSolver.rOld [indexColorEmit] += red(drawColor) * colorMult;
                fluidSolver.gOld [indexColorEmit] += green(drawColor) * colorMult;
                fluidSolver.bOld [indexColorEmit] += blue(drawColor) * colorMult;

                p5particleSystem.addParticles(x * width, y * height, particleNum, drawColor.m_color, 100);
            }
        }
    }
Exemple #4
0
    public void addForce(float x, float y, float dx, float dy, colorP5 drawColor, int particleNum, float colorMult, float randomRange)
    {
        float speed = dx * dx + dy * dy * aspectRatio2;            // balance the x and y components of speed with the screen aspect ratio

        if (speed > 0)
        {
            if (x < 0)
            {
                x = 0;
            }
            else if (x > 1)
            {
                x = 1;
            }
            if (y < 0)
            {
                y = 0;
            }
            else if (y > 1)
            {
                y = 1;
            }

            //float colorMult = 5;
            float velocityMult = 30.0f;

            int index = fluidSolver.getIndexForNormalizedPosition(x, y);

            if (particleNum > 0)
            {
                fluidSolver.rOld [index] += red(drawColor) * colorMult;
                fluidSolver.gOld [index] += green(drawColor) * colorMult;
                fluidSolver.bOld [index] += blue(drawColor) * colorMult;

                p5particleSystem.addParticles(x * width, y * height, particleNum, drawColor.m_color, randomRange);
            }

            fluidSolver.uOld [index] += dx * velocityMult;
            fluidSolver.vOld [index] += dy * velocityMult;
        }
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            if (Physics.Raycast(ray, out hitInfo))
            {
                Vector3 hitPos      = hitInfo.point;
                Vector3 localHitPos = hitInfo.transform.InverseTransformPoint(hitPos);
                //
                float x = 1.0f - (localHitPos.x + 5.0f) / 10.0f;
                float y = 1.0f - (localHitPos.z + 5.0f) / 10.0f;

                float mouseVelX = x - pmouseX;
                float mouseVelY = y - pmouseY;

                if (!mouseDown)
                {
                    mouseVelX = 0;
                    mouseVelY = 0;
                    mouseDown = true;
                }

                float   hue       = ((x + y) * 180 + Time.time) % 360;
                colorP5 drawColor = fluid.colorHue(hue, 1, 1);

                fluid.addForce(x, y, mouseVelX * mouseMoveV, mouseVelY * mouseMoveV, drawColor, (int)(emitCount * Time.deltaTime * 30));

                pmouseX = x;
                pmouseY = y;
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            mouseDown = false;
        }
    }
Exemple #6
0
 public float red(colorP5 color)
 {
     return(color.m_color.r);
 }
Exemple #7
0
 public static Color ToColor(colorP5 colorP5_)
 {
     return(colorP5_.m_color);
 }
Exemple #8
0
 //
 public static Color ConvColor(colorP5 cP5)
 {
     return(cP5.m_color);
 }
 public static Color[] ConvColors(colorP5[] cP5s)
 {
     Color[] colors = new Color[cP5s.Length];
     for (int i = 0; i < cP5s.Length; i++) {
         colors [i] = ConvColor (cP5s [i]);
     }
     return colors;
 }
Exemple #10
0
 public float red(colorP5 color)
 {
     return color.m_color.r;
 }
Exemple #11
0
 public static Color ToColor(colorP5 colorP5_)
 {
     return colorP5_.m_color;
 }
Exemple #12
0
 public float green(colorP5 color)
 {
     return color.m_color.g;
 }
Exemple #13
0
 public float blue(colorP5 color)
 {
     return color.m_color.b;
 }
Exemple #14
0
 public static Color32[] ConvColors32(colorP5[] cP5s)
 {
     Color32[] colors = new Color32[cP5s.Length];
     for (int i = 0; i < cP5s.Length; i++) {
         colors [i] = (Color32)(cP5s [i].m_color);
     }
     return colors;
 }
Exemple #15
0
 public float green(colorP5 color)
 {
     return(color.m_color.g);
 }
Exemple #16
0
 public void addForce(float x, float y, float dx, float dy, colorP5 drawColor, int particleNum)
 {
     addForce(x, y, dx, dy, drawColor, particleNum, colorMult);
 }
Exemple #17
0
 public float blue(colorP5 color)
 {
     return(color.m_color.b);
 }
Exemple #18
0
 //
 public static Color ConvColor(colorP5 cP5)
 {
     return cP5.m_color;
 }