Python pygame.color() Examples
The following are 30
code examples of pygame.color().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.
Example #1
Source File: Utils.py From Carrom_rl with GNU General Public License v3.0 | 6 votes |
def init_pockets(space): pockets = [] for i in [(44.1, 43.1), (756.5, 43), (756.5, 756.5), (44, 756.5)]: inertia = pymunk.moment_for_circle(0.1, 0, POCKET_RADIUS, (0, 0)) body = pymunk.Body(0.1, inertia) body.position = i shape = pymunk.Circle(body, POCKET_RADIUS, (0, 0)) shape.color = POCKET_COLOR shape.collision_type = 2 shape.filter = pymunk.ShapeFilter(categories=0b1000) space.add(body, shape) pockets.append(shape) del body del shape return pockets # Initialize striker with force
Example #2
Source File: pong.py From kvae with MIT License | 6 votes |
def add_walls(self): self.static_lines = [] # Add floor self.static_lines.append(pymunk.Segment(self.space.static_body, (0, 1), (self.res[1], 1), .0)) # Add roof self.static_lines.append(pymunk.Segment(self.space.static_body, (0, self.res[1]), (self.res[1], self.res[1]), .0)) # Set properties for line in self.static_lines: line.elasticity = .99 line.color = color["white"] self.space.add(self.static_lines) return True
Example #3
Source File: Program.py From PTVS-Samples with Apache License 2.0 | 6 votes |
def main(): """Initialize and run the game.""" pygame.init() # Initialize PyGame screen = pygame.display.set_mode(WINDOW_SIZE, 0, 16) pygame.display.set_caption('Python Kinect Game') screen.fill(pygame.color.THECOLORS["black"]) with nui.Runtime() as kinect: kinect.skeleton_engine.enabled = True kinect.skeleton_frame_ready += post_frame # Main game loop while True: event = pygame.event.wait() if event.type == pygame.QUIT: break elif event.type == KINECTEVENT: # process e.skeletons here pass
Example #4
Source File: Utils.py From Carrom_rl with GNU General Public License v3.0 | 6 votes |
def init_striker(space, x, passthrough, action, player): inertia = pymunk.moment_for_circle(STRIKER_MASS, 0, STRIKER_RADIUS, (0, 0)) body = pymunk.Body(STRIKER_MASS, inertia) if player == 1: body.position = (action[0], 145) if player == 2: body.position = (action[0], BOARD_SIZE - 136) body.apply_force_at_world_point((cos(action[1]) * action[2], sin( action[1]) * action[2]), body.position + (STRIKER_RADIUS * 0, STRIKER_RADIUS * 0)) shape = pymunk.Circle(body, STRIKER_RADIUS, (0, 0)) shape.elasticity = STRIKER_ELASTICITY shape.color = STRIKER_COLOR mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories sf = pymunk.ShapeFilter(mask=mask) shape.filter = sf shape.collision_type = 2 space.add(body, shape) return [body, shape] # Adds coins to the board at the given coordinates
Example #5
Source File: Utils.py From Carrom_rl with GNU General Public License v3.0 | 6 votes |
def init_pockets(space): pockets = [] for i in [(44.1, 44.1), (755.9, 44.1), (755.9, 755.9), (44.1, 755.9)]: inertia = pymunk.moment_for_circle(0.1, 0, POCKET_RADIUS, (0, 0)) body = pymunk.Body(0.1, inertia) body.position = i shape = pymunk.Circle(body, POCKET_RADIUS, (0, 0)) shape.color = POCKET_COLOR shape.collision_type = 2 shape.filter = pymunk.ShapeFilter(categories=0b1000) space.add(body, shape) pockets.append(shape) del body del shape return pockets # Initialize striker with force
Example #6
Source File: Utils.py From Carrom_rl with GNU General Public License v3.0 | 6 votes |
def init_striker(space, x, passthrough, action, player): inertia = pymunk.moment_for_circle(STRIKER_MASS, 0, STRIKER_RADIUS, (0, 0)) body = pymunk.Body(STRIKER_MASS, inertia) if player == 1: body.position = (action[0], 140) if player == 2: body.position = (action[0], BOARD_SIZE - 140) body.apply_force_at_world_point((cos(action[1]) * action[2], sin( action[1]) * action[2]), body.position + (STRIKER_RADIUS * 0, STRIKER_RADIUS * 0)) shape = pymunk.Circle(body, STRIKER_RADIUS, (0, 0)) shape.elasticity = STRIKER_ELASTICITY shape.color = STRIKER_COLOR mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories sf = pymunk.ShapeFilter(mask=mask) shape.filter = sf shape.collision_type = 2 space.add(body, shape) return [body, shape] # Adds coins to the board at the given coordinates
Example #7
Source File: carmunk.py From Practical-Reinforcement-Learning with MIT License | 5 votes |
def create_obstacle(self, x, y, r): c_body = pymunk.Body(pymunk.inf, pymunk.inf) c_shape = pymunk.Circle(c_body, r) c_shape.elasticity = 1.0 c_body.position = x, y c_shape.color = THECOLORS["blue"] self.space.add(c_body, c_shape) return c_body
Example #8
Source File: carmunk.py From Self-Driving-Car-Demo with MIT License | 5 votes |
def create_obstacle(self, x, y, r): c_body = pymunk.Body(pymunk.inf, pymunk.inf) c_shape = pymunk.Circle(c_body, r) c_shape.elasticity = 1.0 c_body.position = x, y c_shape.color = THECOLORS["blue"] self.space.add(c_body, c_shape) return c_body
Example #9
Source File: carmunk.py From Practical-Reinforcement-Learning with MIT License | 5 votes |
def create_cat(self): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.cat_body = pymunk.Body(1, inertia) self.cat_body.position = 50, height - 100 self.cat_shape = pymunk.Circle(self.cat_body, 30) self.cat_shape.color = THECOLORS["orange"] self.cat_shape.elasticity = 1.0 self.cat_shape.angle = 0.5 direction = Vec2d(1, 0).rotated(self.cat_body.angle) self.space.add(self.cat_body, self.cat_shape)
Example #10
Source File: carmunk.py From Practical-Reinforcement-Learning with MIT License | 5 votes |
def create_car(self, x, y, r): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.car_body = pymunk.Body(1, inertia) self.car_body.position = x, y self.car_shape = pymunk.Circle(self.car_body, 25) self.car_shape.color = THECOLORS["green"] self.car_shape.elasticity = 1.0 self.car_body.angle = r driving_direction = Vec2d(1, 0).rotated(self.car_body.angle) self.car_body.apply_impulse(driving_direction) self.space.add(self.car_body, self.car_shape)
Example #11
Source File: Utils.py From Carrom_rl with GNU General Public License v3.0 | 5 votes |
def init_walls(space): # Initializes the four outer walls of the board body = pymunk.Body(body_type=pymunk.Body.STATIC) walls = [pymunk.Segment(body, (0, 0), (0, BOARD_SIZE), BOARD_WALLS_SIZE), pymunk.Segment(body, (0, 0), (BOARD_SIZE, 0), BOARD_WALLS_SIZE), pymunk.Segment( body, (BOARD_SIZE, BOARD_SIZE), (BOARD_SIZE, 0), BOARD_WALLS_SIZE), pymunk.Segment( body, (BOARD_SIZE, BOARD_SIZE), (0, BOARD_SIZE), BOARD_WALLS_SIZE) ] for wall in walls: wall.color = BOARD_WALLS_COLOR wall.elasticity = WALLS_ELASTICITY space.add(walls) # Initialize pockets
Example #12
Source File: Utils.py From Carrom_rl with GNU General Public License v3.0 | 5 votes |
def init_walls(space): # Initializes the four outer walls of the board body = pymunk.Body(body_type=pymunk.Body.STATIC) walls = [pymunk.Segment(body, (0, 0), (0, BOARD_SIZE), BOARD_WALLS_SIZE), pymunk.Segment(body, (0, 0), (BOARD_SIZE, 0), BOARD_WALLS_SIZE), pymunk.Segment( body, (BOARD_SIZE, BOARD_SIZE), (BOARD_SIZE, 0), BOARD_WALLS_SIZE), pymunk.Segment( body, (BOARD_SIZE, BOARD_SIZE), (0, BOARD_SIZE), BOARD_WALLS_SIZE) ] for wall in walls: wall.color = BOARD_WALLS_COLOR wall.elasticity = WALLS_ELASTICITY space.add(walls) # Initialize pockets
Example #13
Source File: Utils.py From Carrom_rl with GNU General Public License v3.0 | 5 votes |
def init_walls(space): # Initializes the four outer walls of the board body = pymunk.Body(body_type=pymunk.Body.STATIC) walls = [pymunk.Segment(body, (0, 0), (0, BOARD_SIZE), BOARD_WALLS_SIZE), pymunk.Segment(body, (0, 0), (BOARD_SIZE, 0), BOARD_WALLS_SIZE), pymunk.Segment( body, (BOARD_SIZE, BOARD_SIZE), (BOARD_SIZE, 0), BOARD_WALLS_SIZE), pymunk.Segment( body, (BOARD_SIZE, BOARD_SIZE), (0, BOARD_SIZE), BOARD_WALLS_SIZE) ] for wall in walls: wall.color = BOARD_WALLS_COLOR wall.elasticity = WALLS_ELASTICITY space.add(walls) # Initialize pockets
Example #14
Source File: Utils.py From Carrom_rl with GNU General Public License v3.0 | 5 votes |
def init_striker(space, passthrough, action, player): inertia = pymunk.moment_for_circle(STRIKER_MASS, 0, STRIKER_RADIUS, (0, 0)) body = pymunk.Body(STRIKER_MASS, inertia) if player == 1: body.position = (action[0], 140) if player == 2: body.position = (action[0], BOARD_SIZE - 140) # print " Final Position: ", body.position # body.position=(100,) body.apply_force_at_world_point((cos(action[1]) * action[2], sin( action[1]) * action[2]), body.position + (STRIKER_RADIUS * 0, STRIKER_RADIUS * 0)) shape = pymunk.Circle(body, STRIKER_RADIUS, (0, 0)) shape.elasticity = STRIKER_ELASTICITY shape.color = STRIKER_COLOR mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories sf = pymunk.ShapeFilter(mask=mask) shape.filter = sf shape.collision_type = 2 space.add(body, shape) return [body, shape] # Adds coins to the board at the given coordinates
Example #15
Source File: carmunk.py From reinforcement-learning-car with MIT License | 5 votes |
def create_obstacle(self, x, y, r): c_body = pymunk.Body(pymunk.inf, pymunk.inf) c_shape = pymunk.Circle(c_body, r) c_shape.elasticity = 1.0 c_body.position = x, y c_shape.color = THECOLORS["blue"] self.space.add(c_body, c_shape) return c_body
Example #16
Source File: carmunk.py From reinforcement-learning-car with MIT License | 5 votes |
def create_cat(self): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.cat_body = pymunk.Body(1, inertia) self.cat_body.position = 50, height - 100 self.cat_shape = pymunk.Circle(self.cat_body, 30) self.cat_shape.color = THECOLORS["orange"] self.cat_shape.elasticity = 1.0 self.cat_shape.angle = 0.5 direction = Vec2d(1, 0).rotated(self.cat_body.angle) self.space.add(self.cat_body, self.cat_shape)
Example #17
Source File: carmunk.py From reinforcement-learning-car with MIT License | 5 votes |
def create_car(self, x, y, r): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.car_body = pymunk.Body(1, inertia) self.car_body.position = x, y self.car_shape = pymunk.Circle(self.car_body, 25) self.car_shape.color = THECOLORS["green"] self.car_shape.elasticity = 1.0 self.car_body.angle = r driving_direction = Vec2d(1, 0).rotated(self.car_body.angle) self.car_body.apply_impulse(driving_direction) self.space.add(self.car_body, self.car_shape)
Example #18
Source File: carmunk.py From toyCarIRL with MIT License | 5 votes |
def create_car(self, x, y, r): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.car_body = pymunk.Body(1, inertia) self.car_body.position = x, y self.car_shape = pymunk.Circle(self.car_body, r) self.car_shape.color = THECOLORS["green"] self.car_shape.elasticity = 1.0 self.car_body.angle = 1.4 driving_direction = Vec2d(1, 0).rotated(self.car_body.angle) self.car_body.apply_impulse(driving_direction) self.space.add(self.car_body, self.car_shape)
Example #19
Source File: carmunk.py From toyCarIRL with MIT License | 5 votes |
def create_cat(self): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.cat_body = pymunk.Body(1, inertia) self.cat_body.position = 50, height - 100 self.cat_shape = pymunk.Circle(self.cat_body, 30) self.cat_shape.color = THECOLORS["orange"] self.cat_shape.elasticity = 1.0 self.cat_shape.angle = 0.5 direction = Vec2d(1, 0).rotated(self.cat_body.angle) self.space.add(self.cat_body, self.cat_shape)
Example #20
Source File: carmunk.py From toyCarIRL with MIT License | 5 votes |
def create_obstacle(self, xy1, xy2, r, color): c_body = pymunk.Body(pymunk.inf, pymunk.inf) #c_shape = pymunk.Circle(c_body, r) c_shape = pymunk.Segment(c_body, xy1, xy2, r) #c_shape.elasticity = 1.0 #c_body.position = x, y c_shape.friction = 1. c_shape.group = 1 c_shape.collision_type = 1 c_shape.color = THECOLORS[color] self.space.add(c_body, c_shape) return c_body
Example #21
Source File: world.py From virtuaplant with MIT License | 5 votes |
def draw_lines(screen, lines, color=THECOLORS['dodgerblue4']): """Draw the lines""" for line in lines: body = line.body pv1 = body.position + line.a.rotated(body.angle) pv2 = body.position + line.b.rotated(body.angle) p1 = to_pygame(pv1) p2 = to_pygame(pv2) pygame.draw.lines(screen, color, False, [p1,p2]) # Collision handlers
Example #22
Source File: world.py From virtuaplant with MIT License | 5 votes |
def draw_ball(screen, ball, color=THECOLORS['blue']): p = int(ball.body.position.x), 600-int(ball.body.position.y) pygame.draw.circle(screen, color, p, int(ball.radius), 2)
Example #23
Source File: carmunk.py From rl-rc-car with MIT License | 5 votes |
def create_car(self, x, y, r): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.car_body = pymunk.Body(1, inertia) self.car_body.position = x, y self.car_shape = pymunk.Circle(self.car_body, 15) self.car_shape.color = THECOLORS["green"] self.car_shape.elasticity = 1.0 self.car_body.angle = r self.driving_direction = Vec2d(1, 0).rotated(self.car_body.angle) self.car_body.apply_impulse(self.driving_direction) self.space.add(self.car_body, self.car_shape)
Example #24
Source File: carmunk.py From rl-rc-car with MIT License | 5 votes |
def create_cat(self): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.cat_body = pymunk.Body(1, inertia) self.cat_body.position = 800, 200 self.cat_shape = pymunk.Circle(self.cat_body, 30) self.cat_shape.color = THECOLORS["orange"] self.car_shape.elasticity = 1.0 self.cat_shape.angle = 0.5 self.space.add(self.cat_body, self.cat_shape)
Example #25
Source File: carmunk.py From Self-Driving-Car-Demo with MIT License | 5 votes |
def create_cat(self): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.cat_body = pymunk.Body(1, inertia) self.cat_body.position = 50, height - 100 self.cat_shape = pymunk.Circle(self.cat_body, 30) self.cat_shape.color = THECOLORS["orange"] self.cat_shape.elasticity = 1.0 self.cat_shape.angle = 0.5 direction = Vec2d(1, 0).rotated(self.cat_body.angle) self.space.add(self.cat_body, self.cat_shape)
Example #26
Source File: carmunk.py From rl-rc-car with MIT License | 5 votes |
def create_obstacle(self, x, y, r): c_body = pymunk.Body(pymunk.inf, pymunk.inf) c_shape = pymunk.Circle(c_body, r) c_shape.elasticity = 1.0 c_body.position = x, y c_shape.color = THECOLORS["blue"] self.space.add(c_body, c_shape) return c_body
Example #27
Source File: carmunk.py From Self-Driving-Car-Demo with MIT License | 5 votes |
def create_car(self, x, y, r): inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0)) self.car_body = pymunk.Body(1, inertia) self.car_body.position = x, y self.car_shape = pymunk.Circle(self.car_body, 25) self.car_shape.color = THECOLORS["green"] self.car_shape.elasticity = 1.0 self.car_body.angle = r driving_direction = Vec2d(1, 0).rotated(self.car_body.angle) self.car_body.apply_impulse(driving_direction) self.space.add(self.car_body, self.car_shape)
Example #28
Source File: pong.py From kvae with MIT License | 5 votes |
def create_ball(self, radius=3): inertia = pymunk.moment_for_circle(1, 0, radius, (0, 0)) body = pymunk.Body(1, inertia) position = np.array(self.initial_position) + self.initial_std * np.random.normal(size=(2,)) position = np.clip(position, self.dd + radius + 1, self.res[0] - self.dd - radius - 1) body.position = position shape = pymunk.Circle(body, radius, (0, 0)) shape.elasticity = .9 shape.color = color["white"] return shape
Example #29
Source File: pong.py From kvae with MIT License | 5 votes |
def __init__(self, pong, position): self.pong = pong self.area = pong.res if position == 'left': self.rect = pymunk.Segment(pong.space.static_body, (0, self.area[1] / 2 + 3*scale), (0, self.area[1] / 2 - 3*scale), 1.0) else: self.rect = pymunk.Segment(pong.space.static_body, (self.area[0] - 2, self.area[1] / 2 + 3*scale), (self.area[0] - 2, self.area[1] / 2 - 3*scale), 1.0) self.speed = 2*scale self.rect.elasticity = .99 self.rect.color = color["white"] self.rect.collision_type = 1
Example #30
Source File: pong.py From kvae with MIT License | 5 votes |
def _clear(self): self.screen.fill(color["black"])