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 __init__(self):
        '''
        Initialize Akintu graphics engine with default settings
        '''
        self.screen = pygame.display.set_mode((
            PANE_X * TILE_SIZE + 256,
            max(PANE_Y * TILE_SIZE, 20 * TILE_SIZE)))
        pygame.display.set_caption('Akintu r01')
        self.background = pygame.Surface((PANE_X * TILE_SIZE,
                                          PANE_Y * TILE_SIZE))
        self.images = dict()
        self.persons = OrderedDict()
        self.personsgroup = pygame.sprite.RenderUpdates()
        self.playerframes = OrderedDict()
        self.monsterframes = OrderedDict()
        self.scrollcount = 0
        self.textsize = 12
        self.sidetext = []
        self.dialog = None
        self.overlays = {}

        overlay_colors = ['blue', 'green', 'red', 'cyan', 'orange', 'black']
        for c in overlay_colors:
            color = Color(c)
            color.a = 50
            self.overlays[c] = generate_overlay(TILE_SIZE, TILE_SIZE, color)

        pygame.display.flip()
        self.turntime = 0
        self.tile_updated = False

        # Draw the sidebar text area and make sure it has at least one item
        # in it (even though it's a blank item)
        self.show_text('')
Example #3
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 #4
0
def get_aa_ellipsis(size, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([size[0] * 5, size[1] * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, size)
    #fill with color using blend_rgba_max
    circle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    circle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    return circle
Example #5
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 #6
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 #7
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 #8
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 #9
0
 def draw(self):
     surface = Surface(self.size, flags=SRCALPHA).convert_alpha()
     rect = Rect((0, 0), self.size)
     color = Color(*self.color)
     alpha = color.a
     color.a = 0
     rectangle = Surface(rect.size, SRCALPHA)
     #ex: [h*3, h*3]
     circle = Surface([min(rect.size) * 5] * 2, SRCALPHA)
     draw.ellipse(circle, (0, 0, 0), circle.get_rect(), 0)
     #ex: [h*0.5, h*.05]
     circle = transform.smoothscale(circle,
                                    [int(self.radius_value)] * 2)
     #now circle is just a small circle of radius self.radius*h (for example)
     #blit topleft circle:
     radius = rectangle.blit(circle, (0, 0))
     #now radius = Rect((0, 0), circle.size), rect=Rect((0, 0), self.size)
     #blit bottomright circle:
     radius.bottomright = rect.bottomright #radius is growing
     rectangle.blit(circle, radius)
     #blit topright circle:
     radius.topright = rect.topright
     rectangle.blit(circle, radius)
     #blit bottomleft circle:
     radius.bottomleft = rect.bottomleft
     rectangle.blit(circle, radius)
     #black-fill of the internal rect
     rectangle.fill((0, 0, 0), rect.inflate(-radius.w, 0))
     rectangle.fill((0, 0, 0), rect.inflate(0, -radius.h))
     #fill with color using blend_rgba_max
     rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
     #fill with alpha-withe using blend_rgba_min in order to make transparent
     #the
     rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
     surface.blit(rectangle, rect.topleft)
     return surface
 def draw():
     screen.fill(Color('white')[:3])
     p.draw(screen)
Example #11
0
 def __init__(self, display):
     super().__init__(display)
     gray_color = random.randint(200, 255)
     self.color = Color(gray_color, gray_color, gray_color, 10)
    def _render_pitch(self):
        surface = self.surface
        field = self.field
        
        white = Color('white')
        surface.fill(Color('darkgreen'))

        fieldmidleft = field.midleft
        fieldmidright = field.midright
        
        #goals
        self.home_goal.draw(surface)
        self.away_goal.draw(surface)

        #penalty_box - left
        goal = self.home_goal.rect        
        pb = pg.Rect(0, 0, goal.width * 3.0, field.height * 0.5)
        pb.midleft = fieldmidleft
        pg.draw.rect(surface,
                     white,
                     pb,
                     1)

        #penalty_box_arc - left
        pbarc = pg.Rect(0, 0, pb.width * 0.35, pb.height * 0.5)
        pbarc.center = pb.midright
        pg.draw.arc(surface,
                    white,
                    pbarc,
                    -math.pi * 0.5,
                    math.pi * 0.5)

        #penalty_spot - left
        pb_spot = Vector2(pbarc.midleft)
        pb_spot.x *= 0.8
        pg.draw.circle(surface,
                       white,
                       (int(pb_spot.x),int(pb_spot.y)),
                       3)

        # penalty-box - right
        pb.midright = fieldmidright
        pg.draw.rect(surface,
                     white,
                     pb,
                     1)
        #penalty_box_arc - right
        pbarc.center = pb.midleft
        pg.draw.arc(surface,
                    white,
                    pbarc,
                    math.pi * 0.5,
                    math.pi * 1.5)

        #penalty_spot -right
        pb_spot = Vector2(pbarc.midright)
        pb_spot.x += (0.2 * (field.width - pbarc.midright[0]))
        pg.draw.circle(surface,
                       white,
                       (int(pb_spot.x),int(pb_spot.y)),
                       3)
        

        # midfield
        x1,y1 = field.midtop
        x1 -= 0
        
        pg.draw.line(surface,
                     white,
                     (x1,y1),(x1,field.height),
                     1)

        # field
        pg.draw.rect(surface,
                     white,
                     field, 
                     2)

        #render the ball
##        self.ball.draw(surface)
##        self.ball.draw()

        
        # walls
        for w in self.walls:
            w.draw(surface,True)
            
        # center circle
        pg.draw.circle(surface,
                       white,
                       field.center,
                       int(field.width * 0.15),
                       1)

        pg.draw.circle(surface,
                       white,
                       field.center,
                       3)                       
Example #13
0
# Cell size
CELL_WIDTH = 50
CELL_HEIGHT = 50
CELL_PAD = 7
CELL_BORDER_SIZE = 2

# Default Number of rows and cols
DEF_ROWS = 9
DEF_COLS = 9

# Number of Walls per player
NUM_WALLS = 10

### COLORS ###
# Font Color & SIZE
FONT_COLOR = Color(0, 10, 50)
FONT_BG_COLOR = Color(255, 255, 255)
FONT_SIZE = 16

# Board Background and Border color and look
BOARD_BG_COLOR = Color(240, 255, 255)
BOARD_BRD_COLOR = Color(0, 0, 40)
BOARD_BRD_SIZE = 1

# Cell colors
CELL_BORDER_COLOR = Color(40, 40, 40)
CELL_COLOR = Color(120, 90, 60)
CELL_VALID_COLOR = Color(40, 120, 120)  # Cyan

# Wall Color
WALL_COLOR = Color(10, 10, 10)
Example #14
0
class Colors():
    ORANGE = Color(255, 140, 0)
    RED = Color(255, 0, 0)
    GREEN = Color(0, 255, 0)
    BLACK = Color(0, 0, 0)
    WHITE = Color(255, 255, 255)
Example #15
0
			self.angle = random.randint(70, 100)
			for i in range(20, 300):
				self.move(i)
				self.left(self.angle)
			self.pen = False
			self.goto_random()
			self.pen = True
			self.num -= 1


#####################################################################

width = 1000				# Width of the window
height = 800				# Height of the window
game = game(width, height)

game.bg_color = Color("white")		# Background color

#####################################################################
# Add sprites here													#
#####################################################################

stage(game)

bob = turtle(game)
bob.costume = "turtle.png"
bob.size = 50

#####################################################################

game.run()
Example #16
0
    def true_color(temperature):
        t = decimal_round(temperature.to('kelvin').m)

        kelvin = [
            2660, 3120, 3230, 3360, 3500, 3680, 3920, 4410, 4780, 5240, 5490,
            5610, 5780, 5920, 6200, 6540, 6930, 7240, 8190, 8620, 9730, 10800,
            12400, 13400, 14500, 15400, 16400, 18800, 22100, 24200, 27000,
            30000, 31900, 35000, 38000
        ]

        hexs = [
            '#ffad51', '#ffbd71', '#ffc177', '#ffc57f', '#ffc987', '#ffcd91',
            '#ffd39d', '#ffddb4', '#ffe4c4', '#ffead5', '#ffeedd', '#ffefe1',
            '#fff1e7', '#fff3eb', '#fff6f3', '#fff9fc', '#f9f6ff', '#f2f2ff',
            '#e3e8ff', '#dde4ff', '#d2dcff', '#cad6ff', '#c1d0ff', '#bccdff',
            '#b9caff', '#b6c8ff', '#b4c6ff', '#afc2ff', '#abbfff', '#a9bdff',
            '#a7bcff', '#a5baff', '#a4baff', '#a3b8ff', '#a2b8ff'
        ]

        if t in kelvin:
            return Color(hexs[kelvin.index(t)])

        elif t < kelvin[0]:
            # "extrapolación" lineal positiva
            despues = 1
            antes = 0
        elif t > kelvin[-1]:
            # "extrapolación" lineal nagativa
            despues = -1
            antes = -2
        else:
            # interpolación lineal
            despues = bisect_right(kelvin, t)
            antes = despues - 1

        x1 = kelvin[antes]
        x2 = kelvin[despues]

        y1 = Color((hexs[antes]))
        y2 = Color((hexs[despues]))

        diff_x = x2 - x1
        ar = (y2.r - y1.r) / diff_x
        ag = (y2.g - y1.g) / diff_x
        ab = (y2.b - y1.b) / diff_x

        br = y1.r - ar * x1
        bg = y1.g - ag * x1
        bb = y1.b - ab * x1

        x = t - x1 if t > x1 else x1 - t

        def cap(number):
            if number >= 255:
                return 255
            elif number <= 0:
                v = abs(number)
                return cap(v)
            else:
                return number

        r = cap(decimal_round(ar * x + br))
        g = cap(decimal_round(ag * x + bg))
        b = cap(decimal_round(ab * x + bb))

        color = Color(r, g, b)
        return color
Example #17
0
from math import *  # 从数学模块导入函数
from pygame import Color  # 从pygame导入Color类


def coloradd(color, dh):
    """
       颜色增加函数,本函数把颜色的色相进行增加,其它指标不变。
       color:Color实例化后的颜色
       dh:一个int,色相增加的值
    """
    h, s, v, a = color.hsva
    h = h + dh  # 色相增加
    h = h % 360  # 不能超过360
    color.hsva = h, s, v, a  # 设定颜色的hsva值
    return Color(*color)  # 返回颜色实例


width, height = 480, 360
screen = turtle.getscreen()
screen.setup(width, height)
screen.title("turtle和pygame结合的彩色螺旋图www.lixingqiu.com")
screen.colormode(255)
screen.delay(0)
turtle.width(30)
yanse = Color('red')
for i in range(2200):
    turtle.color(yanse[:-1])
    turtle.fd(i)
    turtle.rt(35)
    yanse = coloradd(yanse, 1)
screen.mainloop()
Example #18
0
# Pipe Mania
from math import floor
from pygame import image, Color, Surface
from random import randint

w, h = 10, 7
matrix = [[0 for x in range(w)] for y in range(h)]
tileSize = 68
panelPosition = (96, 96)
numberNextTiles = 5
nextTiles = [randint(2, 8) for y in range(numberNextTiles)]
nextTilesPosition = (16, 28)
tileMouse = (-1, -1)

waterWays = Surface((w * tileSize, h * tileSize))
waterWays.fill(Color('black'))

tiles = [
    'empty', 'start', 'hori', 'vert', 'cross', 'bottomleft', 'bottomright',
    'topleft', 'topright'
]

ways = [image.load('images/' + tiles[i] + '_way.png') for i in range(1, 9)]

matrix[3][2] = 1  # start tile
waterWays.blit(ways[0], (2 * tileSize, 3 * tileSize))
currentPoint = (2 * tileSize + 43, 3 * tileSize + 34)
waterFlow = []
start = 60 * 30  # 30 seconds

playState = 1
Example #19
0
 def setColor(self, colorString):
     self.color = Color(colorString)
     self.colorString = colorString
Example #20
0
        for btn in self.buttons:
            if btn.is_active(mouse_pos):
                btn.pressed()

    def add_btn(self, btn):
        if type(btn) is Button_menu:
            self.buttons.append(btn)


if __name__ == '__main__':
    pygame.init()

    width, height = 1280, 720
    screen = pygame.display.set_mode((width, height))

    menu = Menu(screen, width, height, image="resource/menu/background.jpg")

    while True:
        screen.fill(Color("white"))

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                exit(0)
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    menu.get_pressed(pygame.mouse.get_pos())

        menu.draw()
        pygame.display.flip()
Example #21
0
 def draw(self):
     surface = self._11l111_opy_.get_surface()
     color = Color(self._1111ll_opy_)
     l1llllll_opy_(surface, color, self._1l1l1_opy_, self._1llll1l_opy_)
Example #22
0
def draw_dot(game, dot):
    surface = game.window.get_surface()
    color = Color(dot.color)
    draw_circle(surface, color, dot.center, dot.radius)
Example #23
0
from pygame import Color

BLACK  = Color(0, 0, 0)
WHITE  = Color(255, 255, 255)
GREEN  = Color(0, 255, 0)
RED    = Color(255, 0, 0)
BLUE   = Color(0, 0, 255)
YELLOW = Color(255, 200, 0)
GREY   = Color(160, 160, 160)
ICE    = Color(92, 247, 251)

GREEN_A50  = Color(0, 255, 0, 50)
RED_A50    = Color(255, 0, 0, 50)
BLUE_A50   = Color(0, 0, 255, 50)
YELLOW_A50 = Color(255, 200, 0, 50)
GREY_A50   = Color(160, 160, 160, 50)
GREY_A200  = Color(100, 100, 100, 200)

SELECTED = Color(255, 200, 0, 100)
MOVE     = Color(0, 0, 255, 75)
ATTACK   = Color(255, 0, 0, 75)
PLAYED   = Color(75, 75, 75, 150)

MENU_SEL = Color(96, 144, 145)
MENU_BG  = Color(51, 51, 51)

TRANSPARENT = Color(0, 0, 0, 0)
class Life:

    name = "Null Life Form"
    x = int(width / 2)
    y = int(height / 2)
    color = Color(255, 0, 0, 0)
    radius = 15
    sexy = 1

    Food = 1

    ini_speed = 1
    speed = 1

    intelligence = 2
    Violence = 0
    Altruism = 0

    offsprings = 0
    #loffsprings = []

    life = 144
    HoursSinceReproduction = 0

    def Think(self):
        if self.Violence < 1:
            if self.Food < 6 or self.HoursSinceReproduction < 6:
                if len(self.getFoodForms()) > 0:
                    if self.intelligence >= 3:
                        x, y = self.locateSmartClosestFood()
                    else:
                        x, y = self.locateClosestFood()
                    self.Move(x, y)
            else:
                clLife = self.closestLife()
                if (clLife.Food > 6 and clLife.HoursSinceReproduction < 2
                    ) or self.intelligence < 2 or (
                        clLife.Food > 6 and (clLife.sexy + self.sexy) / 2 >
                        clLife.HoursSinceReproduction / 4):
                    # Look for sex
                    x, y = self.locateClosestLife()
                    self.Move(x, y)
                else:
                    if len(self.getFoodForms()) > 0:
                        if self.intelligence >= 3:
                            x, y = self.locateSmartClosestFood()
                        else:
                            x, y = self.locateClosestFood()
                        self.Move(x, y)
        elif self.Violence >= 1:
            if self.Food < 6:
                if len(self.getFoodForms()) > 0:
                    if self.intelligence >= 3:
                        x, y = self.locateSmartClosestFood()
                    else:
                        x, y = self.locateClosestFood()
                    d = 0
                    if len(LifeForms) > 1:
                        clLife = self.closestLife()
                        x1, y1 = clLife.x, clLife.y
                        d = self.distanceTo(x1, y1)
                        if d < self.distanceTo(x, y) and len(
                                LifeForms) > 1 and clLife.Violence == 0:
                            if d < self.radius + clLife.radius:
                                self.Murder(clLife)
                            else:
                                self.Move(x1, y1)
                    else:
                        self.Move(x, y)
            else:
                clLife = self.closestLife()
                if (clLife.Food > 6 and clLife.HoursSinceReproduction < 2
                    ) or self.intelligence < 2 or (
                        clLife.Food > 6 and (clLife.sexy + self.sexy) / 2 >
                        clLife.HoursSinceReproduction / 4):
                    # Look for sex
                    x, y = self.locateClosestLife()
                    self.Move(x, y)
                else:
                    if len(self.getFoodForms()) > 0:
                        if self.intelligence >= 3:
                            x, y = self.locateSmartClosestFood()
                        else:
                            x, y = self.locateClosestFood()
                        self.Move(x, y)

    def Birth(self,
              surface,
              name,
              x,
              y,
              color,
              ini_speed,
              sexy,
              intelligence,
              Altruism=0,
              Violence=0):
        self.name = name
        self.x = x
        self.y = y
        self.color = color
        self.surface = surface
        self.sexy = sexy
        self.ini_speed = ini_speed
        self.speed = math.ceil(ini_speed)
        self.intelligence = intelligence
        self.Violence = Violence
        self.Altruism = Altruism

    def Kill(self):
        #self.x=0
        #self.y=0
        #self.color = "Brown"
        #self.name = "Deceased (" + self.name +")"
        RemoveLife(self)
        self.life = 144
        self.offsprings = 0

    def Move(self, toX, toY):
        #print("Am at:",self.x,self.y,"Going to:",toX,toY)
        if abs(toX - self.x) > abs(toY - self.y):
            if abs(toX - self.x) > self.speed:
                if toX - self.x < 0:
                    self.x -= self.speed
                else:
                    self.x += self.speed
            else:
                self.x = toX
        else:
            if abs(toY - self.y) > self.speed:
                if toY - self.y < 0:
                    self.y -= self.speed
                else:
                    self.y += self.speed
            else:
                self.y = toY

    def detectColissions(self):
        for foodForm in self.getFoodForms():
            #print("Distance",self.distanceTo(foodForm.x,foodForm.y))
            if self.distanceTo(foodForm.x,
                               foodForm.y) < foodForm.radius + self.radius:
                self.eat(foodForm.feed)
                foodForm.Remove()
        for lifeForm in self.getLifeFormsNotMe():
            if self.distanceTo(lifeForm.x,
                               lifeForm.y) < lifeForm.radius + self.radius:
                self.TryToReproduce(lifeForm)

    lastLifeFormColission = None
    colissionTimes = 0

    def PunishForClotting(self):
        colided = None
        for lifeForm in self.getLifeFormsNotMe():
            if self.distanceTo(lifeForm.x,
                               lifeForm.y) < lifeForm.radius + self.radius:
                colided = lifeForm
                if self.lastLifeFormColission == lifeForm:
                    self.Food -= self.colissionTimes
                    self.colissionTimes += 1
                    self.x += pm(self.radius)
                    self.y += pm(self.radius)
                else:
                    self.lastLifeFormColission = lifeForm
                    self.colissionTimes = 0
        if colided == None:
            self.lastLifeFormColission = None
            self.colissionTimes = 0

    def Murder(self, lifeForm):
        self.Food += lifeForm.Food
        #self.ini_speed =(lifeForm.speed / 10) + self.ini_speed
        self.intelligence = (lifeForm.intelligence / 10) + self.intelligence
        self.sexy -= 0.1 * self.sexy
        lifeForm.Kill()
        #print(self.name,"Murdering: " + lifeForm.name)

    def TryToReproduce(self, partner):
        #print("Trying to f**k", "Will it work? ", randomChance(5 / ((self.sexy + partner.sexy)/2)) and self.Food > 5 and partner.Food > 5)
        if (
                self.Food > 5 and partner.Food > 5 or
            (self.Food + partner.Food > 10 and self.Altruism > 0)
        ) and self.HoursSinceReproduction < 1 and partner.HoursSinceReproduction < 1:
            if randomChance(5 / ((self.sexy + partner.sexy) / 2)):
                newLife = Life()
                x, y = int((self.x + partner.x) / 2), int(
                    (self.y + partner.y) / 2)
                n = randomName(True)
                newLife.Birth(
                    surface,
                    n,
                    x,
                    y,
                    self.averageColor(partner),
                    mut((self.ini_speed + partner.ini_speed) / 2),
                    mut((self.sexy + partner.sexy) / 2),
                    mut((self.intelligence + partner.intelligence) / 2),
                    Violence=mut((self.Violence + partner.Violence) / 2),
                    Altruism=mut((self.Altruism + partner.Altruism) / 2))
                LifeForms.append(newLife)
                #self.loffsprings.append(newLife)
                #partner.loffsprings.append(newLife)
                #print(n,"was born!")
                if partner.Food <= 5 and self.Altruism > 0:
                    self.Food -= 11 - partner.Food
                    partner.Food = 0
                else:
                    self.Food -= 5
                    partner.Food -= 5
                self.offsprings += 1
                partner.offsprings += 1
                self.HoursSinceReproduction = 6
                partner.HoursSinceReproduction = 6
                if self.Altruism >= 1:
                    newLife.Food += int(self.Food / 2)
                    self.Food -= int(self.Food / 2)
                if partner.Altruism >= 1:
                    newLife.Food += int(partner.Food / 2)
                    partner.Food -= int(partner.Food / 2)
            elif self.Violence >= 2 and partner.Violence <= 1:
                #self.Food-=5
                #partner.Food-=5
                #clLife = self.closestLife()
                x1, y1 = partner.x, partner.y
                d = self.distanceTo(x1, y1)
                if d < self.radius + partner.radius:
                    self.Murder(partner)
                else:
                    self.Move(x1, y1)

    def averageColor(self, partner):
        r, g, b = int(mut((self.color.r + partner.color.r) / 2)), int(
            mut((self.color.g + partner.color.g) / 2)), int(
                mut((self.color.b + partner.color.b) / 2))
        if r > 255: r = 255
        if g > 255: g = 255
        if b > 255: b = 255
        return pygame.Color(r, g, b, 0)

    def distanceTo(self, x, y):
        return ((x - self.x)**2 + (y - self.y)**2)**0.5

    def locateClosestFood(self):
        FoodForms = self.getFoodForms()
        closest = FoodForms[0]
        closestVal = self.distanceTo(closest.x, closest.y)
        for foodForm in FoodForms:
            if self.distanceTo(foodForm.x, foodForm.y) < closestVal:
                closest = foodForm
                closestVal = self.distanceTo(foodForm.x, foodForm.y)
        return closest.x, closest.y

    def locateSmartClosestFood(self):
        FoodForms = self.getFoodForms()
        closest = FoodForms[0]
        closestVal = self.distanceTo(closest.x, closest.y)
        for foodForm in FoodForms:
            if (self.distanceTo(foodForm.x, foodForm.y) / Food.feed <
                    closestVal):
                closest = foodForm
                closestVal = self.distanceTo(foodForm.x,
                                             foodForm.y) / Food.feed
        return closest.x, closest.y

    def eat(self, food):
        self.Food += food
        self.radius = int(15 * (1 + ((abs(self.Food)**0.5) / 4)))
        #if self.Food > 10:
        #    self.speed = math.ceil(self.ini_speed) * speed #math.ceil(self.ini_speed / ((self.Food / 10)**0.5))
        #else:
        #    self.speed = math.ceil(self.ini_speed) * speed

    def locateClosestLife(self):
        aLifeForms = self.getLifeFormsNotMe()
        if not len(aLifeForms) == 0:
            closest = NullForm
            closestVal = self.distanceTo(closest.x, closest.y)
            for lifeForm in aLifeForms:
                if self.distanceTo(
                        lifeForm.x,
                        lifeForm.y) < closestVal and lifeForm.Food > 5:
                    closest = lifeForm
                    closestVal = self.distanceTo(lifeForm.x, lifeForm.y)
            return closest.x + closest.radius, closest.y + closest.radius
        else:
            EndSimulation()
            return self

    def closestLife(self):
        aLifeForms = self.getLifeFormsNotMe()
        if not len(aLifeForms) == 0:
            closest = NullForm
            closestVal = self.distanceTo(closest.x, closest.y)
            for lifeForm in aLifeForms:
                if self.distanceTo(
                        lifeForm.x,
                        lifeForm.y) < closestVal and lifeForm.Food > 5:
                    closest = lifeForm
                    closestVal = self.distanceTo(lifeForm.x, lifeForm.y)
            return closest
        else:
            EndSimulation()
            return self

    def getLifeForms(self):
        return LifeForms

    def getFoodForms(self):
        return FoodForms

    def getLifeFormsNotMe(self):
        tmpLifeForms = LifeForms.copy()
        try:
            tmpLifeForms.remove(self)
        except:
            return tmpLifeForms
        return tmpLifeForms
Example #25
0
 def draw(self):
     # draw the dot on the screen
     surface = self._window.get_surface()
     color = Color(self._color)
     draw_circle(surface, color, self._center, self._radius)
Example #26
0
    def __init__(self):
        pygame.init()

        self.screen = pygame.display.set_mode(
            (self.SCREEN_WIDTH, self.SCREEN_HEIGHT), 0, 32)
        self.tile_img = pygame.image.load(self.BG_TILE_IMG).convert_alpha()
        self.tile_img_rect = self.tile_img.get_rect()

        self.field_border_width = 4
        field_outer_width = self.FIELD_SIZE[0] + 2 * self.field_border_width
        field_outer_height = self.FIELD_SIZE[1] + 2 * self.field_border_width
        self.field_rect_outer = Rect(20, 60, field_outer_width,
                                     field_outer_height)
        self.field_bgcolor = Color(109, 41, 1, 100)
        self.field_border_color = Color(0, 0, 0)
        self.field_box = Box(self.screen,
                             rect=self.field_rect_outer,
                             bgcolor=self.field_bgcolor,
                             border_width=self.field_border_width,
                             border_color=self.field_border_color)

        self.tboard_text = ['The amazing Creeps!']
        self.tboard_rect = Rect(20, 20, field_outer_width, 30)
        self.tboard_bgcolor = Color(50, 20, 0)
        self.tboard = MessageBoard(self.screen,
                                   rect=self.tboard_rect,
                                   bgcolor=self.tboard_bgcolor,
                                   border_width=4,
                                   border_color=Color('black'),
                                   text=self.tboard_text,
                                   font=('tahoma', 18),
                                   font_color=Color('yellow'))

        self.mboard_text = []
        self.mboard_rect = Rect(440, 60, 120, 60)
        self.mboard_bgcolor = Color(50, 20, 0)
        self.mboard = MessageBoard(self.screen,
                                   rect=self.mboard_rect,
                                   bgcolor=self.mboard_bgcolor,
                                   border_width=4,
                                   border_color=Color('black'),
                                   text=self.mboard_text,
                                   font=('verdana', 16),
                                   font_color=Color('white'))

        self.clock = pygame.time.Clock()
        self.paused = False

        self.creep_images = [(pygame.image.load(f1).convert_alpha(),
                              pygame.image.load(f2).convert_alpha())
                             for (f1, f2) in self.CREEP_FILENAMES]

        explosion_img = pygame.image.load(
            'images/explosion1.png').convert_alpha()
        self.explosion_images = [
            explosion_img,
            pygame.transform.rotate(explosion_img, 90)
        ]

        self.field_rect = self.get_field_rect()

        self.entrance_rect = Rect(self.field_rect.left, self.field_rect.top,
                                  self.GRID_SIZE * 2, self.GRID_SIZE * 2)

        self.exit_rect = Rect(self.field_rect.right - self.GRID_SIZE * 2,
                              self.field_rect.bottom - self.GRID_SIZE * 2,
                              self.GRID_SIZE * 2, self.GRID_SIZE * 2)

        # Create the creeps group and the first creep
        self.creeps = pygame.sprite.Group()
        self.spawn_new_creep()

        self.creep_spawn_timer = Timer(500, self.spawn_new_creep)

        self.create_walls()

        # Create the grid-path representation of the field
        #
        self.grid_nrows = self.FIELD_SIZE[1] / self.GRID_SIZE
        self.grid_ncols = self.FIELD_SIZE[0] / self.GRID_SIZE
        self.goal_coord = (self.grid_nrows - 1, self.grid_ncols - 1)
        self.gridpath = GridPath(nrows=int(self.grid_nrows),
                                 ncols=int(self.grid_ncols),
                                 goal=self.goal_coord)

        for wall in self.walls:
            self.gridpath.set_blocked(wall)

        self.options = dict(draw_grid=False)
Example #27
0
            self.surface.blit(line_sf, (x_pos, y_pos))
            y_pos += line_sf.get_height()


##################################################################
##################################################################

if __name__ == "__main__":
    pygame.init()

    SCREEN_WIDTH, SCREEN_HEIGHT = 350, 550
    screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), 0, 32)
    clock = pygame.time.Clock()

    box = Box(screen, Rect(20, 20, 40, 40), Color('brown4'), 0, Color('red'))
    mb = MessageBoard(screen,
                      Rect(80, 100, 200, 55),
                      ["Bozo", "Jorna da asasdasdfdgdfgd"],
                      border_width=2,
                      border_color=Color('yellow'),
                      font=('verdana', 16))

    while True:
        time_passed = clock.tick(30)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        box.draw()
