用户:
柏林噪声查看:4 回复:3 评论:4 创建时间:2020-11-05T20:01:58

1维柏林噪声原理:
在x轴上的各个坐标取一个随机y,
并存入列表中,
利用三角函数cos平滑这些值。

原理看似简单,
但是实现起来确实不容易,
本人在Python中花了好几天时间,
终于搞完了……
(尹子后人)
import turtle as t
import random
import math
List=[]
for i in range(0,9):
List.append(random.randint(-100,100))
t.hideturtle()
t.speed(0)
t.penup()
t.goto(-200,List[0])
t.pensize(10)
t.pendown()
for i in range(1,9):
if(List[i]<List[i-1]):
k=0
for j in range(314):
k+=0.01
t.goto(t.xcor()+50/314,List[i-1]+(math.cos(k)-1)/2*(List[i-1]-List[i]))
else:
k=3.14
for j in range(314):
k-=0.01
t.goto(t.xcor()+50/314,List[i-1]+(math.cos(k)+1)/2*(List[i]-List[i-1]))
t.done()