-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using Elements.Core; | ||
using FrooxEngine.ProtoFlux; | ||
using ProtoFlux.Core; | ||
using ProtoFlux.Runtimes.Execution; | ||
|
||
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Math | ||
{ | ||
[NodeCategory("Obsidian/Math")] | ||
[NodeName("Fibonacci")] | ||
public class FibonacciNode : ValueFunctionNode<FrooxEngineContext, int> | ||
{ | ||
public ValueInput<int> Input; | ||
|
||
protected override int Compute(FrooxEngineContext context) | ||
{ | ||
int n = Input.Evaluate(context); | ||
return Fibonacci(n); | ||
} | ||
|
||
private int Fibonacci(int n) | ||
{ | ||
if (n < 0) | ||
throw new ArgumentException("Negative numbers are not allowed."); | ||
if (n == 0) | ||
return 0; | ||
if (n == 1) | ||
return 1; | ||
|
||
int a = 0, b = 1, temp; | ||
for (int i = 2; i <= n; i++) | ||
{ | ||
temp = a + b; | ||
a = b; | ||
b = temp; | ||
} | ||
return b; | ||
} | ||
} | ||
} |