Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from noise import pnoise2
- import pygame
- from random import randint
- def generate2dperlin(offsetX, offsetY,x,y,octaves):
- noiseMap = []
- for i in range(offsetX,x+offsetX):
- n = []
- for j in range(offsetY,y+offsetY):
- n.append((pnoise2((i+offsetX)/x,(j+offsetY)/y,octaves, 0.5, 2) + 1) )
- noiseMap.append(n)
- return noiseMap
- x = 100
- y = 100
- octaves = 8
- offsetX = randint(-100000,100000)
- offsetY = randint(-100000,100000)
- print(offsetX, offsetY)
- offsetValues = [163, 152, 140, 137, 126, 10] #list of color values
- currentOffsetValue = 0
- noiseMap = generate2dperlin(offsetX, offsetY,x,y,octaves)
- white = (255,255,255)
- green = (58,95,11)
- blue = (0, 119, 190)
- yellow = (237, 201, 175)
- grey = (155, 155, 155)
- dark_blue = (0, 80, 120)
- #pgm
- screen_x = 600
- screen_y = 600
- maxX = 0#how much of the screen will be ofsetted
- rectSize = screen_x//x
- window = pygame.display.set_mode((screen_x, screen_y))
- pygame.display.set_caption('perlin')
- screen = pygame.Surface((screen_x, screen_y))
- done = True
- while done:
- keys = pygame.key.get_pressed()
- if keys[pygame.K_RIGHT]:
- offsetX += 1
- if keys[pygame.K_LEFT]:
- offsetX -= 1
- if keys[pygame.K_UP]:
- offsetY -= 1
- if keys[pygame.K_DOWN]:
- offsetY += 1
- noiseMap = generate2dperlin(int(offsetX), int(offsetY),x,y,octaves)
- for e in pygame.event.get():
- if e.type == pygame.QUIT:
- done = False
- if e.type == pygame.KEYDOWN:
- if e.key == pygame.K_w:
- octaves += 1
- if e.key == pygame.K_s:
- octaves -= 1 * (octaves > 1)
- if e.key == pygame.K_d:
- currentOffsetValue += 1 * (currentOffsetValue < len(offsetValues))
- print('Ты на ',currentOffsetValue, 'элементе')
- if e.key == pygame.K_a:
- currentOffsetValue -= 1 * (currentOffsetValue > 0)
- print('Ты на ',currentOffsetValue, 'элементе')
- noiseMap = generate2dperlin(int(offsetX), int(offsetY),x,y,octaves)
- #print(octaves)
- if e.type == pygame.MOUSEBUTTONDOWN:
- if e.button == 4:
- offsetValues[currentOffsetValue] += 0.5
- if e.button == 5:
- offsetValues[currentOffsetValue] -= 0.5
- noiseMap = generate2dperlin(offsetX, offsetY,x,y,octaves)
- print(offsetValues)
- screen.fill(white)
- for i in range (0, x-maxX):
- for j in range (0, y):
- sColor = noiseMap[i][j] * 137.5
- if (sColor > offsetValues[0]):
- color = white
- elif (sColor > offsetValues[1]):
- color = grey
- elif (sColor > offsetValues[2]):
- color = green
- elif (sColor > offsetValues[3]):
- color = yellow
- elif (sColor > offsetValues[4]):
- color = blue
- elif (sColor > offsetValues[5]):
- color = dark_blue
- else:
- color = white
- pygame.draw.rect(screen, color, (i*rectSize, j*rectSize, rectSize, rectSize))
- window.blit(screen, (0, 0))
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement