def hsva_rev(iterations, final_val, max_iters):
    if iterations == max_iters: return (0,0,0)

    rslt = Color(0)
    rslt.hsva = (int(360-360*iterations/max_iters), 100, 100, 1)

    return rslt
Example #2
0
def change_saturation(color: Color, value: int) -> Color:
    c = Color(color)
    H, S, V, A = c.hsva
    S += value
    if S > 100:
        S = 100
    elif S < 0:
        S = 0
    c.hsva = (H, S, V, A)
    return c
Example #3
0
def change_brightness(color: Color, value: int) -> Color:
    c = Color(color)
    H, S, V, A = c.hsva
    V += value
    if V > 100:
        V = 100
    elif V < 0:
        V = 0
    c.hsva = (H, S, V, A)
    return c
Example #4
0
File: mob.py Project: MacLeek/mh
    def render(self):
        self.check()
        if self.disabled: return

        pos = self.rect.center

        t = self.mod["eyeType"]

        color0 = (255,255,255)
        color1 = (0,0,0)

        radius = (self.mod["eyeSkill"] + 2) * 3

        color = skinColor(self.mod)

        # we have to determine how big the eye will be before drawing
        size = (radius * 2, radius * 2)
        rect = Rect((0,0), size)

        image = Surface(size)
        image.fill(self.colorkey)
        image.set_colorkey(self.colorkey)

        # locking the surface makes multiple drawing operations quicker
        image.lock()

        # draw the border of the eye
        if radius < 10:
            steps = 16
        else:
            steps = 8

        for t in range(0,360,steps):
            t = radians(t)
            new_color = Color(color.r, color.g, color.b)
            h, s, v, a = new_color.hsva
            v = int(sin(t) * 50) + 50
            if v < 0: v = 0 - v
            new_color.hsva = (h, s, v, a)
            x = int(rect.centerx + cos(t) * (radius - 4))
            y = int(rect.centery + sin(t) * (radius - 4))
            draw.circle(image, new_color, (x, y), 3)

        # draw the white and pupil
        draw.circle(image, color0, rect.center, radius - 3)
        draw.circle(image, color1, rect.center, (radius - 3) / 3)

        image.unlock()

        rect.center = pos

        self.rect = rect
        self.image = image
Example #5
0
 def shift_colour(
     colour,
     hue_multiplier=1.0,
     sat_multiplier=1.0,
     val_multiplier=1.0,
     alpha_multiplier=1.0,
 ):
     new_colour = Color(0, 0, 0)
     new_colour.hsva = tuple([
         colour.hsva[0] * hue_multiplier, colour.hsva[1] * sat_multiplier,
         colour.hsva[2] * val_multiplier, colour.hsva[3] * alpha_multiplier
     ])
     return new_colour
Example #6
0
 def f(surface, rectangle):
     x0, y0, W, H = rectangle
     try:
         l = len(data)
     except:
         pdb.set_trace()
     w = W / l
     try:
         for i in range(0, l):
             h = data[i]
             c = Color(0, 0, 0, 0)
             c.hsva = (0, 100, 100, 0)
             x = x0 + i * w
             y = y0 + H * (1 - h)
             rect(surface, c, \
                     (x, y, 0.9 * w, h * H))
     except:
         pdb.set_trace()
Example #7
0
 def f(surface, rectangle):
     x0, y0, W, H = rectangle
     try:
         l = len(data)
     except:
         pdb.set_trace()
     w = W / l
     try:
         for i in range(0, l):
             h = data[i]
             c = Color(0, 0, 0, 0)
             c.hsva = (0, 100, 100, 0)
             x = x0 + i * w
             y = y0 + H * (1 - h)
             rect(surface, c, \
                     (x, y, 0.9 * w, h * H))
     except:
         pdb.set_trace()
Example #8
0
def circleRays(surface, center, data, transform=lambda y: scipy.log(y + 1)):

    x0, y0 = center

    total = math.radians(360)
    l = len(data)
    m = transform(max(data))
    part = total / l
    for i in range(0, l):
        if m > 0:
            p = transform(data[i])
            h = p * 5
            hue = p / m
            c = Color(0, 0, 0, 0)
            c.hsva = ((1 - hue) * 360, 100, 100, 0)
            x = x0 + (m * 2 + h) * math.cos(part * i)
            y = y0 + (m * 2 + h) * math.sin(part * i)
            line(surface, c, (x0, y0), (x, y), 1)
            circle(surface, c, center, int(m * 2), 0)
Example #9
0
File: mob.py Project: MacLeek/mh
def hsv(color, hsva):
    """
    return a new Color object with the HSV values adjusted

    pygame also includes an alpha channel (a)

    since i want to make simple gradations of value when
    rendering the physical bodies, we need a simple way
    to adjust the HSV values of a color.  the pygame
    Color objects have some functionality, but are missing
    features like this one that we are producing here.
    """

    new = Color(color.r, color.g, color.b, color.a)
    h, s, v, a = new.hsva
    h += hsva[0]
    s += hsva[1]
    v += hsva[2]
    a += hsva[3]
    new.hsva = (h,s,v,a)
Example #10
0
def circleRays(surface, center, data, transform=lambda y: scipy.log(y + 1)):

    x0, y0 = center
    
    total = math.radians(360)
    l = len(data)
    m = transform(max(data))
    part = total/l
    for i in range(0, l):
        if m > 0:
            p = transform(data[i])
            h = p * 5
            hue = p / m
            c = Color(0, 0, 0, 0)
            c.hsva = ((1-hue) * 360, 100, 100, 0)
            x = x0 + (m*2+h)*math.cos(part * i)
            y = y0 + (m*2+h)*math.sin(part*i)
            line(surface, c, 
                    (x0,y0),(x,y),1)
            circle(surface,c, center,int(m*2),0)
Example #11
0
def actual_color(c):
	if type(c) is tuple:
		if len(c) == 3:
			r, g, b = c
			c = Color(r, g, b)
		else:
			r, g, b, a = c
			c = Color(r, g, b, a)
	elif type(c) is Color:
		c = Color(c.r, c.g, c.b, c.a)
	else:
		c = Color(c)
	
	if invert_colors:
		h, s, v, a = c.hsva
		#h = (h + 180.0) % 360.0
		#s = (s + 50.0) % 100.0
		v = (v + 99.9) % 100.0
		c.hsva = (h, s, v, a)
		return c
		return Color(255 - c.r, 255 - c.g, 255 - c.b, c.a)
	else:
		return c
Example #12
0
def random_color(count):
    color = Color("white")
    color.hsva = (count%360, 90, 80, 60)
    return color
Example #13
0
 def random_color(self):
     color = Color("white")
     color.hsva = (random.randint(0,350), 90, 80, 60)
     return color
def hsva_coloring_continuous(iterations, final_val, max_iters):
    if iterations == max_iters: return (0, 0, 0)

    rslt = Color(0)
    rslt.hsva = (int(360*iterations/max_iters), 100, 100, 1)
    return rslt
Example #15
0
def hsvaColor(h, s, v, a=100):
    "Create color from HSVA values"
    c = Color(0)
    c.hsva = h % 360 if h >= 360 else h, s, v, a
    return c