Skip to content

Instantly share code, notes, and snippets.

@samneggs
Created December 15, 2021 05:15
Show Gist options
  • Save samneggs/55e632a0bfb4d5cd5f0570501aaa1708 to your computer and use it in GitHub Desktop.
Save samneggs/55e632a0bfb4d5cd5f0570501aaa1708 to your computer and use it in GitHub Desktop.
Appends array with 32 colors between inputs color1 and color2
def fade(input_color1, input_color2):
color1=input_color1<<8 | input_color1>>8 # byte swap to normal RBG565
red1 =color1>>11& 0b11111 # extract red #13
green1=color1>>6 & 0b11111 # extract green
blue1 =color1 & 0b11111 # extract blue
color2=input_color2<<8 | input_color2>>8 # byte swap
red2 =color2>>11& 0b11111 # extract red
green2=color2>>6 & 0b11111 # extract green
blue2 =color2 & 0b11111 # extract blue
inc_red =(red2- red1)/31 # find increment step
inc_green=(green2-green1)/31
inc_blue =(blue2- blue1)/31
for i in range(0,32):
red3 =red1 +int(i*inc_red) # build colors by steps
green3=green1+int(i*inc_green)
blue3 =blue1 +int(i*inc_blue)
color3=red3<<11 | green3<<6 | blue3 # combine RGB
color_l2.append((color3 & 0x00FF)<<8 | (color3>>8)) # byte swap to LCD RGB565
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment