|
1 |
| -#!/usr/bin/env python2.7 |
| 1 | +#!/usr/bin/env python2 |
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 |
|
4 | 4 | """
|
|
7 | 7 |
|
8 | 8 | This little program emulates the awesome Mate Light, just in case you're not on c-base space station but want to send
|
9 | 9 | something to it.
|
| 10 | +
|
| 11 | +Usage: |
| 12 | + emulator.py [-w=<px>] [-h=<px>] [--host=<ip>] [--port=<num>] [--dot=<size>] |
| 13 | + emulator.py --help |
| 14 | + emulator.py --version |
| 15 | +
|
| 16 | +Options: |
| 17 | + --help Show this screen. |
| 18 | + --version Show version. |
| 19 | + -w=<px> Width in pixels [default: 40]. |
| 20 | + -h=<px> Height in pixels [default: 16]. |
| 21 | + --host=<host> Bind to IP address [default: 127.0.0.1]. |
| 22 | + --port=<port> Bind to Port [default: 1337]. |
| 23 | + --dot=<px> Size of dots in pixels [default: 10]. |
10 | 24 | """
|
11 | 25 |
|
12 | 26 | __author__ = 'Ricardo Band'
|
13 | 27 | __copyright__ = 'Copyright 2014, Ricardo Band'
|
14 | 28 | __credits__ = ['Ricardo Band']
|
15 | 29 | __license__ = 'MIT'
|
16 |
| -__version__ = '0.2.0' |
| 30 | +__version__ = '0.3.0' |
17 | 31 | __maintainer__ = 'Ricardo Band'
|
18 | 32 |
|
19 | 33 | __status__ = 'Development'
|
|
22 | 36 | import socket
|
23 | 37 |
|
24 | 38 | import pygame
|
| 39 | +from docopt import docopt |
25 | 40 |
|
26 | 41 |
|
27 | 42 | class Emu(object):
|
28 | 43 | """
|
29 | 44 | The Emulator is a simple pygame game.
|
30 | 45 | """
|
31 |
| - def __init__(self, width=40, height=16, ip='127.0.0.1', port=1337): |
| 46 | + def __init__(self, width=40, height=16, ip='127.0.0.1', port=1337, dotsize=10): |
32 | 47 | """
|
33 | 48 | Creates a screen with the given size, generates the matrix for the Mate bottles and binds the socket for
|
34 | 49 | incoming frames.
|
35 | 50 | """
|
36 | 51 | self.width = width
|
37 | 52 | self.height = height
|
| 53 | + self.dotsize = dotsize |
38 | 54 | pygame.init()
|
39 |
| - # one mate bottle is 10x10px |
40 |
| - self.screen = pygame.display.set_mode([self.width * 10, self.height * 10]) |
| 55 | + self.screen = pygame.display.set_mode([self.width * self.dotsize, self.height * self.dotsize]) |
41 | 56 | pygame.display.set_caption("Mate Light Emu")
|
42 | 57 | self.clock = pygame.time.Clock()
|
43 | 58 | self.matrix = []
|
@@ -71,7 +86,7 @@ def update(self):
|
71 | 86 | if pixel < pixels:
|
72 | 87 | pygame.draw.circle(self.screen,
|
73 | 88 | (self.matrix[pixel], self.matrix[pixel + 1], self.matrix[pixel + 2]),
|
74 |
| - (x * 10 + 5, y * 10 + 5), 5, 0) |
| 89 | + (x * self.dotsize + self.dotsize / 2, y * self.dotsize + self.dotsize / 2), self.dotsize / 2, 0) |
75 | 90 |
|
76 | 91 | def render(self):
|
77 | 92 | """
|
@@ -101,5 +116,6 @@ def gameloop(self):
|
101 | 116 |
|
102 | 117 |
|
103 | 118 | if __name__ == '__main__':
|
104 |
| - EMU = Emu(40, 16, '127.0.0.1', 1337) |
| 119 | + ARGS = docopt(__doc__, version=__version__) |
| 120 | + EMU = Emu(int(ARGS['-w']), int(ARGS['-h']), ARGS['--host'], int(ARGS['--port']), int(ARGS['--dot'])) |
105 | 121 | EMU.gameloop()
|
0 commit comments