Example #28
0
from pygame import Color

BLACK = Color(0, 0, 0, 255)
WHITE = Color(255, 255, 255, 255)
RED = Color(255, 0, 0, 255)
LIME = Color(0, 255, 0, 255)
BLUE = Color(0, 0, 255, 255)
YELLOW = Color(255, 255, 0, 255)
CYAN = Color(0, 255, 255, 255)
AQUA = CYAN  # because they're the same
MAGENTA = Color(255, 0, 255, 255)
FUCHSIA = MAGENTA  # because they're the same
SILVER = Color(192, 192, 192, 255)
GRAY = Color(128, 128, 128, 255)
GREY = GRAY
MAROON = Color(128, 0, 0, 255)
OLIVE = Color(128, 128, 0, 255)
GREEN = Color(0, 128, 0, 255)
PURPLE = Color(128, 0, 128, 255)
TEAL = Color(0, 128, 128, 255)
NAVY = Color(0, 0, 128, 255)
DARK_RED = Color(139, 0, 0, 255)
BROWN = Color(165, 42, 42, 255)
FIREBRICK = Color(178, 34, 34, 255)
CRIMSON = Color(220, 20, 60, 255)
TOMATO = Color(255, 99, 71, 255)
CORAL = Color(255, 127, 80, 255)
INDIAN_RED = Color(205, 92, 92, 255)
LIGHT_CORAL = Color(240, 128, 128, 255)
DARK_SALMON = Color(233, 150, 122, 255)
SALMON = Color(250, 128, 114, 255)
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 #30
0
    def visible_color(frequency):
        color = None
        if 43.4941208 < frequency < 1664.635167:
            if 43.4941208 <= frequency <= 400:
                color = Color(0, 0, 0)
            elif 400 <= frequency <= 410:
                color = Color(37, 12, 83)
            elif 410 <= frequency <= 420:
                color = Color(66, 28, 163)
            elif 420 <= frequency <= 430:
                color = Color(96, 37, 247)
            elif 430 <= frequency <= 440:
                color = Color(78, 55, 232)
            elif 440 <= frequency <= 450:
                color = Color(63, 73, 217)
            elif 450 <= frequency <= 460:
                color = Color(58, 92, 203)
            elif 460 <= frequency <= 470:
                color = Color(63, 111, 188)
            elif 470 <= frequency <= 480:
                color = Color(68, 120, 173)
            elif 480 <= frequency <= 490:
                color = Color(73, 129, 157)
            elif 490 <= frequency <= 500:
                color = Color(78, 138, 143)
            elif 500 <= frequency <= 510:
                color = Color(83, 147, 128)
            elif 510 <= frequency <= 520:
                color = Color(88, 156, 114)
            elif 520 <= frequency <= 530:
                color = Color(93, 165, 100)
            elif 530 <= frequency <= 540:
                color = Color(99, 175, 87)
            elif 540 <= frequency <= 550:
                color = Color(115, 190, 76)
            elif 550 <= frequency <= 560:
                color = Color(141, 206, 68)
            elif 560 <= frequency <= 570:
                color = Color(175, 222, 62)
            elif 570 <= frequency <= 580:
                color = Color(214, 238, 59)
            elif 580 <= frequency <= 590:
                color = Color(255, 255, 60)
            elif 590 <= frequency <= 600:
                color = Color(234, 169, 40)
            elif 600 <= frequency <= 610:
                color = Color(223, 86, 15)
            elif 610 <= frequency <= 620:
                color = Color(219, 0, 0)
            elif 620 <= frequency <= 630:
                color = Color(197, 0, 0)
            elif 630 <= frequency <= 640:
                color = Color(174, 0, 0)
            elif 640 <= frequency <= 650:
                color = Color(152, 0, 0)
            elif 650 <= frequency <= 660:
                color = Color(130, 0, 0)
            elif 660 <= frequency <= 670:
                color = Color(109, 0, 0)
            elif 670 <= frequency <= 680:
                color = Color(87, 0, 0)
            elif 680 <= frequency <= 690:
                color = Color(67, 0, 0)
            elif 690 <= frequency <= 700:
                color = Color(47, 0, 0)
            elif 700 <= frequency <= 710:
                color = Color(27, 0, 0)
            elif 710 <= frequency <= 1664.635167:
                color = Color(0, 0, 0)

        return color
