# L-SYSTEM 을 활용한 프랙탈

L-시스템을 이용해서 여러가지 멋진 프랙탈을 그려보도록 하자. 다음과 같이 변환 규칙, 공리 를 말하면 그에 맞게 코드로 설정하면 된다.

```c
변 환 : F -> F+F--F+F
공 리 : F

lsystem.AddTransRule('F', "F+F--F+F");
lsystem.MakeAxiom("F");
```

이 강좌에서는 따로 실행파일은 제공하지 않고 실행 결과의 그림과 변환 규칙, 공리만을 적는다.

## 코호섬

![](/files/-M3x20aG2EjPH2zhIdix)

|  변환 | F -> F-F+F+FF-F-F+F |
| :-: | ------------------- |
|  공리 | F-F-F-F             |
|  각도 | 90 도                |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(90.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "F-F+F+FF-F-F+F");
lsystem.MakeAxiom("F-F-F-F", 3);
```

## 시어핀스키 사각형

![](/files/-M3x20aI_XNR6YulwLqz)

|  변환 | F -> FF-F-F-F-FF |
| :-: | ---------------- |
|  공리 | F-F-F-F          |
|  각도 | 90 도             |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(90.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "FF-F-F-F-FF");
lsystem.MakeAxiom("F-F-F-F", 3);
```

## 시어핀스키 가스켓

![](/files/-M3x20aKCMjRq8bbql8H)

|  변환 | F -> FF                |
| :-: | ---------------------- |
|  변환 | X -> ++FXF--FXF--FXF++ |
|  공리 | FXF++FF++FF            |
|  각도 | 60 도                   |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(60.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "FF");
lsystem.AddTransRule('X', "++FXF--FXF--FXF++");
lsystem.MakeAxiom("FXF++FF++FF", 4);
```

## 힐버트 곡선

![](/files/-M3x20aMoMdZwIGkeQMP)

|  변환 | F -> F           |
| :-: | ---------------- |
|  변환 | X -> +YF-XFX-FY+ |
|  변환 | Y -> -XF+YFY+FX- |
|  공리 | X                |
|  각도 | 90 도             |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(90.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "F");
lsystem.AddTransRule('X', "+YF-XFX-FY+");
lsystem.AddTransRule('Y', "-XF+YFY+FX-");
lsystem.MakeAxiom("X", 4);
```

## 나무

![](/files/-M3x20aO8GCMZZ2IAGm-)

|  변환 | F -> FF+\[+F-F-F]-\[-F+F+F] |
| :-: | --------------------------- |
|  공리 | F                           |
|  각도 | 30 도                        |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(30.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "FF+[+F-F-F]-[-F+F+F]");
lsystem.MakeAxiom("F", 4);
```

## 열매를 맺는 나무

![](/files/-M3x20aQblNRKJ8-7LaY)

|  변환 | F -> FF+\[+F-F-F@]-\[-F+F+F@] |
| :-: | ----------------------------- |
|  공리 | F                             |
|  각도 | 30 도                          |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(30.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "FF+[+F-F-F@]-[-F+F+F@]");
lsystem.MakeAxiom("F", 4);
```

## 드래곤 곡선

![](/files/-M3x20aSZlKIfS613C23)

|  변환 | F -> F     |
| :-: | ---------- |
|  변환 | X -> X-YF- |
|  변환 | Y -> +FX+Y |
|  공리 | X          |
|  각도 | 90 도       |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(90.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "F");
lsystem.AddTransRule('X', "X-YF-");
lsystem.AddTransRule('Y', "+FX+Y");
lsystem.MakeAxiom("X", 10);
```

## 네모 곡선

![](/files/-M3x20aU54unLJDXpUzZ)

|  변환 | F -> FF-F-F-F-F-F+F |
| :-: | ------------------- |
|  공리 | F-F-F-F-            |
|  각도 | 90 도                |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(90.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "FF-F-F-F-F-F+F");
lsystem.MakeAxiom("F-F-F-F-", 3);
```

## 무궁화

![](/files/-M3x20aWCn1IEbJG97Zp)

|  변환 | F -> F++F++F  | F-F++F |
| :-: | ------------- | ------ |
|  공리 | F++F++F++F++F |        |
|  각도 | 36 도          |        |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(36.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "F++F++F|F-F++F");
lsystem.MakeAxiom("F++F++F++F++F", 3);
```

## 나무

![](/files/-M3x20aYKM9h16BN9Lzw)

|  변환 | F -> F\[+F\[+F]\[-F]F]\[-F\[+F]\[-F]F]F\[+F]\[-F]F |
| :-: | -------------------------------------------------- |
|  공리 | F                                                  |
|  각도 | 30 도                                               |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(30.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "F[+F[+F][-F]F][-F[+F][-F]F]F[+F][-F]F");
lsystem.MakeAxiom("F", 3);
```

## 시어핀스키 곡선

![](/files/-M3x20a_QN--6fUK1bDo)

|  변환 | F -> F       |
| :-: | ------------ |
|  변환 | X -> YF+XF+Y |
|  변환 | Y -> XF-YF-X |
|  공리 | YF           |
|  각도 | 60 도         |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(60.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "F");
lsystem.AddTransRule('X', "YF+XF+Y");
lsystem.AddTransRule('Y', "XF-YF-X");
lsystem.MakeAxiom("YF", 6);
```

## 시어핀스키 삼각형

![](/files/-M3x20abBMs87WQolhrF)

|  변환 | F -> FXF           |
| :-: | ------------------ |
|  변환 | X -> +FXF-FXF-FXF+ |
|  공리 | XF                 |
|  각도 | 120 도              |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(120.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "FXF");
lsystem.AddTransRule('X', "+FXF-FXF-FXF+");
lsystem.MakeAxiom("XF", 5);
```

## 눈송이

![](/files/-M3x20ad4q2uWtmCYG4_)

|  변환 | F -> "" 아무런 문자로도 전재하지 않음    |
| :-: | --------------------------- |
|  변환 | L -> FL-FR--FR+FL++FLFL+FR- |
|  변환 | R -> +FL-FRFR--FR-FL++FL+FR |
|  공리 | FL                          |
|  각도 | 60 도                        |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(60.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "");
lsystem.AddTransRule('L', "FL-FR--FR+FL++FLFL+FR-");
lsystem.AddTransRule('R', "+FL-FRFR--FR-FL++FL+FR");
lsystem.MakeAxiom("FL", 3);
```

## 페아노 곡선

![](/files/-M3x20afAkS-Q0g20yZV)

|  변환 | F -> F                     |
| :-: | -------------------------- |
|  변환 | X -> XFYFX-F-YFXFY+F+XFYFX |
|  변환 | Y -> YFXFY+F+XFYFX-F-YFXFY |
|  공리 | X                          |
|  각도 | 90 도                       |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(90.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "F");
lsystem.AddTransRule('X', "XFYFX-F-YFXFY+F+XFYFX");
lsystem.AddTransRule('Y', "YFXFY+F+XFYFX-F-YFXFY");
lsystem.MakeAxiom("X", 3);
```

## 갈대

![](/files/-M3x20ah-ohau5t-jDdg)

|  변환 | F -> FF+\[F+FF-F]-\[+F+F-F] |
| :-: | --------------------------- |
|  공리 | F                           |
|  각도 | 26 도                        |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(26.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "FF+[F+FF-F]-[+F+F-F]");
lsystem.MakeAxiom("F", 4);
```

## 나무

![](/files/-M3x20aj1yWLENNbfiHC)

|  변환 | F -> FF+\[+F-F-F]-\[-FFF] |
| :-: | ------------------------- |
|  공리 | F                         |
|  각도 | 26 도                      |

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(26.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "FF+[+F-F-F]-[-FFF]");
lsystem.MakeAxiom("F", 4);
```

## 선인장

![](/files/-M3x20alWivyG0l7VnIp)

|  변환 | F -> F               |
| :-: | -------------------- |
|  변환 | S -> \[++G]\[--G]TTS |
|  변환 | G -> +H\[-G]L        |
|  변환 | H -> -G\[+HF]FL      |
|  변환 | T -> TL              |
|  변환 | L -> \[-FFF]\[+FFF]F |
|  공리 | SLFFF                |
|  각도 | 18 도                 |

`코드`

```cpp
lsystem.SelectTurtle(&turtle);
lsystem.SetAngle(18.0f);
lsystem.SetLength(1.0f);
lsystem.SetFactor(1.0f);
lsystem.AddTransRule('F', "F");
lsystem.AddTransRule('S', "[++G][--G]TTS");
lsystem.AddTransRule('G', "+H[-G]L");
lsystem.AddTransRule('H', "-G[+HF]FL");
lsystem.AddTransRule('T', "TL");
lsystem.AddTransRule('L', "[-FFF][+FFF]F");
lsystem.MakeAxiom("SLFFF", 9);
```

이곳에서 설명한 L-시스템 이외에도 자신이 L-시스템을 만들어 볼 수 있다. L-시스템의 모형을 만들고 이에 대한 공리, 변환, 각도를 정해주면 된다. 자신이 설계한 L-시스템이 원하는 그림을 화면에 뿌려낼 때에는 한동안 무아지경에서 빠져 나오지 못할 것이다. ;] - 끝 -


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sungcheol-kim.gitbook.io/fractal-graphics-with-opengl/chapter11.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
