Game AI & Unity/L-system algorithm 25

[Plants and Python][prac11] Flowering: Chance and Time 개화

L-system으로 만든 식물 모델이, 식물처럼 행동할 수 있도록 만드는 것 무엇보다 시간이 흐름에 따라 변화가 생길 수 있도록 만들어보자. import matplotlib.pyplot as plt %matplotlib inline nan = float('nan') def plot_coords(coords, lw=0.5, bare_plot=True): if bare_plot: # Turns off the axis markers. plt.axis('off') # Ensures equal aspect ratio. plt.axes().set_aspect('equal', 'datalim') # Converts a list of coordinates into # lists of X and Y values, res..

[L-system]Fractal Generation with L-Systems ③

1. 분기점 기억하기 식물의 형태를 그리기 위해서는, 어디에서 가지가 뻗어나가야할 지 그 분기점을 기억할 필요가 있다. 그래서 거북이에게 그 분기점을 기억하게 만들기 위해서 '['과 ']' 명령어를 추가할 것이다. 더보기 %matplotlib inline import matplotlib.pyplot as plt plt.style.use('bmh') from math import pi, sin, cos DEGREES_TO_RADIANS = pi / 180 def turtle_to_coords(turtle_program, turn_amount=45): # 거북이가 (0,0)으로 시작하고 위쪽을 향해있다. state = (0.0, 0.0, 90.0) # 거북이가 가는 경로 yield (0.0, 0.0) for..

[L-system]Fractal Generation with L-Systems ②

1. 문자열 변환 규칙 a → aba c → bb 이러한 규칙을 딕셔너리 {'a': 'aba', 'c': 'bb'}를 사용해서 나타낼 수 있다. L-system에서도 비슷한 형태의 규칙이 사용되며, 이 방법을 사용하면 간단한 입력으로 복잡한 이미지를 만들 수 있다. 더보기 %matplotlib inline import matplotlib.pyplot as plt plt.style.use('bmh') from math import pi, sin, cos DEGREES_TO_RADIANS = pi / 180 def turtle_to_coords(turtle_program, turn_amount=45): # 거북이가 (0,0)으로 시작하고 위쪽을 향해있다. state = (0.0, 0.0, 90.0) # 거북..

[L-system]Fractal Generation with L-Systems ①

▶ L-system 프랙탈을 통해, 간단한 규칙을 이용해서 복잡한 시스템을 만들 수 있다. '선 그리기'를 기본으로 작동하는 L시스템을 만들어보자. 1. matplotlib를 사용하여 선 그리기 %matplotlib inline import matplotlib.pyplot as plt plt.style.use('bmh') # 색 설정 plt.plot( [0, 1, 2], # X 값 [0, 1, 0] # Y 값 ) plt.xlabel('x') plt.ylabel('y'); def plot_coords(coords, bare_plot=False): if bare_plot: plt.axis('off') # .set_aspect('equal', 'eatalim')은 가로세로 비율을 동일하게 설정해준다. plt...

[Plants and Python][prac8] 함수와 프랙탈 2

#4 transform_sequence #4 def transform_sequence(sequence, transformations): return ''.join(transformations.get(c, c) for c in sequence) transform_sequence(sequence, transformations) 주어진 시퀀스를 규칙에 따라 변환한다 sequence: 변환될 시퀀스 transformations: 변환 규칙을 포함하는 딕셔너리 transformations.get(c, c) 시퀀스의 문자 c에 대해 변환 사전에서 해당 문자의 변환을 찾는다 만약 변환이 없으면 원래 문자 c를 반환한다 for c in sequence 시퀀스의 각 문자에 대해 반복한다 join() 변환된 문자들을 이어..

[Plants and Python][prac7] 함수와 프랙탈 1

#1 plot_coords 함수 #1 import matplotlib.pyplot as plt %matplotlib inline nan = float('nan') def plot_coords(coords, lw=0.5, bare_plot=True): if bare_plot: # Turns off the axis markers. plt.axis('off') # Ensures equal aspect ratio. plt.axes().set_aspect('equal', 'datalim') # Converts a list of coordinates into # lists of X and Y values, respectively. X, Y = zip(*coords) # Draws the plot. plt.plot(..

[Plants and Python][prac6] 유전자 knock-out

▶ 유전자 knock-out 유전자 knock-out 이란, 생물체의 특정 유전자를 제거하여 그 유전자가 어떤 일을 하는지 이해하는 과정이다. 이 과정은 생물체의 기능을 조사하거나, 질병의 원인을 찾거나, 유전자 간 상호작용을 이해하는 데 도움이 된다. 예를 들어, 어떤 식물에서 특정 유전자를 knock-out하여 그 식물이 어떻게 변하는지 관찰할 수 있다. 이를 통해 그 유전자가 식물의 생존에 어떤 역할을 하는지 알 수 있다. 생물학적 연구에서 중요한 도구로 사용되며, 유전자와 생물학적 기능 사이의 관계를 이해하는 데 도움이 된다. 이번 시간에는 각 셀에서 하나씩 방정식을 제거하여 유전자 knock-out을 만들 것이다. 그리고 그 결과로 나온 4가지 돌연변이된 잎 모양을 플로팅해보겠다. 잎이 위로 자..

[Plants and Python][prac5] 프렉탈을 사용해서 잎 생성하기

Barnsley fern, a fractal In the spirit of bringing plants and math together, this lesson is about the Barnsley fern, a fractal first described by Dr. Michael Barnsley. Let's see what we can learn, by applying flawed, biological approaches to understand the algorithm underlying a fractal: Can a biologist fix a fern? Or, what I learned while studying fractals. Although foolhardy, it is hoped that ..