2月14号又来了!又到了撸美工的时间!

这次依旧带来的是分形科学:分形山脉。当然,这是一个简单的2D的图形。

整体的思路很简单,对于每一条线段,取中点,让其纵坐标“抖动”一下,以此点为最终确定的点,依次连接该点与原线段两端点,得到新的两个线段,进入下一步迭代。

然而上色实在是太麻烦了。作为智障的我选择了两个背景色,233 天色(あまいろ, #2CA9E1)和 666 翡翠色(ひすいいろ, #38B48B)。

附赠python代码

from numpy import *
from matplotlib import *
import matplotlib.pyplot as plt
from random import *

class Point:
	x = 0; y = 0
	def __init__(self, x_, y_):
		self.x = x_; self.y = y_
	def __str__(self):
		return str(self.x) + " " + str(self.y)

def yamadahelp( p1, p2, depth ):
	d_ = depth + 1
	r_ = random()
	h_ = 0.5 ** depth * 0.8
	x_ = 0.5 * (p1.x + p2.x)
	y_ = 0.5 * (p1.y + p2.y) + r_ * h_
	return Point(x_, y_), d_

def yamada( work ):
	return yamadahelp(work[0], work[1], work[2])

def yama( bias ):
	depth = 0
	work = [Point(0, 0), Point(1, 0), depth]
	fin = [Point(0, 0), Point(1, 0)]
	works = [work]
	
	while works:
		cur = works.pop(0)
		pt, d = yamada(cur)
		fin.append(pt)
		if d > 8: continue
		works.append([cur[0], pt, d])
		works.append([pt, cur[1], d])

	fin.sort(key = lambda p: p.x)
	x = []; y = []
	for p in fin:
		x.append(p.x); y.append(p.y - bias)
	return x, y
	
def main():
	fig = plt.figure()
	ax = fig.add_subplot(111)
	for i in range(6):
		x, y = yama(i * 0.03)
		ax.plot(x, y)

	ax.set_xticks([])
	ax.set_yticks([])
	ax.spines['right'].set_color('none')
	ax.spines['left'].set_color('none')
	ax.spines['top'].set_color('none')
	ax.spines['bottom'].set_color('none')
	ax.set_ylim([-0.45, 1])
	# plt.show()
	plt.savefig('example.svg', pad_inches=0.)

if __name__ == '__main__':
	main()

Result

自己调的结果