By admin, 1 May, 2023

Logic helps organize code and enables programs to run more efficiently when implemented properly. A well-written code helps the readability of the code.

 

The following link shows a tutorial by Mathew Ragan where ‘ buttons create a movie crossfader between 4 movieFile Ins: https://matthewragan.com/2015/03/29/ame-394-simple-vj-set-up-touchdesigner/. We analyze this network as a simple exmaple of logic and coding.

 

Let us try to describe the aim of the tutorial in a human logic: we are gonna build a network with 4 moviefile ins, an out signal/data to send to a projector and 4 buttons that will change the projection accroding to the selected moviefileIn using a crossfader. This description of human logic is the basis of what we are gonna structure in data and logic.

Logic helps organize code and enables programs to run more efficiently when implemented properly. A well-written code helps the readability of the code. Without properly applied logic, programs cannot produce the expected outputs. Python is an interpreted, object-oriented, high-level programming language with dynamic semantics developed by Guido van Rossum.

An expression is a combination of values, variables, operators, and calls to functions. Expressions need to be evaluated. If you ask Python to print an expression, the interpreter evaluates the expression and displays the result. Callbacks let you use Python to react to many different kinds of changes in TouchDesigner. Some operators will have callback DATs attached to them when you create them, such as Timer CHOP, while other callback DATs stand alone as their own operator types, such as Parameter Execute DAT.

Events in TouchDesigner are single-moment occurrences that are generated from a variety of conditions - from input actions that a user causes, from external devices and software, and from internal TouchDesigner states caused by things like timers and values crossing thresholds.

In order to make this logic work we will first have to define variables with values that can be checked. Therefore we are going to reference to “constant values at the highest level of our network.” These variables have to be checked every time an event is occuring.

Variables, Expressions and events are three elements that we will use to create our code that will execute our logic:

The event is when the button is clicked. The expression is the code for each button, that has to execute another logic. Differentiating the logic is done in a clause: If a value (or variable) equals the integer “0” the logic has to end op in another result then when it equals “1”.

The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. The if/else statement is a part of JavaScript's "Conditional" Statements, which are used to perform different actions based on different conditions.

The action that has to be executed when an event occurs is assigning the corresponding MovieFileIn with the corresponding entry of the crossfader.

 

 

Image
logic and TouchDesigner

Download the example:

Touchdesigner example logic