Advertisement
Guest User

gradientRect

a guest
Dec 29th, 2021
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. def gradientRect(window, left_colour, right_colour, target_rect):
  2.     """ Draw a horizontal-gradient filled rectangle covering <target_rect> """
  3.     colour_rect = pg.Surface((2, 2))  # tiny! 2x2 bitmap
  4.     pg.draw.line(colour_rect, left_colour, (0, 0), (0, 1))  # left colour line
  5.     pg.draw.line(colour_rect, right_colour, (1, 0), (1, 1))  # right colour line
  6.     colour_rect = pg.transform.smoothscale(colour_rect, (target_rect.width, target_rect.height))  # stretch!
  7.     window.blit(colour_rect, target_rect)  # paint it
  8.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement