Browse Source

center images

Thomas Buck 11 months 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,7 +25,7 @@ if __name__ == "__main__":
25 25
     t.loop_end()
26 26
 
27 27
     success = Manager(t)
28
-    success.add(ScrollText(t, "TODO"))
28
+    success.add(ImageScreen(t, "drinka.gif", 0.2, 3, 20.0))
29 29
     success.add(Solid(t, 1.0))
30 30
 
31 31
     fail = Manager(t)

+ 6
- 3
image.py View File

@@ -24,6 +24,9 @@ class ImageScreen:
24 24
         self.image = Image.open(self.path)
25 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 30
         self.restart()
28 31
 
29 32
     def restart(self):
@@ -63,9 +66,9 @@ class ImageScreen:
63 66
                                 c = self.background
64 67
                     if c == None:
65 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 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 73
 if __name__ == "__main__":
71 74
     import util
@@ -78,7 +81,7 @@ if __name__ == "__main__":
78 81
     imageDir = os.path.join(scriptDir, "images")
79 82
     for f in os.listdir(os.fsencode(imageDir)):
80 83
         filename = os.fsdecode(f)
81
-        m.add(ImageScreen(t, os.path.join(imageDir, filename)))
84
+        m.add(ImageScreen(t, filename))
82 85
 
83 86
     m.restart()
84 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