Example #31
0
from src.models import Hole as BaseHole
from src.sprites import *
from src.utils import colors, Point


Hole = BaseHole(
    'Hole #4',
    par=4,
    origin=Point(50, 100, 0),
    ball=Point(312, 580, 0),
    noncollidibles=LayeredDirty(
        Text(Point(900, 268), 'Par 4', font.Font(None, 30), colors.WHITE),
    ),
    collidibles=LayeredDirty(
        Green([Point(250, 600, 0), Point(250, 150, 0), Point(370, 150, 0), Point(370, 250, 0), Point(770, 250, 0), Point(770, 150, 0), Point(870, 150, 0), Point(870, 400, 0), Point(770, 400, 0), Point(770, 300, 0), Point(370, 300, 0), Point(370, 600, 0)]),
        Slope([Point(250, 150, 0), Point(250, 90, 0), Point(370, 90, 0), Point(370, 150, 0)], Color(100, 0, 0, 255), Vector2(0.0, -0.7)),
        Sand([Point(250, 90, 0), Point(250, 50, 0), Point(370, 50, 0), Point(370, 90, 0)]),
        Slope([Point(410, 250, 0), Point(410, 200, 0), Point(770, 200, 0), Point(770, 250, 0)], Color(100, 0, 0, 255), Vector2(-0.33, -0.6)),
        Slope([Point(410, 300, 0), Point(410, 360, 0), Point(770, 360, 0), Point(770, 300, 0)], Color(100, 0, 0, 255), Vector2(-0.33, 0.6)),
        Rough([Point(410, 200, 0), Point(410, 150, 0), Point(770, 150, 0), Point(770, 200, 0)]),
        Rough([Point(770, 400, 0), Point(410, 400, 0), Point(410, 360, 0), Point(770, 360, 0)]),
        Pin(Point(840, 275, 0)),
        Money(Point(305, 200)),
        Wall(Point(250, 50, 0), Point(370, 50, 0), 5),
        Wall(Point(370, 50, 0), Point(370, 250, 0), 5),
        Wall(Point(370, 250, 0), Point(410, 250, 0), 5),
        Wall(Point(410, 250, 0), Point(410, 150, 0), 5),
        Wall(Point(410, 150, 0), Point(870, 150, 0), 5),
        Wall(Point(870, 150, 0), Point(870, 400, 0), 5),
        Wall(Point(870, 400, 0), Point(410, 400, 0), 5),
        Wall(Point(410, 400, 0), Point(410, 300, 0), 5),
Example #32
0
def l1ll11l1_opy_(dot):
    surface = dot.window.get_surface()
    color = Color(dot.color)
    l1llllll_opy_(surface, color, dot.center, dot.l1l1ll1_opy_)
Example #33
0
 def __init__(self):
     center_pixel = Pixel_xy(
         (uniform(0, SCREEN_PIXEL_WIDTH()), uniform(0,
                                                    SCREEN_PIXEL_HEIGHT())))
     color = utils.color_random_variation(Color('yellow'))
     super().__init__(center_pixel=center_pixel, color=color, scale=1)
Example #34
0
 def _set_bg_color(self):
     """ Set the standard background color by pygame name. """
     c = (self._create_color(self._bg_color)
          or Color(0, 0, 0, 255).normalize())
     self.screen.set(bgcolor=c)
Example #35
0
DIR_BASE = os.path.dirname(__file__)
DIR_ASSETS = os.path.join(DIR_BASE,"data")
DIR_FONDOS = os.path.join(DIR_ASSETS,"bck")
DIR_ELEMENTOS = os.path.join(DIR_FONDOS,"elements")
DIR_UI = os.path.join(DIR_ASSETS,"ui")
DIR_FONTS = os.path.join(DIR_ASSETS,"fonts")

########## Colores ##########
NEGRO = (0,0,0)
BLANCO = (255,255,255)
VERDE = (0,255,0)

BLUEBERRY = (26,115,232)

# Paleta de colores del Simulador
BEIGE_0 = Color("#f4e3d7")
BEIGE_1 = Color("#e9c6af")
BEIGE_2 = Color("#deaa87")
BEIGE_3 = Color("#d38d5f")
BEIGE_4 = Color("#c87137")
BEIGE_5 = Color("#a05a2c")
BEIGE_6 = Color("#784421")
BEIGE_7 = Color("#502d16")
BEIGE_8 = Color("#28170b")

########## Tipografía ##########
VIDALOKA = os.path.join(DIR_FONTS,"Vidaloka-Regular.ttf")

########### Constantes ###########
# Mouse
MOUSE_IZQUIERDO = 1
Example #36
0
 def treat_colors(self):
     for k, v in self.colors.items():
         if isinstance(v, str):
             self.colors[k] = Color(v)
         elif isinstance(v, list):
             self.colors[k] = [Color(i) for i in v]
Example #37
0
CAMERA_HEIGHT = 1300
CAMERA_DEPTH = 1 / math.tan((FIELD_OF_VIEW / 2) * math.pi / 180)
BOTTOM_OFFSET = 5
SPEED_BOOST_DECREASE = 0.004
SPEED_BOOST_LENGTH = 50
HARD_TOP_SPEED = [(SEGMENT_HEIGHT / (1.0 / FPS)) * 1.5,
                  (SEGMENT_HEIGHT / (1.0 / FPS)) * 2.4]
HARD_HANDLING = [0.1, 0.45]
HARD_ACCELERATION = [2.0, 7.0]
PLAYER_Z = (CAMERA_HEIGHT * CAMERA_DEPTH)
FONTS = {
    "retro_computer": os.path.join("lib", "PressStart2P.ttf"),
    "fipps": os.path.join("lib", "Fipps-Regular.otf")
}
COLOURS = {
    "white": Color(255, 255, 255),
    "opaque_white": Color(255, 255, 255, 80),
    "text": Color(172, 199, 252),
    "dark_text": Color(57, 84, 137),
    "selection": [Color(172, 199, 252),
                  Color(100, 149, 252)],
    "sky": Color(10, 10, 10),
    "gutter": Color(100, 100, 100),
    "red": Color(204, 0, 0),
    "bonus_a": Color(255, 78, 0),
    "bonus_b": Color(255, 178, 0),
    "green": Color(0, 204, 0),
    "black": Color(0, 0, 0),
    "tunnel": Color(38, 15, 8)
}
LEVELS = [{
Example #38
0
# pygame must be initialized before we can create a Font.
pygame.init()
try:
    # "data.py" is a skellington-ism. The included custom version supports
    # subdirectories by type.
    import data
except:
    print 'warning: no data.py in module path: proceeding without it'
finally:
    try:
        font = pygame.font.Font(data.filepath('font', 'Vera.ttf'), 14)
    except:
        print 'warning: cannot load font Vera.ttf: using system default'
        font = pygame.font.SysFont(None, 20)

bg_color = Color('grey')
hi_color = Color(155, 155, 155)
text_color = Color('black')
glint_color = Color(220, 220, 220)
shadow_color = Color(105, 105, 105)

margin = 2


class PopupMenu(object):
    """popup_menu.PopupMenu
    PopupMenu(data, block=True) : return menu
    
    data -> list; the list of strings and nested lists.
    pos -> tuple; the xy screen coordinate for the topleft of the main menu; if
        None, the mouse position is used.
Example #39
0
 def _set_font_color(self):
     """ Set the standard font color by pygame name. """
     self._font_color = (self._create_color(self._font_color_name)
                         or Color(1, 1, 1, 255).normalize())
Example #40
0
def random_color(count):
    color = Color("white")
    color.hsva = (count%360, 90, 80, 60)
    return color
Example #41
0
 def random_color(self):
     color = Color("white")
     color.hsva = (random.randint(0,350), 90, 80, 60)
     return color
Example #42
0
 def __init__(self, pos, *groups):
     super().__init__(*groups)
     self.image = Surface((TILE_SIZE, TILE_SIZE))
     self.image.fill(Color("#DDDDDD"))
     self.rect = self.image.get_rect(topleft=pos)
Example #43
-1
def get_aa_round_rect(size, radius, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    rectangle = Surface(size, SRCALPHA)
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([min(size) * 5, min(size) * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, (2*radius, 2*radius))
    #now circle is just a small circle of radius
    #blit topleft circle:
    radius_rect = rectangle.blit(circle, (0, 0))
    #now radius_rect = Rect((0, 0), circle.size), rect=Rect((0, 0), size)
    #blit bottomright circle:
    radius_rect.bottomright = rect.bottomright #radius_rect is growing
    rectangle.blit(circle, radius_rect)
    #blit topright circle:
    radius_rect.topright = rect.topright
    rectangle.blit(circle, radius_rect)
    #blit bottomleft circle:
    radius_rect.bottomleft = rect.bottomleft
    rectangle.blit(circle, radius_rect)
    #black-fill of the internal rect
    rectangle.fill((0, 0, 0), rect.inflate(-radius_rect.w, 0))
    rectangle.fill((0, 0, 0), rect.inflate(0, -radius_rect.h))
    #fill with color using blend_rgba_max
    rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    #the
    rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    surface.blit(rectangle, rect.topleft)
    return surface