Turbulence simulation

what are “?” and “:” for in front of Math.?

I didn’t write that part so I am not used with the notatiob. It must be Linq notation that replaced if then. So one line instead if 7 lines.

1 Like

The ternary operator ‘a ? b : c’ is a convenient way of writing a conditional in one line

(it’s standard in C#, doesn’t need LINQ)

3 Likes

Someone code a 3d version.

Could you help me explain what is condition in the code? is for get a float number?

if(Math.Abs(end.X - start.X) > Math.Abs(end.Y - start.Y))
{
count = Math.Abs(i1 - i0);
}
else
{
count = Math.Abs(j1 - j0);
}

1 Like

Hi @laurent_delrieu , thanks for sharing your code.

I’ve tweak it a bit to get the colors out, so I can build a bitmap with it using BitmapPlus. However the excecution times tripled ( 3 x)

Can you tell this noob why? Everyting is allreay computed, i am just adding the colors to the list for export
my tweaks

B = s.DrawGraphicsMesh(); // Get the list of colors
public List<Color> DrawGraphicsMesh()
    {
      List<Color> colorList = new List<Color>();

      for (int i = 0; i < gridSize; i++)
      {
        for (int j = 0; j < gridSize; j++)
        {
          int c = ToColor(d[idx(i, j)]);
          Color color = Color.FromArgb(255, c, c, c);
          colors[idx(i, j)] = color;
          colorList.Add(color); // Add the color to the list

        }
      }

      displayMesh.VertexColors.SetColors(colors);

      return colorList; // Return the list of colors
    }

vs your code

public void DrawGraphicsMesh(IGH_PreviewArgs args)
    {

      for (int i = 0; i < gridSize; i++)
        for (int j = 0; j < gridSize; j++)
        {
          int c = ToColor(d[idx(i, j)]);
          colors[idx(i, j)] = Color.FromArgb(128, c, c, c);
        }


      displayMesh.VertexColors.SetColors(colors);
      args.Display.DrawMeshFalseColors(displayMesh);
    }

2D Smoke Turbulance Simulator_05.gh (22.3 KB)

it does what it needs to do, but extremly slow

This seems to be a classical conversion problem. Use GH_Colour instead. Input and output with GH_xxxx works best in Grasshopper.
image


    public GH_Colour[] DrawGraphicsMesh()
    {
      GH_Colour[] colorList = new GH_Colour[gridSize * gridSize];

      for (int i = 0; i < gridSize; i++)
      {
        for (int j = 0; j < gridSize; j++)
        {
          int c = ToColor(d[idx(i, j)]);
          Color color = Color.FromArgb(255, c, c, c);
          colors[idx(i, j)] = color;
          colorList[i + gridSize * j] = new GH_Colour(color);

        }
      }
      displayMesh.VertexColors.SetColors(colors);
      // Note: Removed the args.Display.DrawMeshFalseColors(displayMesh) line as we no longer have args

      return colorList; // Return the list of colors
    }
2 Likes

Hi @laurent_delrieu , Hi @crz_06 , nice to have this old post been re-activated. I all forgot this script and I recall playing with that the original gha from @LongNguyen some years back and it was fast and one could draw in realtime (as seen here Rhino/Grasshopper: Smoke Simulation in 2D - YouTube . What it lacked was to use the output in gh, so what you’ve made it already much more usefull. Thanks !!

1st question. The perceived difference in speed between the realtime version of the plugin vs 300-700ms computation in the C# node, Is that really the difference between a compiled version and an embedded C# node, or does it have to do that you are using polylines as input (a list of a multiple points) in a single pass?

That brings me to my 2nd question. Is it possible to extend the functionality of your script to support different types of geometry like curves or points, and to add logic to handle these as well.

3d question: any suggestion how to draw the turbulence in time? Now it computes the turbulance/smoke effect once. Not a animated effect, when I move the curve around. Is this something that could be implemented again?

My apologies for all the requests … i hope one day to have the coding skills to do this myself. I’ve been trying all night to try this with my coding buddy ChatGPT but quess we still need to rely on human skills for a while :wink:

Thank @laurent_delrieu and @LongNguyen for providing simulation code.
@crz_06 and @Chris, Here is my altered version. Copy DM folder to grasshopper Libraries folder. and then run “smoke.gh”
DM1.9.rar (18.6 MB)
smoke.gh (18.2 KB)

4 Likes

just WOW !!! I it’s just everything i imagined to do.

This prerelease of SurfaceRelief looks so exciting, i am just scanning through the new nodes and i can’t what till you release the 1.9 version

Out of curiousty, was this Smoke fx already part of SRelief, or did you just added it for us?

The SurfaceRelief plugin is going to be renamed as DesignMaster which is a backpack of many existing tools. DesignMaster will support both pc and Mac. Later I will upgrade your SurfaceRelief lic to DesignMaster.
I just added smoke function to DM libray two weeks ago. But user interface was implement for this post so you guys can easly use.

1 Like