Skip to content

Instantly share code, notes, and snippets.

@Andrewp2
Created September 8, 2022 02:01
Show Gist options
  • Select an option

  • Save Andrewp2/c055f130059699d4c58476818930f31c to your computer and use it in GitHub Desktop.

Select an option

Save Andrewp2/c055f130059699d4c58476818930f31c to your computer and use it in GitHub Desktop.
A python file to create a series of image files.
import os
import png
import random
A = 255
B = 127
files_to_create = [
# 1
("baseColor", (A, A, A, 0)),
("subsurface", (0, 0, 0, B)),
# 2
("metallic", (B, 0, 0, 0)),
("specular", (0, B, 0, 0)),
("specularTint", (0, 0, B, 0)),
("roughness", (0, 0, 0, B)),
# 3
("anisotropic", (B, 0, 0, 0)),
("sheen", (0, B, 0, 0)),
("sheenTint", (0, 0, B, 0)),
("clearcoat", (0, 0, 0, B)),
# 4
("shadingNormal", (0, 0, A, 0)),
("clearcoatGloss", (0, 0, 0, B)),
# 5
("specTrans", (B, 0, 0, 0)),
# 6
("iridescence", (A, A, A, 0)),
# 7
("emissive", (0, 0, 0, 0)),
("emissiveStrength", (0, 0, 0, A))
]
dir = "./images/"
name = "whatever"
gradient = True
while name != "thin" and name != "solid":
name = input("thin or solid?: ")
if name == "thin":
# 5
files_to_create.append(("diffuseTrans", (0, B, 0, 0)))
files_to_create.append(("flatness", (0, 0, 0, 0)))
elif name == "solid":
# 5
files_to_create.append(("scatterDistance", (0, B, B, B)))
for f in os.listdir(dir):
os.remove(os.path.join(dir, f))
for file_name in files_to_create:
print("Writing: " + dir + file_name[0] + ".png")
f = open(dir + file_name[0] + ".png", 'wb')
p = []
numcols = 2048
numrows = 2048
for r in range(0, numrows):
x = []
for c in range(0, numcols):
if gradient:
x.append(int(r/numrows * 255) if file_name[1][0] > 0 else 0)
x.append(int(c/numcols * 255) if file_name[1][1] > 0 else 0)
x.append(0 if file_name[1][2] > 0 else 0)
x.append(255 if file_name[1][3] > 0 else 0)
else:
x.append(file_name[1][0])
x.append(file_name[1][1])
x.append(file_name[1][2])
x.append(file_name[1][3])
p.append(x)
w = png.Writer(2048, 2048, greyscale=False, alpha=True)
w.write(f, p)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment