Created
December 30, 2010 17:29
-
-
Save jaymzcd/760024 to your computer and use it in GitHub Desktop.
same as last thing only outputs for blender script
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
| #!/usr/bin/env python2 | |
| import string | |
| import re | |
| import random | |
| EXCLUDED = ["", "\n", "a","able","about","across","after","all","almost","also","am","among","ive", "an","and","any", "im", "are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"] | |
| CANVAS_SIZE = 20 | |
| HEADER = """ | |
| import bpy | |
| bpy.ops.object.select_all() | |
| bpy.ops.object.delete() | |
| bpy.ops.object.camera_add() | |
| camera = bpy.context.object | |
| camera.location = (11, 8.5, 32) | |
| """ | |
| FOOTER = """""" | |
| texts = open('nina-sent.txt', 'r') | |
| outfile = open('/tmp/nina.py', 'w') | |
| allwords = list() | |
| def grouped_elements(words, offset, cnt=2): | |
| r = range(offset, offset+cnt) | |
| group = '' | |
| for index in r: | |
| try: | |
| group += ' '+words[index] | |
| except IndexError: | |
| pass | |
| return group | |
| for line in texts: | |
| words = re.findall('\w+', line.translate(string.maketrans("",""), string.punctuation).lower()) | |
| for index, word in enumerate(words): | |
| if word in EXCLUDED: | |
| allwords.append(grouped_elements(words, index, 3)) | |
| else: | |
| allwords.append(grouped_elements(words, index)) | |
| word_counts = list() | |
| allwords.sort() | |
| for group in set(allwords): | |
| word_counts.append((allwords.count(group), group)) | |
| word_counts.sort() | |
| random.shuffle(word_counts) | |
| outfile.write(HEADER) | |
| yoffset = 0 | |
| xoffset = 10 | |
| for wc in word_counts: | |
| color = '%02x' % random.randint(130, 190) * 3 | |
| if wc[0]>1: | |
| size = wc[0]*0.1 | |
| if size>10: | |
| size = 10 | |
| color = 'ff' + '%02x' % random.randint(0, 50)*2 | |
| if size<0.05: | |
| size = 0.05 | |
| color = '%02x' % random.randint(220, 240) * 3 | |
| yoffset += size | |
| if yoffset > CANVAS_SIZE: | |
| yoffset = 0 | |
| xoffset += 2 | |
| if xoffset > CANVAS_SIZE: | |
| xoffset = 0 | |
| text = wc[1] | |
| JITTER = 5 | |
| outfile.write(""" | |
| bpy.ops.object.text_add() | |
| obj = bpy.context.object | |
| obj.location = (%(xoffset)s, %(yoffset)s, %(zoffset)s) | |
| obj.data.body = "%(word)s" | |
| obj.data.extrude = 0.02 | |
| obj.data.text_size = %(size)s | |
| \n""" % { | |
| 'size': size, | |
| 'word': text, | |
| 'count': wc[0], | |
| 'xoffset': xoffset + random.randint(0, JITTER) - JITTER, | |
| 'yoffset': yoffset + random.randint(0, JITTER) - JITTER, | |
| 'zoffset': random.randint(0, JITTER) - JITTER, | |
| 'color': color, | |
| } | |
| ) | |
| outfile.write(FOOTER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment