Gentile

 avatar
unknown
python
2 years ago
3.3 kB
4
Indexable
from asyncio.windows_events import NULL
from random import random, randrange
from PIL import Image
import os

print("Project Ember - Tilegen A1")
bFile = True
filedir = os.path.dirname(os.path.realpath(__file__))
MAX_SIZE_X = 16
MAX_SIZE_Y = 16
IMAGE_NAME = "image.png"

print(filedir + "\GenTile.py")
def newImg():
    print("Output (Including extension): ")
    out = input()

    # If no input, save to root
    if not out == NULL or "":
        IMAGE_NAME = out

    # Set width
    print("Width: ")
    szX = input()

    if not szX == NULL or "":
        MAX_SIZE_X = int(szX)

    # Set height
    print("Height: ")
    szY = input()

    if not szY == NULL or "":
        MAX_SIZE_Y = int(szY)

    MAX_SIZE = MAX_SIZE_X * MAX_SIZE_Y

    # Create new image using 32-bit color depth (alpha supported)
    img = Image.new('RGBA', (MAX_SIZE_X, MAX_SIZE_Y))

    # Optional color-scheme reference file (from root folder):
    print("(Optional) Color-palette reference file 'clr.png' from root? (y/n):")
    clrRef = input()

    print("Detail pixel density (1-3): ")
    pixelDensity = input()

    if clrRef == "y":
        clrRefImg = Image.open("clr.png")
        clrRef = clrRefImg.getpixel((0,0))
        clrRef2 = clrRefImg.getpixel((1,0))

        print(clrRef)
        print(clrRef2)

         # Pass 1 (solid color)
        for y in range(MAX_SIZE_Y):
            for x in range(MAX_SIZE_X):
                img.putpixel((x, y),(clrRef))

        # Pass 2 (detail color)
        for y in range(MAX_SIZE_Y):
            for x in range(MAX_SIZE_X):

                # Make RNG and change MAX_SIZE_X in randrange to random number

                if int(pixelDensity) == 1:
                    if randrange(MAX_SIZE_X + 10) == 3:
                        img.putpixel((x, y),(clrRef2))
                        print("pixel density: " + str(x) + " " + str(y))

                if int(pixelDensity) == 2:
                    if randrange(MAX_SIZE_X) == 3:
                        img.putpixel((x, y),(clrRef2))

                if int(pixelDensity) == 3:
                    if randrange(MAX_SIZE_X - 10) == 3:
                        img.putpixel((x, y),(clrRef2))
                        print("pixel density: " + str(x) + " " + str(y))


    elif clrRef == "n":
        # Pass 1 (solid color)
        for y in range(MAX_SIZE_Y):
            for x in range(MAX_SIZE_X):
                img.putpixel((x, y),(0,200,50))

        # Pass 1 (detail color)
        for y in range(MAX_SIZE_Y):
            for x in range(MAX_SIZE_X):

                if int(pixelDensity) == 1:
                    if randrange(MAX_SIZE_X + 10) == 3:
                        img.putpixel((x, y),(0,125,25))

                if int(pixelDensity) == 2:
                    if randrange(MAX_SIZE_X) == 3:
                        img.putpixel((x, y),(0,125,25))

                if int(pixelDensity) == 3:
                    if randrange(MAX_SIZE_X - 10) == 3:
                        img.putpixel((x, y),(0,125,25))

    print("Pixels set: " + str(MAX_SIZE))

    img.save(IMAGE_NAME)

    print("Tile " + IMAGE_NAME + " saved to root folder")
    return img

newImage = newImg()

if bFile == True:
    newImage.show()

os.system("pause")
Editor is loading...