def next(self, color_in): # Calculate both wallclock time since start, as well as time since last call of next() t = time.time() - self.t_start dt = t - self.last_t self.last_t = t if t < 6: # Val fades us in from black at the beginning, we use sin_ease to bring us in # We clamp to 1.0 since we're going to be running this well past the end time of .5 # We're kind of abusing this function, it's meant to only be called from within ease() # but don't worry, we "Know What We're Doing" (TM) val = sin_ease(0, 1, 2.0, min(t, 2.0)) # Color cycle continually accelerates self.hue_cycle = .7 * exp(-.45 * t) # Calculate new hue, modulo 1.0 self.hue = (self.hue + dt / self.hue_cycle) % 1.0 # Have it saturate out to white from 3 seconds onward: sat = sin_ease(1, 0, 3.0, min(max(t - 3.0, 0.0), 3.0)) # Calculate final color out color_out = Color() color_out.setHSV(self.hue, sat, val) return color_out # Once we're done with startup, ease from the ending white to our color: mix_amnt = self.anim_queue.animate(default_value=0) return mix_amnt * self.white + (1 - mix_amnt) * color_in
def get_paragraph_color(): """ Get the preference corresponding to paragraph background color, and turn it into an hex string """ pref_string = GPS.Preference("Src-Editor-Reference-Style").get() c = Color(pref_string.split("@")[2]) return c.to_hex(), c.shade_or_lighten(0.1).to_hex()
def get_paragraph_color(): """ Get the preference corresponding to paragraph background color, and turn it into an hex string """ pref_string = GPS.Preference("Src-Editor-Reference-Style").get() c = Color( pref_string.split("@")[2] ) return c.to_hex(), c.shade_or_lighten(0.1).to_hex()
def __init__(self): self.t_start = time.time() self.last_t = self.t_start self.hue = 0 # Setup an animation to ease from a mixing value of 1 to 0 over 2.0 seconds self.anim_queue = AnimationQueue() self.anim_queue.push(ease(1, 0, 5.0, sin_ease)) self.white = Color(1, 1, 1)
def __init__(self, listen_port=7331, timeout=4, timeout_fade_duration=4): # create an OSC server and bind it to listen on port 7331 self.server = OSCServer(("", listen_port)) self.server.timeout = 0 self.server.handle_timeout = types.MethodType( lambda x: self.handle_timeout(), self.server) # Create handlers for "/rgb" and "/hsv". This causes a packet to "/rgb" to call self.set_rgb() # and a packet to "/hsv" to call self.set_hsv(), with the arguments path, tags, args, source self.server.addMsgHandler("/rgbw", lambda p, t, a, s: self.set_rgbw(p, t, a, s)) self.server.addMsgHandler("/rgb", lambda p, t, a, s: self.set_rgb(p, t, a, s)) self.server.addMsgHandler("/r", lambda p, t, a, s: self.set_r(p, t, a, s)) self.server.addMsgHandler("/g", lambda p, t, a, s: self.set_g(p, t, a, s)) self.server.addMsgHandler("/b", lambda p, t, a, s: self.set_b(p, t, a, s)) self.server.addMsgHandler("/w", lambda p, t, a, s: self.set_w(p, t, a, s)) self.server.addMsgHandler("/hsv", lambda p, t, a, s: self.set_hsv(p, t, a, s)) self.server.addMsgHandler("/h", lambda p, t, a, s: self.set_h(p, t, a, s)) self.server.addMsgHandler("/s", lambda p, t, a, s: self.set_s(p, t, a, s)) self.server.addMsgHandler("/v", lambda p, t, a, s: self.set_v(p, t, a, s)) # Initialize variables self.color = Color(0.0, 0.0, 0.0, 0.0) self.opacity = 0.0 self.timeout = timeout self.timeout_fade_duration = timeout_fade_duration # Setup our animation queue self.anim_queue = AnimationQueue() # The last time we got a message on our socket self.last_msg_time = time.time()
def next(self, color_in): # Get current time, divide into cycle length and take modulus time_idx = time.time()%self.cycle # Trying to get some late night dimming going, so I can leave this running in my room all day. Really not sure this belongs here vs another function, but it seems to work. time_day = time.time()%6 # Get the number of seconds since midnight rise_time = 9*60*60 - (8*60*60) # Set the offset for sunrise. In this case, I want the light to get brighter at 9am, (and dim at 9pm). The second term accounts for the time zone min_amp = 0 # Set Min, max_amp = 1 # Max brightness # Using first three terms of the fourier expansion of a square wave because I can.(Edit: Used a fourth term) # If you want to see what this looks like, I built it with wolfram alpha: # "graph 0.45*(sin((x-32400)*2pi/86400)+1/3sin(3(x-32400)*2pi/86400)+1/5sin(5(x-32400)*2pi/86400))+0.55 from 0 to 86400" night_dim_amp = (max_amp-min_amp)/2*(math.sin((time_day-rise_time)*2*math.pi/(6))+(max_amp-(max_amp-min_amp)/2)) # Move through the color circle, setting hue to our position in the cycle, # locking saturation to 1, and value varying with time. color_out = Color() color_out.setHSV(time_idx/self.cycle, 1, 0.1) # Return the color we generate. We ignore input color_in return color_out
def __init__(self, cycle=1, off_color=Color(0, 0, 0, 0)): self.cycle = cycle / 2.0 self.off_color = off_color
class Osc(object): def __init__(self, listen_port=7331, timeout=4, timeout_fade_duration=4): # create an OSC server and bind it to listen on port 7331 self.server = OSCServer(("", listen_port)) self.server.timeout = 0 self.server.handle_timeout = types.MethodType( lambda x: self.handle_timeout(), self.server) # Create handlers for "/rgb" and "/hsv". This causes a packet to "/rgb" to call self.set_rgb() # and a packet to "/hsv" to call self.set_hsv(), with the arguments path, tags, args, source self.server.addMsgHandler("/rgbw", lambda p, t, a, s: self.set_rgbw(p, t, a, s)) self.server.addMsgHandler("/rgb", lambda p, t, a, s: self.set_rgb(p, t, a, s)) self.server.addMsgHandler("/r", lambda p, t, a, s: self.set_r(p, t, a, s)) self.server.addMsgHandler("/g", lambda p, t, a, s: self.set_g(p, t, a, s)) self.server.addMsgHandler("/b", lambda p, t, a, s: self.set_b(p, t, a, s)) self.server.addMsgHandler("/w", lambda p, t, a, s: self.set_w(p, t, a, s)) self.server.addMsgHandler("/hsv", lambda p, t, a, s: self.set_hsv(p, t, a, s)) self.server.addMsgHandler("/h", lambda p, t, a, s: self.set_h(p, t, a, s)) self.server.addMsgHandler("/s", lambda p, t, a, s: self.set_s(p, t, a, s)) self.server.addMsgHandler("/v", lambda p, t, a, s: self.set_v(p, t, a, s)) # Initialize variables self.color = Color(0.0, 0.0, 0.0, 0.0) self.opacity = 0.0 self.timeout = timeout self.timeout_fade_duration = timeout_fade_duration # Setup our animation queue self.anim_queue = AnimationQueue() # The last time we got a message on our socket self.last_msg_time = time.time() # Close the socket on exit def cleanup(self): self.server.close() def got_a_packet(self): self.opacity = 1.0 self.last_msg_time = time.time() self.anim_queue.clear() # Set the current color in either RGB or HSV colorspace def set_rgbw(self, path, tags, args, source): self.color.setRGBW(*args) self.got_a_packet() def set_rgb(self, path, tags, args, source): self.color.setRGB(*args) self.got_a_packet() def set_r(self, path, tags, args, source): print path, tags, args, source self.color.setR(args[0]) self.got_a_packet() def set_g(self, path, tags, args, source): self.color.setG(args[0]) self.got_a_packet() def set_b(self, path, tags, args, source): self.color.setB(args[0]) self.got_a_packet() def set_w(self, path, tags, args, source): self.color.setB(args[0]) self.got_a_packet() def set_hsv(self, path, tags, args, source): self.color.setHSV(*args) self.got_a_packet() def set_h(self, path, tags, args, source): self.color.setH(args[0]) self.got_a_packet() def set_s(self, path, tags, args, source): self.color.setS(args[0]) self.got_a_packet() def set_v(self, path, tags, args, source): self.color.setV(args[0]) self.got_a_packet() # This gets called when we have no more packets waiting to be processed def handle_timeout(self): self.timed_out = True # This function retrieves the next color from the Audio object def next(self, color_in): # process any messages we might have waiting for us. We do this by calling handle_request() until # handle_timeout() gets called, at which point we stop: self.timed_out = False while not self.timed_out: self.server.handle_request() # If we've not received a message for `timeout` seconds, slowly ease back to 1.0 power if self.last_msg_time + self.timeout < time.time( ) and self.opacity != 0.0: # Ease slowly from the current value of self.opacity to 0.0 self.anim_queue.push( ease(self.opacity, 0.0, self.timeout_fade_duration, sin_ease)) # This ensures that once the animation is done, we stay at 0.0, and also that we # don't keep on animating over and over again (e.g. the if statement directly above # doesn't keep on activating over and over again) self.opacity = 0.0 # If we're easing back to 0.0 after a client disconnect, then this animation does something. # If we're receiving packets like normal, this animation does nothing, it just returns self.opacity animated_opacity = self.anim_queue.animate(default_value=self.opacity) # Mix between color_in and our stored self.color return color_in * (1.0 - animated_opacity) + animated_opacity * self.color
#Read markov names_model logging.info("Reading markov language model...\n") with open(markovFilename, 'rb') as f: names_model = pickle.load(f) #Create color tagger basic_colors = [color.name for color in basicColorTerms] colorTagger = ColorTagger(basic_colors) while True: root = tk.Tk() style = ttk.Style(root) style.theme_use('clam') rgb = askcolor((255, 255, 0), root) testColor = Color(rgb[1], rgb[0][0], rgb[0][1], rgb[0][2]) closeColors = closestNColors(testColor, basicColorTerms, 1) logging.debug(":".join([c.name for c in closeColors]) + "\n") #Choose pattern according to distro total = sum(patternCounts.values()) patternString = random.choices( [c for c in patternCounts.keys()], [count / total for count in patternCounts.values()])[0] pattern = patternString.split(",") #Generate some names logging.info( "Generating candidate names using pattern {} for color ({}, {}, {})...\n"