Skip to content

Instantly share code, notes, and snippets.

@StoneLabs
Last active October 28, 2024 16:58
Show Gist options
  • Select an option

  • Save StoneLabs/9f50215475f30440de5c15ebcc1900d9 to your computer and use it in GitHub Desktop.

Select an option

Save StoneLabs/9f50215475f30440de5c15ebcc1900d9 to your computer and use it in GitHub Desktop.
Factorio Circle Blueprint Generator
print("Please make sure py_factorio_blueprints is installed (pip install)")
print("Please make sure https://github.com/tzwaan/python-factorio-blueprints is cloned in this directory")
from py_factorio_blueprints.blueprint import Blueprint
print("\nEnter radius: ", end="")
radius = int(input())
print("Enter Thickness: ", end="")
thickness = int(input())
print("\nGenerating Circle...")
blueprint = Blueprint()
Blueprint.import_prototype_data('./python-factorio-blueprints/py_factorio_blueprints/entity_data.json')
# Generate Circle
import numpy
diameter = 2*radius + 2*thickness + 1
xx, yy = numpy.mgrid[:diameter, :diameter]
circle = (xx - radius - thickness) ** 2 + (yy - radius - thickness) ** 2
print(circle)
donut = (circle < (radius + thickness)**2) & (circle > (radius-0.5)**2)
print(donut.shape)
# Make Blueprint
print("\nGenerating Blueprint...", end="\r")
total = diameter * diameter
current = 0
percent = -1
for pos,val in numpy.ndenumerate(donut):
current = current + 1
if round((current / total * 100)) != percent:
percent = round((current / total * 100))
print("Generating Blueprint... " + str(percent) + "%", end="\r", flush=True)
if val == True:
blueprint.entities.make(name="stone-wall", position=pos)
print("\n")
print(blueprint.to_string())
print("\nCopying to Clipboard...")
import pyperclip
pyperclip.copy(blueprint.to_string())
@StoneLabs
Copy link
Author

Demo output for radius 200, tickness 3:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment