Skip to content

Instantly share code, notes, and snippets.

@jf-parent
Created April 1, 2016 03:40
Show Gist options
  • Save jf-parent/57505204749a33bc6d192f98e5b861d1 to your computer and use it in GitHub Desktop.
Save jf-parent/57505204749a33bc6d192f98e5b861d1 to your computer and use it in GitHub Desktop.
ArtScript I
#!/usr/bin/env python
#Result: https://goo.gl/photos/efVQbcnRHd8Jp2EG8
import inspect
from datetime import datetime
from random import randint
from IPython import embed
from PIL import Image, ImageFilter, ImageDraw, ImageFont
def main():
canvas_size = 500
canvas = Image.frombytes('RGBA', (canvas_size, canvas_size), '\x00\x00\x00\x00' * canvas_size * canvas_size)
draw = ImageDraw.Draw(canvas)
#RECTANGLE
x_s = 0
y_s = canvas_size/2
x_e = canvas_size
y_e = canvas_size
draw.rectangle([(x_s, y_s), (x_e, y_e)], fill = '#db2f27')
draw.ellipse((-200, 350, 250, 700), fill = '#fbae17')
for i in range(4):
x_s = randint(50,150)
y_s = randint(300, 350)
x_e = x_s+20
y_e = y_s+20
draw.ellipse((x_s, y_s, x_e, y_e), fill = '#fbae17')
for i in range(3):
x_s = randint(100,300)
y_s = randint(300, 375)
x_e = x_s+20
y_e = y_s+20
draw.ellipse((x_s, y_s, x_e, y_e), fill = '#f7772c')
canvas = canvas.filter(ImageFilter.GaussianBlur(2))
draw = ImageDraw.Draw(canvas)
#Line
for i in range(50):
x_s = canvas_size
y_s = 0
x_e = (canvas_size/2)-(i*10)
y_e = (canvas_size/2)-1
draw.line((x_s, y_s, x_e, y_e), fill="white")
canvas = canvas.filter(ImageFilter.GaussianBlur(1))
draw = ImageDraw.Draw(canvas)
#Code
fnt = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 5)
text = inspect.getsource(main)
x = 50
y = 10
draw.multiline_text((x, y), text, font=fnt, fill=(255,255,255,128))
now = datetime.now().strftime("%H-%M-%S")
canvas.save('result/%s-%s.jpg'%(__file__[:-3], now))
canvas.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment