Browse Source

center images

Thomas Buck 1 year ago
parent
commit
4d1db0d4b8
5 changed files with 7 additions and 4 deletions
  1. 1
    1
      camp_small.py
  2. 6
    3
      image.py
  3. BIN
      images/cocktail.gif
  4. BIN
      images/drink.gif
  5. BIN
      images/drinka.gif

+ 1
- 1
camp_small.py View File

25
     t.loop_end()
25
     t.loop_end()
26
 
26
 
27
     success = Manager(t)
27
     success = Manager(t)
28
-    success.add(ScrollText(t, "TODO"))
28
+    success.add(ImageScreen(t, "drinka.gif", 0.2, 3, 20.0))
29
     success.add(Solid(t, 1.0))
29
     success.add(Solid(t, 1.0))
30
 
30
 
31
     fail = Manager(t)
31
     fail = Manager(t)

+ 6
- 3
image.py View File

24
         self.image = Image.open(self.path)
24
         self.image = Image.open(self.path)
25
         print(p, self.image.width, self.image.height, self.image.is_animated, self.image.n_frames)
25
         print(p, self.image.width, self.image.height, self.image.is_animated, self.image.n_frames)
26
 
26
 
27
+        self.xOff = int((self.gui.width - self.image.width) / 2)
28
+        self.yOff = int((self.gui.height - self.image.height) / 2)
29
+
27
         self.restart()
30
         self.restart()
28
 
31
 
29
     def restart(self):
32
     def restart(self):
63
                                 c = self.background
66
                                 c = self.background
64
                     if c == None:
67
                     if c == None:
65
                         c = (p[v * 3 + 0], p[v * 3 + 1], p[v * 3 + 2])
68
                         c = (p[v * 3 + 0], p[v * 3 + 1], p[v * 3 + 2])
66
-                    self.gui.set_pixel(x, y, c)
69
+                    self.gui.set_pixel(x + self.xOff, y + self.yOff, c)
67
                 else:
70
                 else:
68
-                    self.gui.set_pixel(x, y, v)
71
+                    self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
69
 
72
 
70
 if __name__ == "__main__":
73
 if __name__ == "__main__":
71
     import util
74
     import util
78
     imageDir = os.path.join(scriptDir, "images")
81
     imageDir = os.path.join(scriptDir, "images")
79
     for f in os.listdir(os.fsencode(imageDir)):
82
     for f in os.listdir(os.fsencode(imageDir)):
80
         filename = os.fsdecode(f)
83
         filename = os.fsdecode(f)
81
-        m.add(ImageScreen(t, os.path.join(imageDir, filename)))
84
+        m.add(ImageScreen(t, filename))
82
 
85
 
83
     m.restart()
86
     m.restart()
84
     t.debug_loop(m.draw)
87
     t.debug_loop(m.draw)

BIN
images/cocktail.gif View File


BIN
images/drink.gif View File


BIN
images/drinka.gif View File


Loading…
Cancel
Save