Commits

Anonymous committed 28aadf7

Lerp colours in potion.

Comments (0)

Files changed (2)

alchemymadness/main.py

     screen.fill((0,0,0))
     background = pygame.image.load(skelutil.data_dir("bg.png")).convert_alpha()
 
-    # Tetris area
-    pygame.draw.rect(background, (0,0,255),
-                     (10, 10, SCREEN_SIZE[0]*.4, SCREEN_SIZE[1]*.7), 1)
-
     screen.blit(background, (0,0))
     pygame.display.flip()
 

alchemymadness/potion.py

     chems = 0  # Chem count
     formula = (0,0,0)  # Target formula
     col = (0,0,0)  # Current formula
+    target_col = None
     max_chems = 0  # Target number of chems
     start_y = 470
     target_y = None
         """
         self.chems += 1
         n = ((self.chems-1) / float(self.chems))
-        self.col = (self.col[0] * n, self.col[1] * n, self.col[2] * n)
-        self.col = (self.col[0] + col[0]/float(self.chems),
-                    self.col[1] + col[1]/float(self.chems),
-                    self.col[2] + col[2]/float(self.chems))
+        self.target_col = (self.col[0] * n, self.col[1] * n, self.col[2] * n)
+        self.target_col = (self.target_col[0] + col[0]/float(self.chems),
+                           self.target_col[1] + col[1]/float(self.chems),
+                           self.target_col[2] + col[2]/float(self.chems))
+        self.diff_col = ((self.target_col[0] - self.col[0]),
+                         (self.target_col[1] - self.col[1]),
+                         (self.target_col[2] - self.col[2]))
 
         # Update position
         n = self.chems / float(self.max_chems)
         pass
 
     def update(self, time):
+        # Move rect smoothly
         if self.target_y is not None:
             self.rect.y -= 5*(time/1000.)
             if self.rect.y < self.target_y:
                 self.rect.y = self.target_y
                 self.target_y = None
+        # Lerp colours
+        if self.target_col is not None:
+            diff = (self.diff_col[0] * (time/500.),
+                    self.diff_col[1] * (time/500.),
+                    self.diff_col[2] * (time/500.))
+            col = [self.col[0] + diff[0], self.col[1] + diff[1],
+                   self.col[2] + diff[2]]
+            for i in range(3):
+                if diff[i] > 0:
+                    col[i] = min(col[i], self.target_col[i])
+                else:
+                    col[i] = max(col[i], self.target_col[i])
+
+            self.col = tuple(col)
+            if self.col == self.target_col:
+                self.target_col = None