Skip to content

Instantly share code, notes, and snippets.

@david-wm-sanders
Created July 29, 2026 14:22
Show Gist options
  • Select an option

  • Save david-wm-sanders/32289ab77ebadb9ed37914eff3350361 to your computer and use it in GitHub Desktop.

Select an option

Save david-wm-sanders/32289ab77ebadb9ed37914eff3350361 to your computer and use it in GitHub Desktop.
import itertools, pathlib, sys, time
THIS_DIR = pathlib.Path(__file__).parent
SRC_IMAGE_PATH = THIS_DIR / "dragon5.png"
BRIGHTNESS_ENHANCE_FACTOR = 1.0
CONTRAST_ENHANCE_FACTOR = 1.1
# from draftsman.env import update
# update(verbose=True, path=r"C:\Users\david\AppData\Roaming\Factorio\mods")
# ^busted because custom loader struggles mit Krastorio2 lua lib directory layout... f
print("Loading mod list...")
from draftsman.data.mods import mod_list
print(f"{mod_list=}")
print("Loading image...")
from PIL import Image, ImageEnhance
src_img = Image.open(SRC_IMAGE_PATH)
print(f"{src_img.format=}, {src_img.size=}, {src_img.mode=}")
print("Adjusting image...")
# resize the image
resized_img = src_img.resize((200, 200))
# brighten the image
brightness_enhancer = ImageEnhance.Brightness(resized_img)
brightened_img = brightness_enhancer.enhance(BRIGHTNESS_ENHANCE_FACTOR)
# boost the contrast of the image
contrast_enhancer = ImageEnhance.Contrast(brightened_img)
contrasted_img = contrast_enhancer.enhance(CONTRAST_ENHANCE_FACTOR)
# convert image format to grayscale
converted_img = contrasted_img.convert("L")
# show the image?
# converted_img.show()
# sys.exit(1)
print("Creating blueprint...")
from draftsman.blueprintable import Blueprint
bp = Blueprint()
bp.label = "Artwork!"
bp.version = (1, 0)
img = converted_img
# print(f"{img.size[0]}")
for x in range(img.size[0]):
for y in range(img.size[1]):
pixel = img.getpixel((x, y))
if pixel > 224:
# put steel wall
bp.entities.append("steel-wall", tile_position=[x, y])
elif pixel > 130:
# put concrete wall
bp.entities.append("concrete-wall", tile_position=[x, y])
elif pixel > 32:
# put stone wall
bp.entities.append("stone-wall", tile_position=[x, y])
else:
pass
# print(bp.to_string())
# (THIS_DIR / "blueprint.txt").write_text(bp.to_string())
# insert blueprint string into clipboard :D
import pyperclip
print("Copying blueprint string to clipboard!")
pyperclip.copy(bp.to_string())
print("done?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment