From c5611f889f7b15d06355e90c4e2dcfd3cacb9b27 Mon Sep 17 00:00:00 2001 From: Lukas Schulz Date: Sun, 20 Dec 2020 01:48:33 +0100 Subject: [PATCH] yes. --- main.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index da47d9a..0f9cf8c 100644 --- a/main.py +++ b/main.py @@ -34,9 +34,6 @@ artist_name="" 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) font = ImageFont.load_default() @@ -100,39 +97,39 @@ def drawCanvas(): songinfo.text((songinfo_offset_x,songinfo_offset_y), artist_name) #scrolling_text(song_name,songinfo_offset_x, songinfo_offset_y+10) - global currently_scrolling_title - if(font.getsize(song_name)[0]>160 and not currently_scrolling_title): - x = threading.Thread(target=scrolling_text,args=(song_name,currently_scrolling_title,songinfo_offset_x,songinfo_offset_y+10)) + if(font.getsize(song_name)[0]>160): + x = threading.Thread(target=scrolling_text,args=(song_name,songinfo_offset_x,songinfo_offset_y+10)) x.start() print('scrolling text started') - global currently_scrolling_artist - if(font.getsize(artist_name)[0]>160 and not currently_scrolling_artist): + if(font.getsize(artist_name)[0]>160): - 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() showImage(canvas) -def scrolling_text(text,scrolling_Boolean,offset_x=0,offset_y=0): - scrolling_Boolean = True +def scrolling_text(text,offset_x=0,offset_y=0): + 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): scrolled_text_canvas = Image.new('RGB', (160, 11), color = 'black') scrolled_text = ImageDraw.Draw(scrolled_text_canvas) scrolled_text.text((-i,0), text) showImage(scrolled_text_canvas, offset_x, offset_y) - time.sleep(0.1) + time.sleep(scroll_frame_time) #print('scrolled '+str(i)+' px') 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): scrolled_text_canvas = Image.new('RGB', (160, 11), color = 'black') scrolled_text = ImageDraw.Draw(scrolled_text_canvas) scrolled_text.text(((-(font.getsize(text)[0]-160))+i+1,0), text) showImage(scrolled_text_canvas, offset_x, offset_y) - time.sleep(0.1) + time.sleep(scroll_frame_time) #print('scrolled '+str(i)+' px') - scrolling_Boolean = False