source: nagslang/utils.py@ 343:e5f525c87eb9

Last change on this file since 343:e5f525c87eb9 was 343:e5f525c87eb9, checked in by Neil Muller <drnlmuller@…>, 8 years ago

Robustness fix

File size: 598 bytes
Line 
1import pygame
2from pymunk.vec2d import Vec2d
3
4
5def convert_colour(colour):
6 if isinstance(colour, pygame.Color):
7 return colour
8 if isinstance(colour, tuple):
9 return pygame.Color(*colour)
10 if isinstance(colour, basestring):
11 return pygame.Color(colour)
12 raise ValueError()
13
14
15def vec_from_angle(angle, length=1):
16 vec = Vec2d(length, 0)
17 vec.angle = angle
18 return vec
19
20
21def vec_with_length(coords, length=1):
22 vec = Vec2d(coords)
23 # Don't crash if we're created a zero length vector
24 if vec.length != 0:
25 vec.length = length
26 return vec
Note: See TracBrowser for help on using the repository browser.