<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #msafluid - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23msafluid</link>
      <pubDate>Sun, 08 Aug 2021 20:47:13 +0000</pubDate>
         <description>Tagged with #msafluid - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23msafluid/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Combining the MSAFluid with DepthPointCloud (Kinect2 / Mac)</title>
      <link>https://forum.processing.org/two/discussion/25715/combining-the-msafluid-with-depthpointcloud-kinect2-mac</link>
      <pubDate>Mon, 25 Dec 2017 22:17:28 +0000</pubDate>
      <dc:creator>unknownplayer</dc:creator>
      <guid isPermaLink="false">25715@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>Hello, first post here! I have a rather complicated question it seems. Basically I'm trying to combine MSAFluid sketch and the OpenKinect's DepthPointCloud sketch so that each vertex there will be a emitter of MSAFluid.</p>

<p>I've seen examples like this <span class="VideoWrap"><span class="Video YouTube" id="youtube-FnulH8TrZVo"><span class="VideoPreview"><a href="http://youtube.com/watch?v=FnulH8TrZVo"><img src="http://img.youtube.com/vi/FnulH8TrZVo/0.jpg" width="640" height="385" border="0" /></a></span><span class="VideoPlayer"></span></span></span> which were done with previous libraries and kinect versions - so, now I really want to accomplish this with my Kinect2 and on Processing 3 on my Mac.</p>

<p>You can see the js version of MSAFluid here, also the code is there;
<a href="https://www.openprocessing.org/sketch/95408" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/95408</a></p>

<p>And the DepthPointCloud code;
<a href="https://github.com/shiffman/OpenKinect-for-Processing/tree/master/OpenKinect-Processing/examples/Kinect_v2/DepthPointCloud2" target="_blank" rel="nofollow">https://github.com/shiffman/OpenKinect-for-Processing/tree/master/OpenKinect-Processing/examples/Kinect_v2/DepthPointCloud2</a></p>

<p>Already, thank you for trying to help out! I've seen many posts about this but they are all very old and not helpful in this situation. I really think I can move forward with a little guidance.</p>

<hr />

<p>The solution seems pretty basic actually. Just replace the;</p>

<pre><code>// Draw a point
vertex(point.x, point.y, point.z);
</code></pre>

<p>in the draw function (line 82) with the particlesystem (from the MSAFluid) so it would create an emitter where there is a vertex and it should work. Doesn't it? Though, I have tried this and it didn't work, maybe did it the wrong way, not sure. The problem I guess is that once I move in front of the camera vertex doesn't move unlike the mouse, it just shows another vertex which already is there but not displayed, is this logic correct? I mean how can manage this like shown on the video above, I just want each vertex created in the for loop to emit this fluid particles in the force of my movement.</p>

<p>Many thanks!</p>
]]></description>
   </item>
   <item>
      <title>MSAFLuids examples update</title>
      <link>https://forum.processing.org/two/discussion/4043/msafluids-examples-update</link>
      <pubDate>Sun, 30 Mar 2014 21:03:31 +0000</pubDate>
      <dc:creator>thomaslengeling</dc:creator>
      <guid isPermaLink="false">4043@/two/discussions</guid>
      <description><![CDATA[<p>Hello.</p>

<p>I forgot the post this, but a couple of months ago I updated the MSAFluids examples for processing 2.1. There was some openGL calls needed to be updated. I made a push request to the main one repository.</p>

<p><a href="https://github.com/ThomasLengeling/p5-MSAFluid" target="_blank" rel="nofollow">https://github.com/ThomasLengeling/p5-MSAFluid</a></p>

<p>Thomas.</p>
]]></description>
   </item>
   <item>
      <title>Msafluid Cuts Out, SimpleopenNI</title>
      <link>https://forum.processing.org/two/discussion/10762/msafluid-cuts-out-simpleopenni</link>
      <pubDate>Tue, 12 May 2015 06:24:06 +0000</pubDate>
      <dc:creator>Shaker</dc:creator>
      <guid isPermaLink="false">10762@/two/discussions</guid>
      <description><![CDATA[<p>I am having some trouble getting processing to continue drawing a fluid effect on the kinect skeleton. I have a sketch that uses the kinect and msafluid, but I am having a problem where the fluid effect will cut out for no reason then sometimes pick back up. I think the issue has to do with too many users being recognized but could be way wrong. Has anyone experienced this issue. I'm on OS X 10.10.</p>

<p>I figure to solve this I could limit the number of users to one instead of the default 12-14?  The code I made limits the users that are drawn but allows the user list to build in the background.</p>

<p>// draw the skeleton if it's available
int g;<br />
for (g=1; g&lt;=1; g++)</p>

<p>if(context.isTrackingSkeleton(g))</p>

<p>drawSkeleton(g);</p>

<p>I am not getting any errors and the kinect is still tracking the skeleton when it cuts out. Is there any way to get a more in-depth look at whats going on when the effect cuts out. Still pretty new at this, any help is greatly appreciated.</p>
]]></description>
   </item>
   <item>
      <title>Stop Particles From Being Erased</title>
      <link>https://forum.processing.org/two/discussion/10683/stop-particles-from-being-erased</link>
      <pubDate>Thu, 07 May 2015 05:34:43 +0000</pubDate>
      <dc:creator>Shaker</dc:creator>
      <guid isPermaLink="false">10683@/two/discussions</guid>
      <description><![CDATA[<p>I'm pretty new at this so please excuse my bad terminology. I have a project that requires every frame to be redrawn for the animation of particles and fluid then to fade them after creation but I want to add a background particle effect that every particle stays on the screen until the sketch is stopped. I have everything working and appearing on screen but the background branching particle effect is redrawn and thus only the newest particles appear and unfortunately overlay the animated particles.</p>

<p>Is there any way to draw the background branch particles behind the fluid and to keep them from being erased every frame without effecting the fluid fade?</p>
]]></description>
   </item>
   <item>
      <title>How to use shader as background for another piece of code?</title>
      <link>https://forum.processing.org/two/discussion/8014/how-to-use-shader-as-background-for-another-piece-of-code</link>
      <pubDate>Fri, 07 Nov 2014 15:49:44 +0000</pubDate>
      <dc:creator>lisaleave</dc:creator>
      <guid isPermaLink="false">8014@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to blend the MsaFluid particle with a shader background.
Right now I am kinda using the stupidest way, I sent both images to maxMSP using Syphon and blend them in max.</p>

<p>I know usually the fluid runs on a PImage, but the particle system in MsaFluid is another class using some parameters from the fluid and I don't have a lot of understanding to it. 
For the shader part I just found out how to load it using PShader, and have no idea what's that.</p>

<p>Other than that I have no idea how to start.</p>
]]></description>
   </item>
   <item>
      <title>How to change the background in MSA Fluid?</title>
      <link>https://forum.processing.org/two/discussion/2935/how-to-change-the-background-in-msa-fluid</link>
      <pubDate>Sun, 09 Feb 2014 07:14:36 +0000</pubDate>
      <dc:creator>chickyboo</dc:creator>
      <guid isPermaLink="false">2935@/two/discussions</guid>
      <description><![CDATA[<p>Hello there,</p>

<p>I would like to know how to change the background of MSAfluid. Been trying to figure it out all week but I am defeated. Any help is much appreciated.</p>

<p>TIA</p>

<h2>MSAfluid</h2>

<pre><code>import msafluid.*;

import processing.opengl.*;
import javax.media.opengl.*;

import TUIO.*;

final float FLUID_WIDTH = 120;

float invWidth, invHeight;    // inverse of screen dimensions
float aspectRatio, aspectRatio2;

MSAFluidSolver2D fluidSolver;

ParticleSystem particleSystem;

PImage imgFluid;

boolean drawFluid = true;

void setup() {

    size(960, 640, OPENGL);    // use OPENGL rendering for bilinear filtering on texture
//    size(screen.width * 49/50, screen.height * 49/50, OPENGL);
    hint( ENABLE_OPENGL_4X_SMOOTH );    // Turn on 4X antialiasing

    invWidth = 1.0f/width;
    invHeight = 1.0f/height;
    aspectRatio = width * invHeight;
    aspectRatio2 = aspectRatio * aspectRatio;

    // create fluid and set options
    fluidSolver = new MSAFluidSolver2D((int)(FLUID_WIDTH), (int)(FLUID_WIDTH * height/width));
    fluidSolver.enableRGB(true).setFadeSpeed(0.003).setDeltaT(0.5).setVisc(0.0001);

    // create image to hold fluid picture
    imgFluid = createImage(fluidSolver.getWidth(), fluidSolver.getHeight(), RGB);

    // create particle system
    particleSystem = new ParticleSystem();

    // init TUIO
    initTUIO();

 }


void mouseMoved() {
    float mouseNormX = mouseX * invWidth;
    float mouseNormY = mouseY * invHeight;
    float mouseVelX = (mouseX - pmouseX) * invWidth;
    float mouseVelY = (mouseY - pmouseY) * invHeight;

    addForce(mouseNormX, mouseNormY, mouseVelX, mouseVelY);
}

void draw() {
    updateTUIO();
    fluidSolver.update();

    if(drawFluid) {

        imgFluid.updatePixels();//  fastblur(imgFluid, 2);
        image(imgFluid, 0, 0, width, height);
    } 

    particleSystem.updateAndDraw();

}

void mousePressed() {
    drawFluid ^= true;

}

void keyPressed() {
    switch(key) {
    case 'r': 
        renderUsingVA ^= true; 
        println("renderUsingVA: " + renderUsingVA);
        break;
    }
}



// add force and dye to fluid, and create particles
void addForce(float x, float y, float dx, float dy) {
    float speed = dx * dx  + dy * dy * aspectRatio2;    // balance the x and y components of speed with the screen aspect ratio

    if(speed &gt; 0) {
        if(x&lt;0) x = 0; 
        else if(x&gt;1) x = 1;
        if(y&lt;0) y = 0; 
        else if(y&gt;1) y = 1;

        float colorMult = 5;
        float velocityMult = 30.0f;

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

        color drawColor;

        colorMode(HSB, 360, 1, 1);
        float hue = ((x + y) * 180 + frameCount) % 360;
        drawColor = color(hue, 1, 1);
        colorMode(RGB, 1);  

        fluidSolver.rOld[index]  += red(drawColor) * colorMult;
        fluidSolver.gOld[index]  += green(drawColor) * colorMult;
        fluidSolver.bOld[index]  += blue(drawColor) * colorMult;

        particleSystem.addParticles(x * width, y * height, 100);
        fluidSolver.uOld[index] += dx * velocityMult;
        fluidSolver.vOld[index] += dy * velocityMult;

    }
}
</code></pre>

<h2>Particle</h2>

<pre><code>class Particle {
    final static float MOMENTUM = 0.5;
    final static float FLUID_FORCE = 0.6;

    float x, y;
    float vx, vy;
    float radius;       // particle's size
    float alpha;
    float mass;

    void init(float x, float y) {
        this.x = x;
        this.y = y;
        vx = 0;
        vy = 0;
        radius = 5;
        alpha  = random(0.3, 1);
        mass = random(0.1, 1);
    }


    void update() {
        // only update if particle is visible
        if(alpha == 0) return;

        // read fluid info and add to velocity
        int fluidIndex = fluidSolver.getIndexForNormalizedPosition(x * invWidth, y * invHeight);
        vx = fluidSolver.u[fluidIndex] * width * mass * FLUID_FORCE + vx * MOMENTUM;
        vy = fluidSolver.v[fluidIndex] * height * mass * FLUID_FORCE + vy * MOMENTUM;

        // update position
        x += vx;
        y += vy;

        // bounce of edges
        if(x&lt;0) {
            x = 0;
            vx *= -1;
        }
        else if(x &gt; width) {
            x = width;
            vx *= -1;
        }

        if(y&lt;0) {
            y = 0;
            vy *= -1;
        }
        else if(y &gt; height) {
            y = height;
            vy *= -1;
        }

        // hackish way to make particles glitter when the slow down a lot
        if(vx * vx + vy * vy &lt; 1) {
            vx = random(-1, 1);
            vy = random(-1, 1);
        }

        // fade out a bit (and kill if alpha == 0);
        alpha *= 0.999;
        if(alpha &lt; 0.01) alpha = 0;

    }


    void updateVertexArrays(int i, FloatBuffer posBuffer, FloatBuffer colBuffer) {
        int vi = i * 4;
        posBuffer.put(vi++, x - vx);
        posBuffer.put(vi++, y - vy);
        posBuffer.put(vi++, x);
        posBuffer.put(vi++, y);

        int ci = i * 6;
        colBuffer.put(ci++, alpha);
        colBuffer.put(ci++, alpha);
        colBuffer.put(ci++, alpha);
        colBuffer.put(ci++, alpha);
        colBuffer.put(ci++, alpha);
        colBuffer.put(ci++, alpha);
    }


    void drawOldSchool(GL gl) {
        gl.glColor3f(alpha, alpha, alpha);
        gl.glVertex2f(x-vx, y-vy);
        gl.glVertex2f(x, y);
    }

}
</code></pre>

<h2>ParticleSystem</h2>

<pre><code>import java.nio.FloatBuffer;
import com.sun.opengl.util.*;

boolean renderUsingVA = true;


void fadeToColor(GL gl, float r, float g, float b, float speed) {
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    gl.glColor4f(r, g, b, speed);
    gl.glBegin(GL.GL_QUADS);
    gl.glVertex2f(0, 0);
    gl.glVertex2f(width, 0);
    gl.glVertex2f(width, height);
    gl.glVertex2f(0, height);
    gl.glEnd();
}




class ParticleSystem {
    FloatBuffer posArray;
    FloatBuffer colArray;

    final static int maxParticles = 5000;
    int curIndex;

    Particle[] particles;

    ParticleSystem() {
        particles = new Particle[maxParticles];
        for(int i=0; i&lt;maxParticles; i++) particles[i] = new Particle();
        curIndex = 0;

        posArray = BufferUtil.newFloatBuffer(maxParticles * 2 * 2);// 2 coordinates per point, 2 points per particle (current and previous)
        colArray = BufferUtil.newFloatBuffer(maxParticles * 3 * 2);
    }


    void updateAndDraw(){
        PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;         // processings opengl graphics object
        GL gl = pgl.beginGL();                // JOGL's GL object

        gl.glEnable( GL.GL_BLEND );             // enable blending
        if(!drawFluid) fadeToColor(gl, 0, 0, 0, 0.05);

        gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);  // additive blending (ignore alpha)
        gl.glEnable(GL.GL_LINE_SMOOTH);        // make points round
        gl.glLineWidth(1);


        if(renderUsingVA) {
            for(int i=0; i&lt;maxParticles; i++) {
                if(particles[i].alpha &gt; 0) {
                    particles[i].update();
                    particles[i].updateVertexArrays(i, posArray, colArray);
                }
            }    
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glVertexPointer(2, GL.GL_FLOAT, 0, posArray);

            gl.glEnableClientState(GL.GL_COLOR_ARRAY);
            gl.glColorPointer(3, GL.GL_FLOAT, 0, colArray);

            gl.glDrawArrays(GL.GL_LINES, 0, maxParticles * 2);
        } 
        else {
            gl.glBegin(GL.GL_LINES);               // start drawing points
            for(int i=0; i&lt;maxParticles; i++) {
                if(particles[i].alpha &gt; 0) {
                    particles[i].update();
                    particles[i].drawOldSchool(gl);    // use oldschool renderng
                }
            }
            gl.glEnd();
        }

        gl.glDisable(GL.GL_BLEND);
        pgl.endGL();
    }


    void addParticles(float x, float y, int count ){
        for(int i=0; i&lt;count; i++) addParticle(x + random(-15, 15), y + random(-15, 15));
    }


    void addParticle(float x, float y) {
        particles[curIndex].init(x, y);
        curIndex++;
        if(curIndex &gt;= maxParticles) curIndex = 0;
    }

}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>