Fixed too big images.

This commit is contained in:
The Wobbler 2023-07-19 17:24:45 +02:00
parent 0c39f7abbc
commit a8e25e4add

View file

@ -41,10 +41,16 @@ class Wobbler:
self.image_original = random.choice(images) self.image_original = random.choice(images)
self.max_width, self.max_height = self.image_original.get_size() self.divider = 1
self.width = self.max_width * self.size / 100 self.max_width, self.max_height = self.image_original.get_size()
self.height = self.max_height * self.size / 100 while self.max_width > max_wobbler_size * 2 or self.max_height > max_wobbler_size * 2:
self.divider += 0.01
self.max_width = self.image_original.get_width() / self.divider
self.max_height = self.image_original.get_height() / self.divider
self.width = self.max_width * self.size / 100 / self.divider
self.height = self.max_height * self.size / 100 / self.divider
self.image = self.image_original self.image = self.image_original
self.image = pygame.transform.scale(self.image, (self.width, self.height)) self.image = pygame.transform.scale(self.image, (self.width, self.height))
@ -56,8 +62,8 @@ class Wobbler:
screen.blit(self.image, self.image_rect) screen.blit(self.image, self.image_rect)
def update(self): def update(self):
self.width = self.max_width * self.size / 100 self.width = self.max_width * self.size / 100 / self.divider
self.height = self.max_height * self.size / 100 self.height = self.max_height * self.size / 100 / self.divider
self.image = self.image_original self.image = self.image_original
self.image = pygame.transform.scale(self.image, (self.width, self.height)) self.image = pygame.transform.scale(self.image, (self.width, self.height))