This commit is contained in:
Lukas Schulz 2020-12-20 01:48:33 +01:00
parent 9f07752e78
commit c5611f889f

27
main.py
View file

@ -34,9 +34,6 @@ artist_name=""
is_playing = False is_playing = False
currently_scrolling_artist = False
currently_scrolling_title = False
token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)
font = ImageFont.load_default() font = ImageFont.load_default()
@ -100,39 +97,39 @@ def drawCanvas():
songinfo.text((songinfo_offset_x,songinfo_offset_y), artist_name) songinfo.text((songinfo_offset_x,songinfo_offset_y), artist_name)
#scrolling_text(song_name,songinfo_offset_x, songinfo_offset_y+10) #scrolling_text(song_name,songinfo_offset_x, songinfo_offset_y+10)
global currently_scrolling_title if(font.getsize(song_name)[0]>160):
if(font.getsize(song_name)[0]>160 and not currently_scrolling_title): x = threading.Thread(target=scrolling_text,args=(song_name,songinfo_offset_x,songinfo_offset_y+10))
x = threading.Thread(target=scrolling_text,args=(song_name,currently_scrolling_title,songinfo_offset_x,songinfo_offset_y+10))
x.start() x.start()
print('scrolling text started') print('scrolling text started')
global currently_scrolling_artist if(font.getsize(artist_name)[0]>160):
if(font.getsize(artist_name)[0]>160 and not currently_scrolling_artist):
y = threading.Thread(target=scrolling_text,args=(artist_name,currently_scrolling_artist,songinfo_offset_x,songinfo_offset_y)) y = threading.Thread(target=scrolling_text,args=(artist_name,songinfo_offset_x,songinfo_offset_y))
y.start() y.start()
showImage(canvas) showImage(canvas)
def scrolling_text(text,scrolling_Boolean,offset_x=0,offset_y=0): def scrolling_text(text,offset_x=0,offset_y=0):
scrolling_Boolean = True scroll_frame_time = (font.getsize(text)[0]-160)/(10/2)
if(scroll_frame_time<0.1):
scroll_frame_time = 0.1
for i in range(font.getsize(text)[0]-160): for i in range(font.getsize(text)[0]-160):
scrolled_text_canvas = Image.new('RGB', (160, 11), color = 'black') scrolled_text_canvas = Image.new('RGB', (160, 11), color = 'black')
scrolled_text = ImageDraw.Draw(scrolled_text_canvas) scrolled_text = ImageDraw.Draw(scrolled_text_canvas)
scrolled_text.text((-i,0), text) scrolled_text.text((-i,0), text)
showImage(scrolled_text_canvas, offset_x, offset_y) showImage(scrolled_text_canvas, offset_x, offset_y)
time.sleep(0.1) time.sleep(scroll_frame_time)
#print('scrolled '+str(i)+' px') #print('scrolled '+str(i)+' px')
if((5-(font.getsize(text)[0]-160)*0.2)>0): if((5-(font.getsize(text)[0]-160)*0.2)>0):
time.sleep(5-(font.getsize(text)[0]-160)*0.2) time.sleep(5-(font.getsize(text)[0]-160)*2*scroll_frame_time)
for i in range(font.getsize(text)[0]-160): for i in range(font.getsize(text)[0]-160):
scrolled_text_canvas = Image.new('RGB', (160, 11), color = 'black') scrolled_text_canvas = Image.new('RGB', (160, 11), color = 'black')
scrolled_text = ImageDraw.Draw(scrolled_text_canvas) scrolled_text = ImageDraw.Draw(scrolled_text_canvas)
scrolled_text.text(((-(font.getsize(text)[0]-160))+i+1,0), text) scrolled_text.text(((-(font.getsize(text)[0]-160))+i+1,0), text)
showImage(scrolled_text_canvas, offset_x, offset_y) showImage(scrolled_text_canvas, offset_x, offset_y)
time.sleep(0.1) time.sleep(scroll_frame_time)
#print('scrolled '+str(i)+' px') #print('scrolled '+str(i)+' px')
scrolling_Boolean = False