create_texture__mcl_portals_portal.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import png
  2. w, h = 16, 128;
  3. s = [[int(0) for c in range(w)] for c in range(h)]
  4. def drawpixel(x, y, t):
  5. if (x >= 0) and (x < w) and (y >= 0) and (y < h):
  6. if(t == 1):
  7. s[y][x] = 1
  8. elif t==2:
  9. s[y][x] = 1 - s[y][x]
  10. elif t==3:
  11. s[y][x] = s[y][x] + 1
  12. if s[y][x] > 3:
  13. s[y][x] =s[y][x]-4
  14. def circle(X1, Y1, R, t):
  15. x = 0
  16. y = R
  17. delta = 1 - 2 * R
  18. error = 0
  19. while y >= 0:
  20. if Y1%w + y < w:
  21. drawpixel(X1 + x, Y1 + y, t)
  22. if Y1%w - y >= 0:
  23. drawpixel(X1 + x, Y1 - y, t)
  24. if Y1%w + y < w:
  25. drawpixel(X1 - x, Y1 + y, t)
  26. if Y1%w - y >= 0:
  27. drawpixel(X1 - x, Y1 - y, t)
  28. error = 2 * (delta + y) - 1
  29. if ((delta < 0) and (error <= 0)):
  30. x = x + 1
  31. delta = delta + 2 * x + 1
  32. elif ((delta > 0) and (error > 0)):
  33. y = y - 1
  34. delta = delta - 2 * y + 1
  35. else:
  36. x = x + 1
  37. y = y - 1
  38. delta = delta + 2 * (x - y)
  39. def line(y1, x1, y2, x2, v):
  40. signx = 1
  41. signy = 1
  42. dx = x2 - x1
  43. dy = y2 - y1
  44. if dx < 0:
  45. dx = - dx
  46. signx = -1
  47. if dy < 0:
  48. dy = - dy
  49. signy = -1
  50. offsx = dx/2
  51. offsy = dy/2
  52. dir1 = 0
  53. if dx >= dy:
  54. dir1 = 1
  55. for i in range(max(dx, dy)+1):
  56. if(v == 1):
  57. s[x1][y1] = 1
  58. elif v==2:
  59. s[x1][y1] = 1 - s[x1][y1]
  60. elif v==3 or (v==4 and ((x1^y1)&1)) or (v==5 and (((x1|y1)&1)==0)) or (v==7 and ((((x1+1)|y1)&1)==0)) or (v==8 and ((((x1+1)|(y1+1))&1)==0)) or (v==6 and (((x1|(y1+1))&1)==0)):
  61. s[x1][y1] = s[x1][y1] + 1
  62. if s[x1][y1] > 3:
  63. s[x1][y1] = s[x1][y1] - 4
  64. if dir1 == 1:
  65. x1 += signx
  66. offsy += dy
  67. if offsy >= dx:
  68. y1 += signy
  69. offsy -= dx
  70. else:
  71. y1 += signy
  72. offsx += dx
  73. if offsx >= dy:
  74. x1 += signx
  75. offsx -= dy
  76. # R, G, B, Alpha (0xFF = opaque):
  77. palette=[
  78. (0x30,0x03,0xaf,0xa4),
  79. (0x4f,0x1c,0xaf,0xb4),
  80. (0x7f,0x3d,0xa0,0xc8),
  81. (0x6d,0x5d,0x99,0xb1)
  82. ]
  83. circles = h//w
  84. maxr = w//2
  85. for i in [1,2,3,5,9,10,11,13]:
  86. for c in range(circles):
  87. q = ((circles-c-1)+i)%w
  88. circle(maxr, maxr+c*w, q, 3)
  89. linesperside = 2
  90. linestarts = round(w / linesperside) # 8
  91. lineoffset = round(w / linestarts) # 2
  92. wminus = w - 1
  93. for j in range(linesperside):
  94. for k in range(linestarts):
  95. offset = k * w
  96. for q in [0,1,3,4]:
  97. # for q in [1]:
  98. i = j*linestarts + ((k+q)%linestarts)
  99. line(i, offset, wminus-i, offset+wminus, 5+(k&3))
  100. line(wminus, offset+i, 0, offset+wminus-i, 5+(k&3))
  101. w = png.Writer(len(s[0]), len(s), palette=palette, bitdepth=2)
  102. f = open('mcl_portals_portal.png', 'wb')
  103. w.write(f, s)