Initial Commit

This commit is contained in:
2022-10-17 19:17:22 +02:00
commit 14c182a39c
18 changed files with 863 additions and 0 deletions

View File

@ -0,0 +1,28 @@
from PIL import Image, ImageDraw
import noise
slides = []
width=500
height=500
#cycles=5948
cycles=595
divider=1000
divider=100
for lacu in range(0,cycles):
print("Lacunarity: "+str(round(lacu/divider,3)) )
img = Image.new('RGB', (width,height))
for x in range(1,width):
for y in range(1,height):
area = noise.pnoise2( x/128, y/128, octaves=50, persistence=0.5, lacunarity=round(lacu/divider,3), repeatx=width, repeaty=height, base=25 )
img.putpixel( (int(x),int(y)), round(area*255) )
d = ImageDraw.Draw(img)
d.text( (1,1), "Lacunarity: "+str(round(lacu/divider,3)), fill=(255,0,0))
slides.append(img)
slides[0].save("lacunarity.gif", save_all=True, append_images=slides[1:], optimize=True, duration=50, loop=0)

68
experiments/camera.py Normal file
View File

@ -0,0 +1,68 @@
# Import 1st party modules
import curses
# Import my own libraries
from state import State
gamestate = State()
gamestate.load()
#print(gamestate.terrain[1][2])
def draw_map(stdscr):
# key press
k = 0
# Map center
center = {}
center['x'] = round(gamestate.metadata['width']/2)
center['y'] = round(gamestate.metadata['height']/2)
# Clear and refresh the screen for a blank canvas
stdscr.clear()
stdscr.refresh()
# Start colors in curses
curses.start_color()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_GREEN) # Neutral Land
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE) # Neutral Sea
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_GREEN) # Friendly Land
curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_BLUE) # Friendly Sea
curses.init_pair(5, curses.COLOR_RED, curses.COLOR_GREEN) # Enemy Land
curses.init_pair(6, curses.COLOR_RED, curses.COLOR_BLUE) # Enemy Sea
curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_BLACK) # Outside of the map
while (k != ord('q')):
# Initialization
stdscr.clear()
height, width = stdscr.getmaxyx()
if k == curses.KEY_DOWN:
center['y'] = center['y'] + 1
elif k == curses.KEY_UP:
center['y'] = center['y'] - 1
elif k == curses.KEY_RIGHT:
center['x'] = center['x'] + 1
elif k == curses.KEY_LEFT:
center['x'] = center['x'] - 1
for y in range(1,height):
for x in range(1,width):
if gamestate.terrain[x][y] == "l":
stdscr.addstr( y, x, " ", curses.color_pair(1) )
elif gamestate.terrain[x][y] == "w":
stdscr.addstr( y, x, " ", curses.color_pair(2) )
# Refresh the screen
stdscr.refresh()
# Wait for next input
k = stdscr.getch()
def main():
curses.wrapper(draw_map)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,16 @@
from map import Map
from PIL import Image, ImageDraw
slides = []
if __name__ == "__main__":
for x in range(1,100):
map = Map(sealevel=x, xoffset=0, yoffset=0)
map.generateMap()
# map.findCoast()
# map.generateCities()
# map.addCities()
#map.printWorld()
slides.append(map.saveWorld())
slides[0].save("zlevel_7.gif", save_all=True, append_images=slides[1:], optimize=True, duration=500, loop=0)

View File

@ -0,0 +1,18 @@
from map import Map
# from PIL import Image, ImageDraw
slides = []
if __name__ == "__main__":
max_scale = 32
max_lacunarity = 100
width=150
height=50
for lacunarity in range(1,max_lacunarity):
lacunarity = lacunarity/100
print("Lacunarity: "+str(lacunarity))
map = Map(scale=32, base=1, width=width, height=height, lacunarity=lacunarity)
map.generateMap()
slides.append(map.saveWorld())
slides[0].save("zoom_base1_zoom"+str(max_scale)+"_lacunarity"+str(max_lacunarity)+"_width"+str(width)+"_height"+str(height)+".gif", save_all=True, append_images=slides[1:], optimize=True, duration=40, loop=0)

View File

@ -0,0 +1,19 @@
from map import Map
from PIL import Image, ImageDraw
slides = []
if __name__ == "__main__":
max_scale = 64
lacunarity = 1.5
for scale in range(32,max_scale):
print("Scale: "+str(scale))
map = Map(scale=scale, base=1, width=640, height=480, lacunarity=lacunarity)
map.generateMap()
# map.findCoast()
# map.generateCities()
# map.addCities()
#map.printWorld()
slides.append(map.saveWorld())
slides[0].save("zoom_base1_zoom"+str(max_scale)+"_lacunarity"+str(lacunarity)+".gif", save_all=True, append_images=slides[1:], optimize=True, duration=150, loop=0)

31
experiments/test.py Normal file
View File

@ -0,0 +1,31 @@
import curses
from state import State
k = 0
gamestate = State()
gamestate.load()
terrain = gamestate.terrain
def main(stdscr):
mypad = curses.newpad(62,62)
for y in range(0,62):
mypad.addstr( y, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqerstuvwxyz1234567890")
mypad_pos = 0
mypad.refresh(mypad_pos, 0, 5, 5, 10, 30)
while (k != ord('q')):
mypad.refresh(mypad_pos, 0, 5, 5, 10, 30)
if k == curses.KEY_DOWN:
mypad_pos += 1
mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)
elif k == curses.KEY_UP:
mypad_pos -= 1
mypad.refresh(mypad_pos, 0, 5, 5, 10, 60)
k = stdscr.getch()
curses.wrapper(main)