Notice: Array to string conversion in /var/www/wiki.sourcebinder.org/includes/Setup.php on line 304

Warning: Parameter 1 to Language::getMagic() expected to be a reference, value given in /var/www/wiki.sourcebinder.org/includes/StubObject.php on line 58
Creating a custom node that calculates sine values - SourceBinder Wiki

Creating a custom node that calculates sine values

From SourceBinder Wiki

Jump to: navigation, search

In this tutorial, you can learn how to create a simple node that calculates the sine value of a value.

Contents

Creating the node

First step is to select File/New Node from the top menu.

filemenu.jpg


Then select custom and click on the next button.

newnode.jpg


Here you have to give SourceBinder some data about the node you want to create

  • Node name would be Sin
  • Category is Math
  • Library it uses is none since it does not use any other custom libraries.

It's good practice to give a short description about the node like It calculates the sine value of a number

nodeproperties.jpg


Writing some code

Then, by clicking on the next button you can create your node.

Currently, it does not do anything at all, so let's write some code.

Double click on the node and then select the Source Editor button.

sourceeditorbutton.jpg


We need two variables, one that represents the input value and an other that represents the output value. Both of them is a number.

inputoutputvars.jpg


Let's define the core of our node, which is the sine calculating.

The logic you need is something like this:

output = Math.sin(input * Math.PI/180);

You have to put this logic into the update function.

code1.jpg


Every time when this node receives an input value, the framework calls this update function and fills the output variable with the sine value of the input variable.

Only one thing left, after the output variable has changed, you have to notify the framework by calling the invalidate() method.

code2.jpg


Let's click on the Save and Compile button to compile this code. If everything goes well, it compiles the code.


Node attributes

After that, you have to set up the Node Attributes. Click on the Node Attributes button at the bottom.

nodeattr.jpg


You have to define which variables are input variables and which are output variables. In this case, input is an input variable, and output is an output variable.

attr1.jpg


attr2.jpg


The Primary Input or the Primary Output means that these variables get a yellow triangle in the node representation.


primary.jpg

Congratulation, your node is ready.

Testing

You can create a simple composition like this.

test.jpg

You can create a Stepper node that feeds your node and a VerticalLineChart node that draws your sine values.

By setting the Stepper node correctly, you can draw a nice sine wave.

stepper1.jpg

stepper2.jpg


Here you can find this composition.

Personal tools