Skip to content

Instantly share code, notes, and snippets.

@aparrish
Created April 23, 2011 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aparrish/938804 to your computer and use it in GitHub Desktop.
Save aparrish/938804 to your computer and use it in GitHub Desktop.
processing.py sketch for making rotating poem things
import random
class Sketch(object):
def __init__(self):
self.words = [
['then', 'later', 'and'],
['my', 'the', 'a', 'that'],
['minister', 'survey', 'drunk', 'lather', 'liver', 'doctor', 'grue', 'vice', 'devilry', 'shortcake'],
['confessed', 'drained', 'maintained', 'checked out', 'focused'],
['your', 'those', 'all', 'his', 'her', 'lifelessly.', 'as well.', 'here.', 'first.'],
['bohemian', 'western', 'cephalopod', 'extra', 'blank', 'split', 'medium'],
['shackles', 'discounts', 'flip-flops', 'programs', 'diets', 'schemes', 'vaults', 'sprouts'],
['!', '.', '?', '...', '?!']
]
self.longests = []
self.textsize = 28
def setup(self):
size(800, 480, OPENGL)
hint(ENABLE_DEPTH_SORT)
self.font = createFont('League Gothic', 72)
textAlign(LEFT, CENTER)
textFont(self.font)
textSize(self.textsize)
for patt in self.words:
widths = [textWidth(w.upper() + " ") for w in patt]
self.longests.append(max(widths))
for i in range(len(self.words)):
wordlist = self.words[i]
random.shuffle(wordlist)
self.words[i] = wordlist
longest_sum = sum(self.longests)
self.center = width/2 - (longest_sum / 2.0)
def draw(self):
background(255)
textSize(self.textsize)
for j, wordlist in enumerate(self.words):
for i, word in enumerate(wordlist):
pushMatrix()
translate(self.center + sum(self.longests[:j]), height/2)
theta = ((2*PI)/len(wordlist)) * i * -1
rotateX(theta + (frameCount * (0.0006 * len(wordlist))))
translate(0, 0, 60)
fill(72 + (modelZ(0, 0, 0) * -1) * 2.5)
text(word.upper(), 0, 0)
popMatrix()
sketch = Sketch()
def setup():
sketch.setup()
def draw():
sketch.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment