为了账号安全,请及时绑定邮箱和手机立即绑定

我使用 OpenSimplex 错了吗

我使用 OpenSimplex 错了吗

米脂 2021-07-05 08:05:27
所以我尝试使用 OpenSimplex 噪声来生成 2D 地形,但似乎我错过了一些东西,因为地形看起来大多是随机的。我究竟做错了什么?这是代码:import pygamefrom opensimplex import OpenSimplextmp = OpenSimplex()pygame.init()display_width = 800display_height = 600black = (40,40,40)gameDisplay = pygame.display.set_mode((display_width,display_height))gameDisplay.fill(black)gameDisplay.convert()clock = pygame.time.Clock()dimensions = [100,100]size = 40def mapping(x):    y = (x + 1) * 10 + 40    return yclass GroundCell:    def __init__(self,x,y,dim):        self.x = x        self.y = y        self.dim = dimtempcells = []allCells = []for a in range(0,dimensions[0]):    tempcells = []    for b in range(0,dimensions[1]):        tempcells.append(GroundCell(a*size,b*size,mapping(tmp.noise2d(a,b))))    allCells.append(tempcells)while True:    for event in pygame.event.get():        if event.type == pygame.QUIT:            pygame.quit()            quit()        if event.type == pygame.KEYDOWN:            if event.key == pygame.K_ESCAPE:                pygame.quit()                quit()    for a in allCells:        for b in a:            pygame.draw.rect(gameDisplay,(b.dim,b.dim,b.dim),(b.x,b.y,size,size))    pygame.display.update()    clock.tick(120)    gameDisplay.fill(black)这是产生噪声的图像
查看完整描述

1 回答

?
德玛西亚99

TA贡献1770条经验 获得超3个赞

你必须得到整数之间的值,这会“平滑”结果,否则你会得到普通的噪音。所以你必须改变这一行:

tempcells.append(GroundCell(a*size,b*size,mapping(tmp.noise2d(a,b))))

像这样:

tempcells.append(GroundCell(a*size,b*size,mapping(tmp.noise2d(a*0.1,b*0.1))))


查看完整回答
反对 回复 2021-07-06
  • 1 回答
  • 0 关注
  • 204 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号