Godot Nature of Code  1.2.0
Nature of Code implemented in Godot Engine
Public Member Functions | Properties | List of all members
Fractals.KochCurve Class Reference

Koch curve. More...

Inherits Resource.

Public Member Functions

 KochCurve (Vector2 start, Vector2 end, int generations)
 Create new Koch curve. More...
 
void GenerateAll ()
 Generate all needed generations. More...
 
void GenerateOne ()
 Generate one generation. More...
 
void Draw (CanvasItem canvas)
 Draw curve using canvas. More...
 
void DrawUntil (CanvasItem canvas, int index)
 Draw curve using canvas until line index. More...
 

Properties

int Count [get]
 Line count. More...
 

Detailed Description

Koch curve.

Definition at line 69 of file KochLine.cs.

Constructor & Destructor Documentation

◆ KochCurve()

Fractals.KochCurve.KochCurve ( Vector2  start,
Vector2  end,
int  generations 
)
inline

Create new Koch curve.

Parameters
startStarting point
endEnding point
generationsGeneration count

Definition at line 84 of file KochLine.cs.

85  {
86  _generations = generations;
87 
88  _lines.Add(new KochLine()
89  {
90  Start = start,
91  End = end
92  });
93  }

Member Function Documentation

◆ Draw()

void Fractals.KochCurve.Draw ( CanvasItem  canvas)
inline

Draw curve using canvas.

Parameters
canvasCanvas item

Definition at line 148 of file KochLine.cs.

149  {
150  foreach (var line in _lines)
151  line.Draw(canvas);
152  }

◆ DrawUntil()

void Fractals.KochCurve.DrawUntil ( CanvasItem  canvas,
int  index 
)
inline

Draw curve using canvas until line index.

Parameters
canvasCanvas item
indexLine index

Definition at line 159 of file KochLine.cs.

160  {
161  var limit = Mathf.Max(0, Mathf.Min(index, Count));
162  for (var i = 0; i < limit; ++i)
163  _lines[i].Draw(canvas);
164  }
int Count
Line count.
Definition: KochLine.cs:76
void Draw(CanvasItem canvas)
Draw curve using canvas.
Definition: KochLine.cs:148

◆ GenerateAll()

void Fractals.KochCurve.GenerateAll ( )
inline

Generate all needed generations.

Definition at line 98 of file KochLine.cs.

99  {
100  for (int i = 0; i < _generations; ++i)
101  GenerateOne();
102  }
void GenerateOne()
Generate one generation.
Definition: KochLine.cs:107

◆ GenerateOne()

void Fractals.KochCurve.GenerateOne ( )
inline

Generate one generation.

Definition at line 107 of file KochLine.cs.

108  {
109  var next = new List<KochLine>();
110 
111  foreach (var line in _lines)
112  {
113  var a = line.KochA();
114  var b = line.KochB();
115  var c = line.KochC();
116  var d = line.KochD();
117  var e = line.KochE();
118 
119  next.Add(new KochLine()
120  {
121  Start = a,
122  End = b
123  });
124  next.Add(new KochLine()
125  {
126  Start = b,
127  End = c
128  });
129  next.Add(new KochLine()
130  {
131  Start = c,
132  End = d
133  });
134  next.Add(new KochLine()
135  {
136  Start = d,
137  End = e
138  });
139  }
140 
141  _lines = next;
142  }

Property Documentation

◆ Count

int Fractals.KochCurve.Count
get

Line count.

Definition at line 76 of file KochLine.cs.


The documentation for this class was generated from the following file: