Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
# TodaysPeople by Fabian Topfstedt # Based on NodeBoxes 'TextFromList' example (See http://nodebox.net) import datetime import urllib def get_tagthenet_url_for_todays_wikipedia_page(): now = datetime.datetime.now() day = now.day months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] month = months[now.month - 1] url = 'http://tagthe.net/api/?url=http://en.wikipedia.org/wiki/%s_%s&view=json' % (month, day) return url def get_people(): """Returns the names of people found on a web page""" url = get_tagthenet_url_for_todays_wikipedia_page() w = urllib.urlopen(url) ttn = w.read() w.close() # oh that's so hacked ... but it is code for artworks, not for rockets ;) start_string = '"person":[' start_index = ttn.find(start_string) + len(start_string) stop_index = ttn[start_index:].find(']') + start_index people_str = ttn[start_index: stop_index] people_str = people_str.replace('"', '') people = people_str.split(',') return people # Canvas size w = 1920 h = 1200 size(w, h) # People of the day's names people = get_people() # Typo font('Arial Black') # Define some colors. white = color(1,1,1) black = color(0,0,0) red = color(1,0,0) # Translation translate((w//4),(h//4)) for i in range(50): # The next line isn't inside of the push-pops and therefore # the translate is appended every time. This might mean that # the composition goes off-screen. This also means that # it creates more interesting compositions. translate(random(-100, 100), random(-100, 100)) # Save therefore current transformation. It's a good idea # to do this in the beginning of a loop. End the # loop with a pop. push() # Rotate in increments of 45 degrees. rotate(random(5)*45) fontsize(random(200)) fill(choice((white,black,red))) someText = choice(people) # One in two times, change the text to lowercase. if random(2) == 1: someText = someText.lower() try: text(someText, 0, 0) except: pass pop()
This paste will be private.
From the Design Piracy series on my blog: