forked from fanfani/Night-Of-The-Living-Plotters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space_invaders.py
executable file
·115 lines (91 loc) · 9.94 KB
/
space_invaders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
"""
a software piece written in a quick-n-dirty style for
" A L I E N V I C T O R Y B O O G I E - W O O G I E "
artwork exhibited at "Insert Coin - Retrogaming 2011"
National Gallery of Cosenza, Dec 3 2011 to Jan 8 2012
(info at http://insertcoin.verdebinario.org)
REQUIRES PYTHON, PYSERIAL, NUMPY, HP2XX AND CHIPLOTLE
install everything on debian squeeze in two handy steps:
1) apt-get install python python-serial python-numpy python-setuptools hp2xx
2) easy_install -U chiplotle && mkdir ~/.chiplotle
chiplotle documentation: http://music.columbia.edu/cmc/chiplotle/manual/
:copyright:
VP-6803P (astio@ciotoni.net)
:license:
GNU Lesser General Public License, Version 3
(http://www.gnu.org/copyleft/lesser.html)
"""
from chiplotle import *
from chiplotle.tools.plottertools import instantiate_virtual_plotter
import random
# select the first plotter configured in chiplotle
#~ plotter = instantiate_plotters()[0]
# hint: change to a virtual plotter for testing and debug
plotter = instantiate_virtual_plotter(type="HP7550A")
# scale
plotter.write(hpgl.SC([(-148,148),(-210,210)]))
# pick up the first pen
plotter.select_pen(1)
# draw two rectangle frames around the invader area
plotter.write(shapes.rectangle(420, 296))
plotter.write(shapes.rectangle(210, 210))
# select a random "zero" point for the invader
x = random.randint(-50, 50)
y = random.randint(-30, 30)
# and a random square size
l = random.randint(8, 10)
# here come the invaders
invader = []
invader_1 = [ [-35, 30], [25, 30], [-25, 20], [15, 20], [-35, 10], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [25, 10], [-35, 0], [-15, 0], [-5, 0], [5, 0], [25, 0], [-45, -10], [-35, -10], [-15, -10], [-5, -10], [5, -10], [25, -10], [35, -10], [-55, -20], [-45, -20], [-35, -20], [-25, -20], [-15, -20], [-5, -20], [5, -20], [15, -20], [25, -20], [35, -20], [45, -20], [-55, -30], [-35, -30], [-25, -30], [-15, -30], [-5, -30], [5, -30], [15, -30], [25, -30], [45, -30], [-55, -40], [-35, -40], [25, -40], [45, -40], [-25, -50], [15, -50], [-15, -60], [5, -60] ]
invader_2 = [ [-25, 20], [15, 20], [-15, 10], [-5, 10], [5, 10], [-45, 0], [-25, 0], [-15, 0], [-5, 0], [5, 0], [15, 0], [35, 0], [-45, -10], [-35, -10], [-5, -10], [25, -10], [35, -10], [-35, -20], [-25, -20], [-15, -20], [-5, -20], [5, -20], [15, -20], [25, -20], [-45, -30], [-25, -30], [15, -30], [35, -30], [-15, -40], [5, -40] ]
invader_3 = [ [-15, 20], [5, 20], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [-35, 0], [-25, 0], [-15, 0], [-5, 0], [5, 0], [15, 0], [25, 0], [-45, -10], [-35, -10], [-5, -10], [25, -10], [35, -10], [-25, -20], [-15, -20], [-5, -20], [5, -20], [15, -20], [-35, -30], [-15, -30], [5, -30], [25, -30], [-45, -40], [35, -40] ]
invader_4 = [ [-35, 40], [25, 40], [-25, 30], [15, 30], [-15, 20], [-5, 20], [5, 20], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [-25, 0], [-5, 0], [15, 0], [-35, -10], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [5, -20], [15, -20], [-35, -20], [-15, -20], [-45, -30], [-35, -30], [-15, -30], [5, -30], [25, -30], [35, -30] ]
invader_5 = [ [-15, 20], [5, 20], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [-35, 0], [-25, 0], [-5, 0], [15, 0], [25, 0], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [-25, -20], [5, -20], [-35, -30], [-5, -30] ]
invader_6 = [ [-25, 40], [25, 40], [-15, 30], [-5, 30], [5, 30], [15, 30], [-35, 20], [-25, 20], [-15, 20], [-5, 20], [5, 20], [15, 20], [25, 20], [35, 20], [-25, 10], [5, 10], [15, 10], [25, 10], [-45, 0], [-35, 0], [-25, 0], [-5, 0], [5, 0], [25, 0], [35, 0], [45, 0], [-45, -10], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [45, -10], [-45, -20], [-15, -20], [15, -20], [45, -20], [-55, -30], [-45, -30], [-5, -30], [5, -30], [45, -30], [55, -30] ]
invader_7 = [ [-15, 30], [25, 30], [-25, 20], [-15, 20], [-5, 20], [5, 20], [15, 20], [25, 20], [35, 20], [-35, 10], [-5, 10], [5, 10], [35, 10], [-35, 0], [-25, 0], [-15, 0], [-5, 0], [5, 0], [15, 0], [25, 0], [35, 0], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [-15, -20], [25, -20], [-25, -30], [-15, -30], [15, -30], [25, -30] ]
invader_8 = [ [-15, 30], [-5, 30], [5, 30], [15, 30], [-25, 20], [-15, 20], [-5, 20], [5, 20], [15, 20], [25, 20], [-35, 10], [-5, 10], [5, 10], [35, 10], [-35, 0], [-5, 0], [5, 0], [35, 0], [-45, -10], [-35, -10], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [35, -10], [45, -10], [-45, -20], [-25, -20], [25, -20], [45, -20], [-45, -30], [-15, -30], [15, -30], [45, -30], [-35, -40], [35, -40] ]
invader_9 = [ [-35, 30], [-25, 30], [15, 30], [25, 30], [-15, 20], [-5, 20], [5, 20], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [-35, 00], [-5, 0], [25, 0], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [-35, -20], [-15, -20], [5, -20], [25, -20], [-35, -30], [-15, -30], [5, -30], [25, -30] ]
invader_10 = [ [-5, 30], [5, 30], [-15, 20], [-5, 20], [5, 20], [15, 20], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [25, 10], [-35, 0], [-25, 0], [-5, 0], [5, 0], [25, 0], [35, 0], [-35, -10], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [35, -10], [-25, -20], [-5, -20], [5, -20], [25, -20], [-35, -30], [35, -30], [-25, -40], [25, -40] ]
invader_11 = [ [-5, 20], [5, 20], [-25, 10], [-5, 10], [5, 10], [25, 10], [-35, 0], [-25, 0], [-15, 0], [-5, 0], [5, 0], [15, 0], [25, 0], [35, 0], [-25, -10], [25, -10], [-25, -20], [15, -20], [-35, -30], [5, -30] ]
invader_12 = [ [-35, 30], [35, 30], [-35, 20], [-15, 20], [15, 20], [35, 20], [-25, 10], [-5, 10], [5, 10], [25, 10], [-5, 0], [5, 0], [-5, -10], [5, -10], [-15, -20], [15, -20], [-35, -30], [-25, -30], [25, -30], [35, -30] ]
invader_13 = [ [-15, 30], [-5, 30], [5, 30], [-25, 20], [-15, 20], [-5, 20], [5, 20], [15, 20], [-35, 10], [-5, 10], [25, 10], [-25, 0], [-15, 0], [-5, 0], [5, 0], [15, 0], [-15, -10], [-5, -10], [5, -10], [-25, -20], [15, -20], [-35, -30], [25, -30] ]
invader_14 = [ [-25, 30], [25, 30], [-35, 20], [-15, 20], [15, 20], [-5, 10], [5, 10], [-25, 0], [-15, 0], [-5, 0], [5, 0], [15, 0], [25, 0], [-35, -10], [-5, -10], [5, -10], [35, -10], [-35, -20], [-25, -20], [-15, -20], [-5, -20], [5, -20], [15, -20], [25, -20], [35, -20], [-35, -30], [-25, -30], [25, -30], [35, -30], [-45, -40], [-35, -40], [-25, -40], [-15, -40], [15, -40], [25, -40], [35, -40], [45, -40] ]
invader_15 = [ [-15, 30], [-5, 30], [5, 30], [15, 30], [-25, 20], [-15, 20], [-5, 20], [5, 20], [15, 20], [25, 20], [-35, 10], [-25, 10], [-15, 10], [-5, 10], [25, 10], [35, 10], [-35, 0], [-25, 0], [-15, 0], [-5, 0], [5, 0], [15, 0], [25, 0], [35, 0], [-25, -10], [-5, -10], [5, -10], [15, -10], [-25, -20], [15, -20],[-25, -30], [-15, -30], [15, -30], [25, -30] ]
invader_16 = [ [-5, 30], [-15, 20], [-5, 20], [5, 20], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [-35, 0], [-5, 0], [25, 0], [-45, -10], [-35, -10], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [35, -10], [-25, -20], [-15, -20], [-5, -20], [5, -20], [15, -20], [-35, -30], [25, -30], [-45, -40], [35, -40] ]
invader_17 = [ [-25, 40], [15, 40], [-15, 30], [5, 30], [-25, 20], [-15, 20], [-5, 20], [5, 20], [15, 20], [-35, 10], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [25, 10], [-45, 0], [-35, 0], [-5, 0], [25, 0], [35, 0], [-45, -10], [-35, -10], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [35, -10], [-35, -20], [-25, -20], [15, -20], [25, -20], [-45, -30], [-15, -30], [5, -30], [35, -30] ]
invader_18 = [ [-35, 30], [-25, 30], [-15, 30], [-5, 30], [5, 30], [15, 30], [25, 30], [-45, 20], [-15, 20], [-5, 20], [5, 20], [35, 20], [-45, 10], [-15, 10], [-5, 10], [5, 10], [35, 10], [-35, 0], [-25, 0], [-15, 0], [-5, 0], [5, 0], [15, 0], [25, 0], [-25, -10], [-5, -10], [15, -10], [-25, -20], [-5, -20], [15, -20] ]
invader_19 = [ [-20, 20], [20, 20], [-30, 10], [-20, 10], [-10, 10], [0, 10], [10, 10], [20, 10], [30, 10], [-40, 0], [-30, 0], [0, 0], [30, 0], [40, 0], [-30, -10], [-20, -10], [-10, -10], [0, -10], [10, -10], [20, -10], [30, -10], [-40, -20], [-20, -20], [20, -20], [40, -20], [-50, -30], [-10, -30], [10, -30], [50, -30] ]
invader_20 = [ [-15, 30], [-5, 30], [5, 30], [-25, 20], [-15, 20], [-5, 20], [5, 20], [15, 20], [-35, 10], [-5, 10], [25, 10], [-35, 0], [-5, 0], [25, 0], [-45, -10], [-35, -10], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [35, -10], [-35, -20], [-25, -20], [-15, -20], [-5, -20], [5, -20], [15, -20], [25, -20], [-25, -30], [-5, -30], [15, -30], [-35, -40], [25, -40] ]
invader_21 = [ [-25, 40], [25, 40], [-15, 30], [15, 30], [-25, 20], [-15, 20], [-5, 20], [5, 20], [15, 20], [25, 20], [-35, 10], [-25, 10], [-15, 10], [-5, 10], [5, 10], [15, 10], [25, 10], [35, 10], [-45, 0], [-35, 0], [-5, 0], [5, 0], [35, 0], [45, 0], [-45, -10], [-35, -10], [-25, -10], [-15, -10], [-5, -10], [5, -10], [15, -10], [25, -10], [35, -10], [45, -10], [-15, -20], [-5, -20], [5, -20], [15, -20], [-25, -30], [-15, -30], [15, -30], [25, -30], [-35, -40], [-25, -40], [25, -40], [35, -40] ]
# select a random invader
inv = random.randint(1, 21)
invader = eval('invader_%d' % inv )
# shuffle and slice the invader array
random.shuffle(invader)
penna = 1 ; num_d_penne = 6
slice = len(invader) / num_d_penne
plotter.select_pen(penna+1)
# draw the invader :)
for i in range(0, len(invader)):
# change pen at every iteration
if ((i+1) % slice) == 0 and penna < num_d_penne :
penna +=1
plotter.select_pen(penna)
# get inspiration from /dev/urandom
k = random.randint(1, 3) ;
s = random.randint(-1, 1) ; t = random.randint(-1, 1) ;
# write down the rectangle(s)
r = shapes.rectangle(l, l)
transforms.offset(r, (invader[i][0] +s*k/3 +x, invader[i][1] +t*k/3 +y))
plotter.write(r)
# it's an original piece of art by VP-6803P. No shit.
plotter.write(hpgl.PU([(120,-120)]))
plotter.write(hpgl.DT(terminator='*'))
plotter.write(hpgl.LB('VP-6803P*'))
# get ready for a new masterpiece.
plotter.select_pen(0)
plotter.write(hpgl.IN())
# next line of code is for software viewing. Use with virtual plotter
# HPGL and EPS output files are saved in ~/.chiplotle/output/
io.view(plotter)