def noise(framesize, frames, res): bar = Bar('Image generation', frames) pnf1 = PerlinNoiseFactory(3, octaves=2, tile=(framesize * framesize, framesize * framesize, frames)) pnf2 = PerlinNoiseFactory(3, octaves=3, tile=(framesize * framesize, framesize * framesize, frames)) pnf3 = PerlinNoiseFactory(3, octaves=4, tile=(framesize * framesize, framesize * framesize, frames)) for t in range(frames): s = spiner() img = PIL.Image.new('RGB', (framesize, framesize)) for i in range(framesize): n1 = pnf1(i / (framesize / res), i / (framesize / res), t / frames) for j in range(framesize): n2 = pnf2(i / (framesize / res), j / (framesize / res), t / frames) n3 = pnf3(i / (framesize / res), j / (framesize / res), t / frames) cval1 = int(clamp(((n1 + 0.5) * 255), 0, 255)) cval2 = int(clamp(((n2 + 0.5) * 255), 0, 255)) cval3 = int(clamp(((n3 + 0.5) * 255), 0, 255)) output = (int(clamp(cval1, 0, 255)), int(clamp(cval3, 0, 255)), int(clamp(cval2, 0, 255))) img.putpixel((i, j), output) s.next() img.save("imgout/noise{:03d}.png".format(t)) bar.next() bar.finish()
def __init__(self): self.loaded_chunks = {} #4 self.selected_texture = 0 self.noise_biomes = PerlinNoiseFactory(1, 1) self.noise_plane = PerlinNoiseFactory(1, 3) self.noise_desert = PerlinNoiseFactory(1, 1) self.noise_mountain = PerlinNoiseFactory(1, 2) self.noise_caves = PerlinNoiseFactory(2, 5) self.generator = Worker(self.generateChunk)
def perlinmakin(size, res, frames, frameres): space_range = size // res frame_range = frames // frameres pnf = PerlinNoiseFactory(3, octaves=4, tile=(space_range, space_range, frame_range)) for t in range(frames): img = PIL.Image.new('L', (size, size)) for x in range(size): for y in range(size): n = pnf(x / res, y / res, t / frameres) img.putpixel((x, y), int((n + 1) / 2 * 255 + 0.5)) img.save("noiseframe{:03d}.png".format(t)) print(t)
def __init__( self, size, tile, octaves, seed ): # генерация мира по введенным параметрам. Параметры следует перенести куда-то, потому что после генерации мира они уже частично неинтересны self.size = int(size) # размер карты self.res = int(tile) # размер тайлов self.frames = 40 self.frameres = 40 self.space_range = self.size // self.res # количество тайлов self.frame_range = self.frames // self.frameres self.seed = seed # семя генератора self.save_path = None # файл карты self.octaves = int(octaves) # количества октав генератора t1 = time.time() self.pnf = PerlinNoiseFactory( 3, self.seed, octaves=self.octaves, tile=(self.space_range, self.space_range, self.frame_range)) # объект трехмерного шума перлина print('DEBUG : Perlin noise has been generated.') t2 = time.time() - t1 print('DEBUG : Perlin noise has been generated for %d seconds.)' % (t2)) self.map_tiles = [] # карта self.img = self.draw_image() self.log = open('log.txt', 'a') # heights_analysis(self.map_tiles) self.save_path = 'map/%dkm_world_tile%d_%s.png' % ( self.frames, self.space_range, self.seed) self.img.save(self.save_path) timestamp = time.ctime(time.time()) self.log.write("World generation start has been done at: %s" % (timestamp) + '\n') self.log.close() return None
SEARCHED_NODE = 5 PATH_NODE = 6 # Determine grid ROW = 20 COLUMN = ROW CELL_WIDTH = (SCREEN_WIDTH-200)/ROW - MARGIN CELL_HEIGHT = SCREEN_HEIGHT/COLUMN - MARGIN # Set the state state = States.SET_START grid = [] node_states = {} frontier = [] came_from = {} node_weights = {} found_end = False pnf = PerlinNoiseFactory(2, octaves = 8) start_node = None end_node = None def main(): global state global grid global node_states global frontier global came_from global found_end global start_node global end_node
def __init__(self): self.worldSize = 40 self.terrianMap = [[0 for x in range(self.worldSize)] for y in range(self.worldSize)] self.pnf = PerlinNoiseFactory(2, octaves=5, tile=(0, 0))
' <model file="models/box.3d" ambiR="0.5" ambiG="0.5" ambiB="0.5" texture="assets/grass_block.png" />' ) print(' </models>') print('</group>') sky = [0.529, 0.808, 0.922] print('<scene>') print('<lights>') print(' <light type="POINT" y="10" x="5" z="5"/>') print('</lights>') print('<group R="{}" G="{}" B="{}">'.format(sky[0], sky[1], sky[2])) print(' <scale x="-200" y="-200" z="-200" />') print(' <models>') print(' <model file="models/sphere.3d" diffR="{}" diffG="{}" diffB="{}" />'. format(sky[0], sky[1], sky[2])) print(' </models>') print('</group>') PNFactory = PerlinNoiseFactory(2) x_size = 100 y_size = 100 for x in range(x_size): for z in range(y_size): y = floor(PNFactory(x / 16, z / 16) * 4) block(x - (x_size / 2), y, z - (y_size / 2)) print('</scene>')
from perlin import PerlinNoiseFactory from PIL import Image size = 200 res = 40 frames = 20 frameres = 5 space_range = size // res frame_range = frames // frameres pnf = PerlinNoiseFactory(3, octaves=4, tile=(space_range, space_range, frame_range)) for t in range(frames): img = Image.new('L', (size, size)) for x in range(size): for y in range(size): n = pnf(x / res, y / res, t / frameres) img.putpixel((x, y), int((n + 1) / 2 * 255 + 0.5)) img.save("noiseframe{:03d}.png".format(t)) print(t)
def __init__( self, size, tile, octaves, seed ): #генерация мира по введенным параметрам. Параметры следует перенести куда-то, потому что после генерации мира они уже частично неинтересны self.size = int(size) #размер карты self.res = int(tile) #размер тайлов self.frames = 40 self.frameres = 40 self.space_range = self.size // self.res #количество тайлов self.frame_range = self.frames // self.frameres self.seed = seed #семя генератора self.save_path = None #файл карты self.octaves = int(octaves) #количества октав генератора t1 = time.time() pnf = PerlinNoiseFactory( 3, self.seed, octaves=self.octaves, tile=(self.space_range, self.space_range, self.frame_range)) #объект трехмерного шума перлина print('DEBUG : Perlin noise has been generated.') t2 = time.time() - t1 print('DEBUG : Perlin noise has been generated for %d seconds.)' % (t2)) self.map_tiles = [] #карта def heights_analysis( map_tiles ): #объект, записывающий в лог сведения о мире (высоты и таймштампы) heigh = [] #создание for x in range(len(map_tiles)): new_heigh = map_tiles[x][2] heigh.append(new_heigh) heigh.sort() print(len(heigh)) min_heigh = heigh[0] max_heigh = heigh[len(heigh) - 1] print('Min heigh is', min_heigh) print('Max heigh is', max_heigh) log.write("World max heigh point: %d" % (min_heigh) + '\n') log.write("World min heigh point: %d" % (max_heigh) + '\n') amount = 0 for x in range(len(heigh)): amount = amount + heigh[x] average = amount / len(heigh) #for x in range(map_tiles): #for y in range(map_tiles): #print(map_tiles[x][y]) print(amount) print(average) log.write("World average heigh point: %d" % (average) + '\n') return (None) class region(world): def __init__(self, x, y, z): self.x = x self.y = y self.z = z self.biom = None if z < 100: #определение уровня воды self.biom = 'Water' elif z > 150: #уровень гор if z > 165: #уровень высокогорья self.biom = 'Highlands' else: self.biom = 'Mountians' else: self.biom = 'Forest' #генератор региона 100х100 class ZArray: __slots__ = ["_array"] def __init__(self, ini_state): self._array = [None for i in range(ini_state)] def __getitem__(self, idx): return self._array[idx] def __setitem__(self, idx, value): if idx < 0: raise Exception("Out of bounds") for i in range((idx + 1) - len(self._array)): self._array.append(None) self._array[idx] = value def __str__(self): return "ZArray(" + ", ".join([str(i) for i in self._array]) + ")" class Map: def __init__(self, x_size, y_size, ini_state=256): self.x_size = x_size self.y_size = y_size self._map = [[ZArray(ini_state) for i in range(x_size)] for i in range(y_size)] def __getitem__(self, tup): y, x, z = tup if (self.y_size > y and y >= 0) and (self.x_size > x and x >= 0): return self._map[y][x][z] raise Exception("Out of bounds") def __setitem__(self, tup, value): y, x, z = tup if (self.y_size > y and y >= 0) and (self.x_size > x and x >= 0): self._map[y][x][z] = value return raise Exception( "Out of bounds" ) #карта, хранящая x,y,z координаты и привязанный объект (region) def draw_image(): for t in range(1): t1 = time.time() print('DEBUG : Start drawing image.') img = PIL.Image.new('RGB', (self.size, self.size)) for x in range(self.size): for y in range(self.size): n = pnf(x / self.res, y / self.res, t / self.frameres) z = (int((n + 1) / 2 * 255 + 0.5) ) #получение высоты тайла if z < 90: #95 уровень воды img.putpixel((x, y), (0, 0, z)) elif z > 150: #уровень гор if z > 165: cliff = z - 30 img.putpixel((x, y), (cliff, cliff, cliff)) else: img.putpixel((x, y), (z, z, z)) else: img.putpixel((x, y), (0, z, 0)) t2 = time.time() - t1 print('DEBUG : Image has been drawed for %d seconds.)' % (t2)) return (img) self.img = draw_image() log = open('log.txt', 'a') #heights_analysis(self.map_tiles) self.save_path = 'map/%dkm_world_tile%d_%s.png' % ( self.frames, self.space_range, self.seed) self.img.save(self.save_path) timestamp = time.ctime(time.time()) log.write("World generation start has been done at: %s" % (timestamp) + '\n') log.close() return (None) #class population
nd = noise(xOffDown, yOffDown) if (n > -0.06 and nd > -0.05): char += "#" else: char += " " yOff += scale yOffDown += scale xOff += scale xOffDown += scale os.system("cls") print(color + char) if __name__ == '__main__': colorama.init() noise = PerlinNoiseFactory(2, 1) scale = 0 xOff2 = 213 xOffDown2 = 1337 COLORS = ["red", "yellow", "green", "blue", "white"] COLORS_C = [Fore.RED, Fore.YELLOW, Fore.GREEN, Fore.BLUE, Fore.WHITE] color = "" while True: print("") color = input("Which Color?: ") if color in COLORS: print("") print("COLOR: " + color) color = COLORS_C[COLORS.index(color)] break
def __init__(self): self.create_grid() self.perlin_noise_factory = PerlinNoiseFactory(2, octaves=OCTAVES, unbias=UNBIAS)
) print(' ' * indent, '</group>') print("<scene>") print(' <light type="DIRECTIONAL" dirY="10" colour="#303030" />') print(" <group>") print( f' <scale X="-{SIZE_X + SIZE_Z}" Y="-{SIZE_X + SIZE_Z}" Z="-{SIZE_X + SIZE_Z}"/>' ) print( ' <model file="models/sphere.3d" texture="textures/8k_stars_milky_way.jpg" emis="#FFFFFF"/>' ) print(" </group>") floor_factory = PerlinNoiseFactory(2, octaves=64) def get_height(x, z): return floor(floor_factory(x / SIZE_X, z / SIZE_Z) * 50) for x in range(SIZE_X): for z in range(SIZE_Z): xa = x - SIZE_X / 2 za = z - SIZE_Z / 2 p0 = get_height(x - 1, z) p1 = get_height(x, z - 1) p2 = get_height(x + 1, z) p3 = get_height(x, z + 1)