Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tiny Sprite Sheet Generator by France Force, 2020
- # Python version by Ben Ferguson - MIT License
- # Requires Pillow for Python3
- from PIL import Image, ImageDraw
- import random
- import math
- from datetime import datetime
- i = (16 * 32) - 1 # Sprite number
- x, j, pas, s, X, Y = 0, 0, 0, 0, 0, 0
- px_b = (0, 0, 0) # pixel colors - black
- px_c = (0, 0, 0) # pen color
- img = Image.new('RGB', (512, 256), "white")
- pixels = img.load() # loads in pixel data as assignable array
- # Set seed to constant if you like!
- seed = datetime.now().timestamp() # Sets random library seed to current system time
- def R(): # Define random function
- global s
- s = s + 1
- r = int((math.sin(s + i*i) + 1)*1e9 % 256) | 0
- return r
- def PxRect(x, y, c): # Draw a black border
- pixels[x-1, y-1] = c
- pixels[x, y-1] = c
- pixels[x+1, y-1] = c
- pixels[x-1, y] = c
- pixels[x+1, y] = c
- pixels[x-1, y+1] = c
- pixels[x, y+1] = c
- pixels[x+1, y+1] = c
- i = (32 * 16)-1 # 32 rows x 16 columns of sprites
- while i >= 0:
- pas = 4 # 4 passes: outline left/right and fill left/right
- while pas > 0:
- s = seed
- j = int(R()/5 + 50)|0 # sprite pixels between 50-101
- while j > 0:
- X = j & 7
- Y = j >> 3 # X/Y pixel index of sprite
- if (R()**2 / 2e3) <= (X*X + (Y-5)**2):
- j = j - 1 # Skip this iteration if distance is above rand
- continue
- if R() < 19: # small chance of new random color
- px_c = (R(), R(), R())
- rx = 7 + i%32*16 - pas%2*2*X + X # X pos flipped, if even
- ry = 2 + (i>>5)*16 + Y # y pos
- if pas > 2:
- PxRect(rx, ry, px_b) # first two passes draw outline rects
- pixels[rx, ry] = px_c # color pixel!
- j = j - 1
- pas = pas - 1
- i = i - 1
- img.show() # open created image
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement