@@ -15,10 +15,11 @@ def __init__(self, day, part):
15
15
16
16
17
17
def paint (self ):
18
- self .canvas = {}
18
+ self .canvas = np .zeros ((43 ,23 ,12000 ))
19
+ self .scores = np .zeros ((12000 ))
19
20
self .ball_x = 0
20
21
self .paddle_x = 0
21
-
22
+ inc = 0
22
23
while True :
23
24
x = self .execute_opcode (reset_pointer = False )
24
25
y = self .execute_opcode (reset_pointer = False )
@@ -27,26 +28,38 @@ def paint(self):
27
28
if z == 4 :
28
29
self .ball_x = x
29
30
self .input (- 1 if self .ball_x < self .paddle_x else 1 if self .ball_x > self .paddle_x else 0 )
31
+ self .canvas [x , y , inc ] = z
32
+ inc += 1
30
33
if z == 3 :
31
34
self .paddle_x = x
35
+ inc += 1
36
+
32
37
33
38
if isinstance (z , Day ):
39
+ print (inc )
34
40
break
35
41
if x == - 1 and y == 0 :
36
42
#print("Score: ", z)
37
43
self .score = z
38
- self .visualize ()
44
+ self .scores [inc :] = z
45
+ #self.visualize()
39
46
else :
40
- self .canvas [(x , y )] = z
41
- if len (self .canvas .keys ()) > 910 :
42
- self .visualize ()
47
+ if z in [1 ,2 ]:
48
+ self .canvas [x , y , :] = z
49
+ elif z == 0 :
50
+ self .canvas [x , y , inc :] = z
51
+ elif z == 3 :
52
+ self .canvas [x , y , inc ] = z
53
+
54
+ #self.visualize()
55
+
43
56
return self
44
57
def visualize (self ):
45
58
46
59
print ("Score: " , self .score )
47
60
#x, y = zip(*self.canvas.keys())
48
- # painting = {0: " ", 1: "░", 2: "▒", 3: "▉", 4: "◓"}
49
- #for j in range(min(y)-2, max(y)+1):
61
+ painting = {0 : " " , 1 : "░" , 2 : "▒" , 3 : "▉" , 4 : "◓" }
62
+ # for j in range(min(y)-2, max(y)+1):
50
63
# for i in range(min(x), max(x)+1):
51
64
# for j in range(0, 25):
52
65
# for i in range(0, 45):
@@ -87,27 +100,17 @@ def visualize(self):
87
100
# 3 is a horizontal paddle tile. The paddle is indestructible.
88
101
# 4 is a ball tile. The ball moves diagonally and bounces off objects.
89
102
90
- fig = plt .figure ()
103
+ fig = plt .figure (figsize = ( 9 , 5 ) )
91
104
92
105
93
- def f (x , y ):
94
- return np .sin (x ) + np .cos (y )
95
-
96
- x = np .linspace (0 , 2 * np .pi , 120 )
97
- y = np .linspace (0 , 2 * np .pi , 100 ).reshape (- 1 , 1 )
98
- # ims is a list of lists, each row is a list of artists to draw in the
99
- # current frame; here we are just animating one artist, the image, in
100
- # each frame
101
106
ims = []
102
- for i in range (60 ):
103
- x += np .pi / 15.
104
- y += np .pi / 20.
105
- im = plt .imshow (f (x , y ), animated = True )
107
+ for i in range (0 ,7000 ,10 ):
108
+ im = plt .imshow (np .rot90 (part2 .canvas [:,:,i ], k = - 1 ), animated = True , cmap = plt .cm .get_cmap ('Greens' , 6 ))
106
109
ims .append ([im ])
107
-
108
- ani = animation .ArtistAnimation (fig , ims , interval = 50 , blit = True ,
110
+ plt . axis ( 'off' )
111
+ ani = animation .ArtistAnimation (fig , ims , interval = 50 , blit = False ,
109
112
repeat_delay = 1000 )
110
113
111
- # ani.save('dynamic_images.mp4')
114
+ ani .save ('dynamic_images.mp4' )
112
115
113
116
plt .show ()
0 commit comments