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

Colors library saturation function problem

Posted by nbveh Masala on Dec 03, 2008

Hello!

I`m using colors library for creating gradient background of screen, both colors of gradient are random. Also for using in fullscreen mode, my patch making little oval mouse pointer. Both of element changing dynamically it`s saturation from 1 to 0 and back, with different speed(kinda hypnotic,pulsing color effect).

Everything working fine, but i just realized(after adding mouse pointer element, where saturation change cycle much more faster) that whatever color was randomly chosen by program, after first cycle it turns into kind of pink... weird!

i`m using this line in setup

mcl=color(random(),random(),random())
and this in draw
mcl.saturation=mclsat
    
    if msd==0:
        mclsat-=0.1
        ms+=0.1
    else:
        mclsat+=0.1
        ms-=0.1
        
    if ms>=1:
        msd=1
    elif ms<=0.0:
        msd=0


 
Posted by Nbveh Masala on Dec 05, 2008

here little example showing this problem(tell me if it is only me see it in red color...:)

size (400,400)
 
speed (30)
 
def setup():
    
   colors = ximport("colors")
   
   global col,sat,count
   
   col=color(random(),random(),random())
   sat=1
   count=0
    
def draw():
   global sat
   global count
   fill(col) 
   
   rect(WIDTH/2-50,HEIGHT/2-50,100,100,0.3)
   
   col.saturation=sat
   
   if count==0:
       sat-=0.03
   else:
       sat+=0.03
       
   if sat<=0.0:
       count=1
   elif sat>=1:
       count=0



Posted by Stefan G on Dec 05, 2008

First of, you're just importing the colors library but not using it.
So you should write

col=colors.Color(random(),random(),random())
if you want to use the colors functionality.

This won't fix your problem with the pink coloring though. I think it's because when a color is completely desaturated (saturation equals to 0) you get a grey color (red == green == blue). So the hue information gets lost here, it becomes 0 (or 1) as well. And a hue of 0 or 1 is a red hue. So you could either store the hue value in your setup function and reuse that in your draw function or either prevent the saturation value from ever becoming 0.



Posted by nbveh Masala on Dec 05, 2008

i`ll try it! thanx!