Skip to content

Instantly share code, notes, and snippets.

@Erkaman
Created July 1, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erkaman/9bf45b2e7b8bd2364590ebaa2107ebee to your computer and use it in GitHub Desktop.
Save Erkaman/9bf45b2e7b8bd2364590ebaa2107ebee to your computer and use it in GitHub Desktop.
Python script that creates a simple Minecraft grass atlas.
# this python script simply creates a simple grass atlas image.
# the atlas is used in this small minecraft renderer:
# https://github.com/mikolalysenko/regl/pull/21
import png
import os
import noise
# open file
OUT_FILE = "atlas.png"
f = open(OUT_FILE, 'wb')
w = 32
h = 32
writer = png.Writer(w, h, alpha='RGBA')
data = []
def lerp(a, b, l):
return [int(a[0]*l + b[0]*(1.0-l)), int(a[1]*l + b[1]*(1.0-l)), int(a[2]*l + b[2]*(1.0-l)), 255 ]
# create atlas data.
i = 0
while i < w*h:
x = (i % w)
y = (i / w)
s = 0.7;
if y > 19:
t = 0 # dirt
else:
t = 1 # grass
if (x == 4 or x==5) and y == 19:
t = 0
if x == 0 and (y == 19 or y==18):
t = 0
if (x == 11 or x==12) and (y == 20 or y==21):
t = 1
if (x == 7) and (y == 20 or y==21):
t = 1
if (x == 15) and (y == 20 or y==21):
t = 1
if t == 0:
n = 0.5 * (1.0 + noise.snoise2(x*s+1000.94,y*s+1000.32, 3, 0.5, 2.0))
c = lerp([0.0, 0.0, 0.0], [170, 110, 40, 255],n )
else:
n = 0.5 * (1.0 + noise.snoise2(x*s,y*s, 3, 0.5, 2.0))
c = lerp([0.0,50.0,0.0], [0.0, 150.0,0.0],n )
data.extend(c)
i = i + 1
#write to file
writer.write_array(f, data)
f.close()
# open file(only works in OSX)
os.system("open " + OUT_FILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment