1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Web library

We finished up on the NodeBox Web library, which allows you to access the internet from NodeBox in an easy way: perform search queries on Yahoo!, get articles from Wikipedia, search for images on morgueFile, find colors on kuler, parse and clean up HTML (using Beautiful Soup), read newsfeeds, download stuff asynchronously while your animation keeps on running, and much much more.

The library is available here!

Hyperlink graph and images, text, colors from the internet:







Some code examples:

web =  ximport("web")
onscreen_urls = []
def recurse_web(url, x, y, depth=5):
    """ Traverse the web recursively.
    Draw the url as a node on the canvas.
    Find links in the url's webpage.
    Then execute this command on all the links.
    Bet you can't wait to change that mysterious depth=5
    to depth=sys.maxint :-)
    global onscreen_urls
    fill(0, 0, 0, 0.2)
    oval(x-depth*8, y-depth*8, depth*16, depth*16)
    fill(1, 1, 1, (depth+1)*0.25)
    oval(x-2, y-2, 4, 4)
    page = web.page.parse(url)
    if page.error:
        print "ERROR:", url, page.error
    if page.title:
        # Never trust web content - plainify it!
        #title = web.html.plain(page.title)
        #text(title, x+4, y-4, width=150)
        text(web.url.parse(url).domain, x+4, y-4)
    if depth > 0:
        links = page.links()
        for url in links[:10]:
            # Don't do backlinks.
            # Don't start downloading PDF's etc.
            if url not in onscreen_urls \
            and web.url.is_webpage(url):  
                dx = x+random(-150,150)
                dy = y+random(-150,150)
                line(x, y, dx, dy)
                recurse_web(url, dx, dy, depth-1)
recurse_web("http://nodebox.net", WIDTH/2, HEIGHT/2)
# Morguefile images in Core Image
coreimage = ximport("coreimage")
images = web.morguefile.search("network")
img = choice(images)
canvas = coreimage.canvas(500,500)
l = canvas.layer(img.path)
l.filter_triangletile(dx=-334, dy=-149, width=355.93)
# Urban Dictionary definitions!
definitions = web.urbandictionary.search("internet") 
print choice(definitions).description
>>> A magical place where you can spend hours on end talking to people 
>>> all over the world posing as a 10 year old girl, do research on 
>>> any subject imaginable, play games, or look at some good porn.


Created by Tom De Smedt