Advertisement
Guest User

NES nametable mirroring diagrams generator

a guest
Mar 5th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.14 KB | None | 0 0
  1. import PIL.Image
  2. import PIL.ImageDraw
  3.  
  4. tex_a = "  ****  " \
  5.         " **  ** " \
  6.         "**    **" \
  7.         "**    **" \
  8.         "********" \
  9.         "**    **" \
  10.         "**    **" \
  11.         "**    **"
  12. tex_b = "******* " \
  13.         "**    **" \
  14.         "**    **" \
  15.         "******* " \
  16.         "**    **" \
  17.         "**    **" \
  18.         "**    **" \
  19.         "******* "
  20. tex_c = " ****** " \
  21.         "**    **" \
  22.         "**    **" \
  23.         "**      " \
  24.         "**      " \
  25.         "**    **" \
  26.         "**    **" \
  27.         " ****** "
  28. tex_d = "******* " \
  29.         "**    **" \
  30.         "**    **" \
  31.         "**    **" \
  32.         "**    **" \
  33.         "**    **" \
  34.         "**    **" \
  35.         "******* "
  36. tex_2 = "        " \
  37.         "  ***** " \
  38.         " **   **" \
  39.         "     ** " \
  40.         "   ***  " \
  41.         "  **    " \
  42.         " **     " \
  43.         " *******"
  44. tex_4 = "        " \
  45.         "    *** " \
  46.         "   **** " \
  47.         "  ** ** " \
  48.         " **  ** " \
  49.         " *******" \
  50.         "     ** " \
  51.         "     ** "
  52. tex_0 = "        " \
  53.         "   ***  " \
  54.         "  *  ** " \
  55.         " **   **" \
  56.         " **   **" \
  57.         " **   **" \
  58.         "  **  * " \
  59.         "   ***  "
  60. tex_Cn= "        " \
  61.         "   **** " \
  62.         "  **  **" \
  63.         " **     " \
  64.         " **     " \
  65.         " **     " \
  66.         "  **  **" \
  67.         "   **** "
  68. tex_8 = "        " \
  69.         "  ***** " \
  70.         " **   **" \
  71.         " **   **" \
  72.         "  ***** " \
  73.         " **   **" \
  74.         " **   **" \
  75.         "  ***** "
  76. tex = { "a":tex_a, "b":tex_b, "c":tex_c, "d":tex_d, "0":tex_0, "2":tex_2, "4":tex_4, "8":tex_8, "C":tex_Cn }
  77.  
  78. col_a = (  0,  0,160)
  79. col_b = (160,  0,  0)
  80. col_c = (  0,120,  0)
  81. col_d = (120,120,  0)
  82. col = { "a":col_a, "b":col_b, "c":col_c, "d":col_d }
  83.  
  84. fade = [ 130, 160, 180 ]
  85. fade_mirror = 160
  86.  
  87. def fade_color(c,f):
  88.     (r,g,b) = c
  89.     r = f + int(((255-f)*r)/255)
  90.     g = f + int(((255-f)*g)/255)
  91.     b = f + int(((255-f)*b)/255)
  92.     return (r,g,b)
  93.  
  94. def draw_tex(img,s,col,scale,x,y):
  95.     pixels = img.load()
  96.     while len(s) > 0:
  97.         t = tex[s[0]]
  98.         s = s[1:]
  99.         for ty in range(0,8):
  100.             py = y + (scale * ty)
  101.             for tx in range(0,8):
  102.                 px = x + (scale * tx)
  103.                 if t[0] != ' ':
  104.                     for spy in range(0,scale):
  105.                         for spx in range(0,scale):
  106.                             pixels[px+spx,py+spy] = col
  107.                 t = t[1:]
  108.         x += (scale * 8)
  109.                
  110.  
  111. def draw_table(img,s,x,y,addr,mirr):
  112.     pixels = img.load()
  113.     for ty in range(0,(30*4)+1):
  114.         for tx in range(0,(32*4)+1):
  115.             cb = col[s]
  116.             if (tx % (32*4) == 0) or (ty % (30*4) == 0):
  117.                 cb = (0,0,0)
  118.             elif (tx % 8 == 0) or (ty % 8 == 0):
  119.                 cb = fade_color(cb,fade[0])
  120.             elif (tx % 4 == 0) or (ty % 4 == 0):
  121.                 cb = fade_color(cb,fade[2])
  122.             else:
  123.                 cb = fade_color(cb,fade[1])
  124.             if mirr and cb != (0,0,0):
  125.                 cb = fade_color(cb,fade_mirror)
  126.             pixels[tx+x,ty+y] = cb
  127.     draw_tex(img,addr,(0,0,0),1,x+8,y+8)
  128.     draw_tex(img,s,(255,255,255),8,x+33,y+29)
  129.  
  130. dimx = (32 * 4 * 2)+1
  131. dimy = (30 * 4 * 2)+1
  132.  
  133. def mirroring_img(seq):
  134.     subx = (32 * 4)
  135.     suby = (30 * 4)
  136.     img = PIL.Image.new("RGB",(dimx,dimy))
  137.     draw_table(img,seq[0],   0,   0,"2000",False)
  138.     draw_table(img,seq[1],subx,   0,"2400",seq[1] in seq[0:1])
  139.     draw_table(img,seq[2],   0,suby,"2800",seq[2] in seq[0:2])
  140.     draw_table(img,seq[3],subx,suby,"2C00",seq[3] in seq[0:3])
  141.     img.save("mirroring_"+seq+".png")
  142.  
  143. mirroring_img("aabb")
  144. mirroring_img("abab")
  145. mirroring_img("aaaa")
  146. mirroring_img("bbbb")
  147. mirroring_img("abcd")
  148. mirroring_img("abba")
  149. mirroring_img("abbb")
  150. mirroring_img("acbc")
  151. mirroring_img("abcc")
  152. mirroring_img("abbc")
  153.  
  154. img0 = PIL.Image.open("mirroring_aaaa.png")
  155. img1 = PIL.Image.open("mirroring_bbbb.png")
  156. img = PIL.Image.new("RGB",(dimx,(dimy*2)+8),(255,255,255))
  157. img.paste(img0,(0,0))
  158. img.paste(img1,(0,dimy+8))
  159. img.save("mirroring_aaaa_bbbb.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement