» code snippets
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

code snippets

Examples for declaring Pins using attributes

This is an Input Pin of type bool (ie. 0 or 1) with a hint to the GUI that it should be operated as a Bang. And it is Single which means it is not spreadeable.

[Input("Reset", IsBang = true, IsSingle = true)]
ISpread<bool> FReset;

This is an Input Pin with minimun value 0.0 and maximum value 1.0. The Order attribute specifies the position of the pin in the node 0 will be left most 1 will be second pin from the left ...

[Input("Friction", MinValue = 0.0, MaxValue = 1.0, Order = 0)]
ISpread<double> FFriction;

This is an Input pin called My Input with Variable name FInput of type int with a default value of 2. Remember that a pin can always be reset to its default using Alt+Rightclick on the pin.

[Input("My Input", DefaultValue = 2)]
IDiffSpread<int> FInput;

Using IDiffSpread instead of ISpread allows you to check if the pins data has changed using the .IsChanged property:

if (FInput.IsChanged) 
{
//do something 
}

This is a pin of type Vector2D whose x and y default values are both 0.0

[Input("Input", DefaultValues = new double[] {0.0, 0.0})]
ISpread<Vector2D> FInput;

PinGroup vs. BinSize

A PinGroup likge eg. used in Cons (Spreads) that allows you to specify the number of inputs via a configuration pin in the Inspektor can be specified like:

[Input("Input", IsPinGroup = true)]
ISpread<ISpread<double>> FInput;

If you do the same but leave out the IsPinGroup = true instead of the configuration pin that sets the pincount you'll get a BinSize pin:

[Input("Input")]
ISpread<ISpread<double>> FInput;

More info: pin attributes

Dealing with SliceCount

Examples for getting and setting SliceCount:

Get the Maximum spread count of any of the Input pins and set it to the Output pin.

FOutput.SliceCount = SpreadMax;

Get the SliceCount of a certain Pin

FInput.SliceCount

Get the maximum SliceCount of two Pins.

var count = FInput1.CombineWith(FInput);
FOutput.SliceCount = count;

Get the minimum SliceCount from two pins.

var count = Math.Min(FInput.SliceCount, FInput1.SliceCount);
FOutput.SliceCount = count;

Spreads

Playing with List&AssignFrom

List are a convinient way to play with dynamic spreads ,you can add , remove ,insert and much more...
you need to add this : using System.Collections.Generic; to your code .
There are many examples on the net you will find some nice ones in dotnetperls

// we make a new list and called it myList 
      List<int> myList = new List<int>();

We make some logic with it

// If the Pin Add is Bang the spread from the Input Pin gets in .
            if (FAdd[0])
            {
              myList.Clear();// We clear the List here to start all over otherwise we,ll add a new spread each time we bang .
 
             // Here we get the spread from Input Pin in 
             // so loop as many times as the size of the spread to get it
 
            for (int i = 0; i < FInput.SliceCount; i++)
              {
                myList.Add(FInput[i]);
              }
 
            //here we add some more logic ,If spread contains the value in the filter pin 
            //we remove all occurances in the spread of this value.
            if (myList.Contains(FFilter[0]))
              {
            myList.RemoveAll(item => item == FFilter[0]);
              }
 
            // some more we want to add a value on top of the list and at the end 
            myList.Insert(0,111);
                // To the begginig of the List
                //Note this is the whole list so if you add again another one will be place
            myList.Add(111);// to the end of the List
            }
// We clear the List if the Reset Pin is bang 
            if (FReset[0])
            {
                myList.Clear();
            }

We Assing the List to our Output Pin

// we set the SliceCount of our Output pin to be the same as size of the List .
            FOutput.SliceCount = myList.Count;
            //and Assign the data from our List to the Output Pin .
            FOutput.AssignFrom(myList);

This is the Patch&Code of it .

Note : In most occasions will be more effective to use already in ISpread(T) Extension Methods instead of creating new list like

FInput.Add(FInput[i]) or FInput.RemoveAll(item => item == FFilter[0]);

instead of creating the new List and do

myList.Add(FInput[i])
myList.RemoveAll(item => item == FFilter[0]);

anonymous user login

Shoutbox

~4h ago

joreg: vvvvTv S02E01 is out: Buttons & Sliders with Dear ImGui: https://www.youtube.com/live/PuuTilbqd9w

~6d ago

joreg: vvvvTv S02E00 is out: Sensors & Servos with Arduino: https://visualprogramming.net/blog/2024/vvvvtv-is-back-with-season-2/

~7d ago

fleg: hey there! What's the best tool for remote work? Teamviewer feels terrible. Thanks!

~20d ago

joreg: Last call: 6-session vvvv beginner course starting November 4: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-i/

~1mth ago

joreg: Missed the last meetup? You can rewatch it here: https://www.youtube.com/live/MdvTa58uxB0?si=Fwi-9hHoCmo794Ag

~1mth ago

theurbankind: When is the next big event, like node festival ?

~1mth ago

~1mth ago

joreg: Join us for the next vvvv meetup on Oktober 17th: https://visualprogramming.net/blog/2024/25.-vvvv-worldwide-meetup/

~1mth ago

joreg: 6 session beginner course part 2 "Deep Dive" starts January 13th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-ii/