diff options
author | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 01:50:44 +0100 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 01:50:44 +0100 |
commit | 3f2f5f9403ac43b57afc246c4f27d3138f81863a (patch) | |
tree | 66200913997c4e5f526db58bb0392ec166619596 /plugins | |
parent | 725088882d82e983a03c0fb006707fa79b5c5acc (diff) |
Added imager plugin.
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/imager.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/plugins/imager.py b/plugins/imager.py new file mode 100755 index 0000000..7c26092 --- /dev/null +++ b/plugins/imager.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 +""" +This script generates an PNG image from a SALIS save file (or a list of saved +files), on which each pixel corresponds to a single byte on the simulation. +It's useful for identifying large scale structures and appreciating the +large-scale evolution of the world. + +Tu run it, simply call it from within the ./bin/ directory inside the SALIS +main directory, such as: + +../plugins/imager.py def.sim.* + +Calling this will create a PNG image for each file beggining with "def.sim". +""" +import sys +from ctypes import * +from PIL import Image +files = sys.argv[1:] +salis = CDLL("libsalis.so") +salis.sm_getSize.restype = c_uint + +def makeImage(iname): + salis.s_load(bytes(iname, "utf-8")) + lsize = int(salis.sm_getSize() ** 0.5) + image = Image.new("RGB", (lsize, lsize), "black") + pixels = image.load() + + for y in range(lsize): + for x in range(lsize): + addr = (y * lsize) + x + byte = salis.sm_getByteAt(addr) + pixels[x, y] = (byte // 4, byte // 2, byte) + + salis.s_quit() + oname = iname + ".png" + image.save(oname) + print(oname + " generated") + +for f in files: + makeImage(f) |