Created
February 2, 2011 08:48
-
-
Save daeken/807419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PIL import Image | |
| from math import cos, sin, sqrt | |
| import struct | |
| import psyco | |
| psyco.full() | |
| def f(x, y): | |
| tsin = sin(3.14159/4) | |
| tcos = cos(3.14159/4) | |
| return int(sqrt(abs(x*tcos - y*tsin))), int(sqrt(abs(y*tcos + x*tsin))) | |
| #f = lambda v: int(sqrt(abs(v))) | |
| #f = lambda v: v**2 | |
| size = 256 | |
| hsize = size / 2 | |
| idata = [None]*(size*size*3) | |
| i = 0 | |
| def pixel(v): | |
| global i, idata | |
| idata[i] = chr(v) | |
| i += 1 | |
| idata[i] = chr(v) | |
| i += 1 | |
| idata[i] = chr(v) | |
| i += 1 | |
| tdata = [[None] * size] * size | |
| for y in range(size): | |
| print y | |
| #y = f(y) | |
| for x in range(size): | |
| tx, ty = f(x-hsize, y-hsize) | |
| if tx & ty == 0: | |
| tdata[y][x] = 255 | |
| else: | |
| tdata[y][x] = 0 | |
| for y, row in enumerate(tdata): | |
| print y | |
| map(pixel, row) | |
| im = Image.fromstring('RGB', (size, size), ''.join(idata)) | |
| im.save('tattoo%i.png' % size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment