# Introduction to modular components¶

prerequisites

You should have a general understanding of Vectors and Trigonometry, if not then soon enough parts of these lessons might be confusing. If you want to get the most of out Sverchok but don’t have a strong Math background then work your way through related KhanAcademy content, it’s a great resource and mind bogglingly comprehensive.

## Lesson 01 - A Plane¶

Nodes covered in this lesson: Math, Vector In, Float, Range Float, Viewer Draw, Stethoschope, Formula, Vector Math.

Let’s make a set of 4 vectors and combine them to represent a plane. I’ll use the Trigonometric concept of the unit-circle to get coordinates which are 0.5 PI appart. We carefully pick points on the unit-circle so that when we connect them via edges it results in a square. To begin we want to create a series of numbers, to represent those points on the unit-circle. Essentially this sequence is [0.25 pi, 0.75 pi, 1.25 pi, 1.75 pi]. Because these aren’t whole numbers, but so called Floats, we use a Node that generates a range of Floats: Range Float. (or ‘Float series’ as it’s called when added to the node view).

Making a series of numbers

• Add -> numbers -> Range Float This node has a set of defaults which output [0.000, 1.000..... 9.000]. We will tell the node to make [0.25, 0.75, 1.25, 1.75] and multiply them later with the constant PI.

Seeing the output of the Range Float node

• Add -> Text -> Stethoscope

Hook up the Stethoscope input into the Float range output, you’ll see text printed onto the node view. You can change the color of the Stethoscope text using the color property if the background color is too similar to the text color. Setting up the input values of Range Float to generate the right output

Set the Float Series mode to Step and make sure the Start value is 0.25 and Step value is 0.50. You should type these numbers in instead of adjusting the slider, it’s fast and instantly accurate. Set the Count slider to 4, whichever way is fastest for you. Multiplying the series by PI

• Add -> numbers -> Math ( add two math nodes)

We know the output of the Float series now, what we will do is multiply the series by a constant PI. This is like doing [0.25, 0.75, 1.25, 1.75] * pi, which is what we wanted from the beginning, namely; [0.25 * pi, 0.75 * pi, 1.25 * pi, 1.75 * pi].

1. Set one of the Math nodes to the constant PI
2. Switch the other Math node to a Multiplier node by selecting Multiplication (*) from its dropdowns.
3. Connect the output of PI to one of the input sockets of the Multiply Node
4. Connect the output of the Float Series into the other input of the Multiply Node.

The result should look something like this, hook up the Stethoscope to see the outputs. Getting the Sine and Cosine of this series

• Add -> numbers -> Math ( add two math nodes)

These new Math nodes will do the Trigonometry for us. Set one of them to a Cosine and the other to a Sine. These two nodes will now output the cos or sin of whatever is routed into them, in this case the series of Floats. See the outputs of the Sine and Cosine node, each element represents a component of the set of Vectors we want to make. Sine will represent Y and Cosine will be X.

Making Vectors from a series of numbers

• Add -> Vector -> Vector In

The Vector In node takes as input 1 or more numbers per component. Sockets which are not explicitely connected to will be represented by a zero.

1. Connect the resulting Cosine series to the first component in of Vector in (x)
2. Connect the resulting Sine series to the second component in of Vector in (y)
3. Leaving Vector In’s 3rd socket (z) empty puts a zero as the z component for all vectors generated by that node. Display Geometry

• Add -> Viz -> Viewer Draw

Sverchok draws geometry using the Viewer Nodes, there are two types of viewer nodes but we’ll focus on Viewer Draw for the moment. Stethoscope is useful for showing the values of any socket, but when we’re dealing with final geometric constructs like Vectors often we want to see them in 3D to get a better understanding.

Connect the output of Vectors In into the Vertices on the Viewer Draw node. You should see 4 vertices appear on your 3d view (but don’t worry if you don’t immediately spot them): Notice the 3 color fields on the Viewer Draw node, they represent the color that this node gives to its Vertices, Edges, and Faces. If (after connecting Vector In to ViewerDraw) you don’t see the Vertices in 3dview, it is probably because your background 3dview color is similar to the Vertex color. Adjust the color field to make them visible.

Increasing the Size of the Vertex

Sometimes, especially while introducing Sverchok, it’s preferred to display Vertices a little bigger than the default values of 3 pixels. If you had difficulty spotting the vertices initially you will understand why. The N-panel (side panel, or properties panel) for the Node View will have extra panels when viewing a [Sverchok Node Tree]. Some nodes have a dedicated properties area in this panel to hold features that might otherwise complicate the node’s UI. In the case of the Viewer Draw, there’s quite a bit of extra functionality hidden away in the properties area. For now we are interested only in the Vertex Size property. In the image below it’s marked with a (red) dot. This slider has a range between 0 and 10, set it to whatever is most comfortable to view. Here a close up: I think you’ll agree that the Vertices are much easier to see now: Make some edges

We’ve created vertices, now we’re going to generate edges. We have 4 vertices and thus 4 indices: [0,1,2,3], the edges will be connected as [[0,1],[1,2],[2,3],[3,0]].

Vertices Indexed: • Add -> Numbers -> Formula

There are numerous ways to generate the index list for edges. For our basic example the simplest approach is to write them out manually. Eventually you will be making hundreds of Vertices and at that point it won’t be viable to write them out manually. For this lesson we’ll not touch that subject.

The formula node evaluates what you write into the function field, and then outputs the result to its out socket. Type into that field the following sequence [[0,1],[1,2],[2,3],[3,0]]. Now hook the output of Formula node into the EdgPol input of ViewerDraw. You should see the following: Make a first Polygon

We will reuse the Vertices, you can disconnect the Formula node from Viewer Draw. Let’s also reuse the Formula node by clearing the function field and replacing the content with the following sequence: [[0,1,2,3]]. Connect the output of this Formula node to the EdgPol input on Viewer Draw. You should now see the following: Controlling the size of the Polygon

There are many ways to scale up a set of vectors, we’ll use the Vector Math node.

• Add -> Vector -> Vector Math

Change the Vector Math node’s mode to Multiply Scalar. This will let you feed a number to the Vectors to act as a multiplier. We’ll add a Float node to generate the multiplier.

• Add -> Numbers -> Float
1. Hook up the Float node to the Scalar (green) input of the Vector Math (Multiply Scalar) node
2. Connect the output of the Vector In node into the top input of the Vector Math node.
3. Now connect the output of the Vector Math node into the Vertices socket of the Viewer Draw node.

You should have something like this. Now if you change the slider on the Float node, you’ll notice 2 things:

1. the header of the Float node gets the value of the slider, and more importantly,
2. the Polygon will start to increase and decrease in size because you are multiplying the x, y, and z components of the Vectors by that amount.

End of lesson 01

Save this .blend you’ve been working in now, somewhere where you will find it easily, as Sverchok_Unit_01_Lesson_01. We will use it as a starting point for the next lesson.

We’ll stop here for lesson 01, if you’ve followed most of this you’ll be making crazy shapes in a matter of hours. Please continue on to Lesson 02 - A Circle, but take a break first. Look outside, stare at a tree – do something else for 10 minutes.