201
edits
Ashin.mandal (talk | contribs) No edit summary |
Ashin.mandal (talk | contribs) No edit summary |
||
(20 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== 8bitify - an image based twitter bot == | |||
[[File:Ashin_top_8bitify.png]] | |||
8bitify is a twitter bot that takes the image and text that you tweet to him and turns it into an 8bit console cut scene. | |||
<div style="width: 800px;"> | |||
'''Approach:''' | |||
8 bit games and old consoles fascinate me. I wanted to make a bot that recreated cut scenes from the old games with a graphic in the middle and text below it. It would in a way recreate old memories and also create possibility for a different kind of 8 bit poetry. | |||
Apart from this I also wanted the bot to behave more like an actual bot that you can talk to. I wanted people to meet him first, talk to him, figure out how he works, rather than a set of predefined instructions. | |||
'''Implementation:''' | |||
In the first version of the bot, if one tweeted to the bot there was a binary response depending on whether you tweeted with an image or not. If there was no image with the tweet, the bot would ask you to send one. | |||
With the latest update of the bot, now you can talk to him as well. I have attempted to make the AI good enough at least to pull of a basic conversation. | |||
The bot is live on a Heroku server. Tweet to [https://twitter.com/8bitify @8bitify] now to get to know him! See if you can get him to 8bitify a picture for you! | |||
'''Basic instructions for a basic conversation:''' | |||
The AI of the bot is still at a very basic stage. It responds to generic greetings like "Hello!", "Good Morning!" and "Bye!" You could also ask the bot how it is doing today or how it works. Be creative! Hopefully if you ask the right questions, it will have an answer for you. Otherwise, you will just be asked to try again. | |||
</div> | |||
'''Example Tweets:''' | |||
[[File:Ashin_8bitify_input.png]] | |||
[[File:Ashin_8bitify_output.png]] | |||
[[File:Ashin_child.png]] | |||
[[File:Ashin_child_8bit.png]] | |||
[[File:Ashin_bike.png]] | |||
[[File:Ashin_bike_8bit.png]] | |||
[[File:Ashin_luis.png]] | |||
[[File:Ashin_luis_8bit.png]] | |||
'''Example Conversation:''' | |||
[[File:Ashin_8bitbot_conversation.png]] | |||
[https://twitter.com/botsnplots/status/645483625018843136 Here] is the full conversation. | |||
'''The code for the filter:''' | |||
<source lang="python"> | |||
""" | |||
This module contains filter functions to modify images | |||
""" | |||
from PIL import Image, ImageDraw, ImageFont, ImageEnhance | |||
def eightBitify(img, text): | |||
""" Create an 8 bit version of the image. """ | |||
# Setting the pixelation range | |||
baseWidth=180 | |||
peakWidth=500 | |||
# Setting the text settings | |||
stringBreakPosition = 43 | |||
textIndent = 30 | |||
textStart = 305 | |||
textColor = (255,255,255) | |||
textFont = ImageFont.truetype('pixel.ttf', 10) | |||
# Creating the 8 bit image | |||
contrast = ImageEnhance.Contrast(img) | |||
img = contrast.enhance(1.5) | |||
brightness = ImageEnhance.Brightness(img) | |||
img = brightness.enhance(1.5) | |||
img = resizeImage(img, baseWidth) | |||
img = resizeImage(img, peakWidth) | |||
# Cropping the image | |||
img = img.crop((0, 25, 500, 210)) | |||
# Pasting the image in a new widescreen canvas | |||
newImg = Image.new("RGB", (500,375), "black") | |||
newImg.paste(img,(0, 95, 500, 280)) | |||
# Adding text to the image | |||
draw = ImageDraw.Draw(newImg) | |||
for line in text.splitlines(): | |||
lastPosition = 0 | |||
for i in xrange(0, len(line), 43): | |||
breakPosition = i + 43 | |||
if (breakPosition > len(text)): | |||
breakPosition = len(text) | |||
else: | |||
while(text[breakPosition - 1] != " "): | |||
breakPosition -= 1 | |||
draw.text((textIndent, textStart), line[lastPosition:breakPosition], textColor, font=textFont) | |||
lastPosition = breakPosition | |||
textStart += 10 | |||
return newImg | |||
def resizeImage(img, width): | |||
wpercent = (width/float(img.size[0])) | |||
height = int((float(img.size[1])*float(wpercent))) | |||
img = img.resize((width, height)) | |||
return img | |||
if __name__ == "__main__": | |||
# load a test image | |||
text = "I am trying to create a sentence or two which have 140 characters. Because I want to test it with my new twitter bot. I hope the bot is cool." | |||
img = Image.open("birdman.png") | |||
# blur the image | |||
img2 = eightBitify(img, text) | |||
img2.show() | |||
</source> | |||
Rest of the code can be found on [https://github.com/ashinmandal/8bitified GitHub]. | |||
== Little Box Robot - a Python Processing program to animate a ro(bot) == | == Little Box Robot - a Python Processing program to animate a ro(bot) == | ||
An experiment with Processing and Python to generate a simple looping animation. | An experiment with Processing and Python to generate a simple looping animation. | ||
The code: | '''The code:''' | ||
<source lang="python"> | <source lang="python"> | ||
""" | """ | ||
Line 98: | Line 219: | ||
[[File:Ashin_little_shitty_robot.gif]] | [[File:Ashin_little_shitty_robot.gif]] | ||
edits