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

Colorpicker

Posted by FredericAlbers on Jun 11, 2007



This script picks randomcolors from images. In this case a dolphin.
Just create a new folder, trow some pics in the folder, and change the document names in the script.
Enjoy

size(600,600)
colormode(RGB,250)
 
coreimage= ximport("coreimage")
canvas= coreimage.canvas(600,600)
 
# A list with all document names you put in the folder (in this example the folder is called images/)
animals = ["dolfijn", "eekhoorn", "giraf", "koe", "kameel", "kameleon", "neushoorn", "olifant", "tijger", "toekan", "uil", "vos", "zebra"]
 
# Let nodebox choose a picture from the images folder
chooseanimal = choice (animals)
 
print chooseanimal
 
img = canvas.layer("images/"+chooseanimal+".jpg")
w, h = img.size()
pix = img.pixels()
 
# A for loop with 300 circles, where the circle's color is taken from a random pixel from the image.
for i in range(300):
    r,g,b = pix.get_pixel(int(random(w)),int(random(h)))
    background(r,g,b)
    fill(r,g,b)
    d = random(10,150)
    x = random(WIDTH-120)
    y = random(HEIGHT-120)
    oval(x,y,d,d)
    
# Draws a shadow
    fill(0,28)
    nostroke()
    oval(x-10,y-10,d+18,d+18)
    reset()