Posts: 42 Threads: 13 Joined: Aug 2021 Got an idea but dont know where to start. I want a program that shows a dot moving from the circumference towards the circle center. The size, color, and speed of the dot can be changed when required. On reaching the center, the dot will start from the circumference, x cm from the last starting point. How can I get started on this? Thanks. Posts: 6,920 Threads: 22 Joined: Feb 2020 Is this a game? Does a user somehow control the dot, or is it a status display? If a game, how does the user control the dot? Posts: 379 Threads: 2 Joined: Jan 2021 Here is a very basic script using pygame: from pygame import display, QUIT, event, draw, time SCREEN = display.set_mode ((500, 500)) dot_x_position = 30 while True : for user_input_event in event.get () : if user_input_event.type == QUIT : exit () SCREEN.fill ((0, 0, 0)) draw.circle (SCREEN, (200, 0, 0), (249, 249), 220, 4) draw.circle (SCREEN, (0, 0, 200), (dot_x_position, 249), 20) if dot_x_position < 249 : dot_x_position += 1 time.Clock ().tick (100) display.update () Posts: 42 Threads: 13 Joined: Aug 2021 (Nov-21-2021, 03:02 PM)deanhystad Wrote: Is this a game? Does a user somehow control the dot, or is it a status display? If a game, how does the user control the dot? Not as a game. User does not control the dot. User presses a key at a certain phase. Posts: 42 Threads: 13 Joined: Aug 2021 (Nov-21-2021, 03:06 PM)BashBedlam Wrote: Here is a very basic script using pygame: from pygame import display, QUIT, event, draw, time SCREEN = display.set_mode ((500, 500)) dot_x_position = 30 while True : for user_input_event in event.get () : if user_input_event.type == QUIT : exit () SCREEN.fill ((0, 0, 0)) draw.circle (SCREEN, (200, 0, 0), (249, 249), 220, 4) draw.circle (SCREEN, (0, 0, 200), (dot_x_position, 249), 20) if dot_x_position < 249 : dot_x_position += 1 time.Clock ().tick (100) display.update () Many thanks! I have tried it and it is what I want to start with. I will add to it to do what I have in mind. Much appreciated. Posts: 42 Threads: 13 Joined: Aug 2021 (Nov-21-2021, 03:06 PM)BashBedlam Wrote: Here is a very basic script using pygame: from pygame import display, QUIT, event, draw, time SCREEN = display.set_mode ((500, 500)) dot_x_position = 30 while True : for user_input_event in event.get () : if user_input_event.type == QUIT : exit () SCREEN.fill ((0, 0, 0)) draw.circle (SCREEN, (200, 0, 0), (249, 249), 220, 4) draw.circle (SCREEN, (0, 0, 200), (dot_x_position, 249), 20) if dot_x_position < 249 : dot_x_position += 1 time.Clock ().tick (100) display.update () BashBedlam, Need your help again. At the end of your program, I want to add some other codes. But for some reason, it does not proceed after display.update time.Clock ().tick (100) display.update () Print("I am here") It does not print I am here Appreciate your help. Thanks. Posts: 6,920 Threads: 22 Joined: Feb 2020 Is your code like this? time.Clock ().tick (100) display.update () print("I am here")Or like this? time.Clock ().tick (100) display.update () print("I am here")If the latter you aren't reaching the print statement because you are still in the while True: loop. Posts: 42 Threads: 13 Joined: Aug 2021 (Dec-01-2021, 05:38 AM)deanhystad Wrote: Is your code like this? time.Clock ().tick (100) display.update () print("I am here")Or like this? time.Clock ().tick (100) display.update () print("I am here")If the latter you aren't reaching the print statement because you are still in the while True: loop. Thanks. I have tried both. Former one will print as many times as it cycles through the loop. I dont want that. I want to exit from the moving dot program and do something else. But using the latter format, it just does not print the "I am here". Somehow I need to exit from pygame, I think, to continue to do the rest. Posts: 379 Threads: 2 Joined: Jan 2021 Dec-01-2021, 05:45 PM (This post was last modified: Dec-01-2021, 05:45 PM by BashBedlam.) Okay... In this version, when the dot reaches the middle, we use breakto fall through the first whileloop. After that we print to the screen and wait for the user to close the window. That is where you would put any extra code. Does that help? from pygame import display, QUIT, event, draw, time, font, init SCREEN = display.set_mode ((500, 500)) init () dot_x_position = 30 while True : for user_input_event in event.get () : if user_input_event.type == QUIT : exit () SCREEN.fill ((0, 0, 0)) draw.circle (SCREEN, (200, 0, 0), (249, 249), 220, 4) draw.circle (SCREEN, (0, 0, 200), (dot_x_position, 249), 20) if dot_x_position < 249 : dot_x_position += 1 else : break time.Clock ().tick (100) display.update () text = font.SysFont ('ariel', 42).render ('Close window to contunue.', 1, (255, 255, 255), (1, 1, 1)) SCREEN.blit (text, (70, 50)) display.update () while True : for user_input_event in event.get () : if user_input_event.type == QUIT : exit () Posts: 42 Threads: 13 Joined: Aug 2021 (Dec-01-2021, 05:45 PM)BashBedlam Wrote: Okay... In this version, when the dot reaches the middle, we usebreakto fall through the firstwhileloop. After that we print to the screen and wait for the user to close the window. That is where you would put any extra code. Does that help? from pygame import display, QUIT, event, draw, time, font, init SCREEN = display.set_mode ((500, 500)) init () dot_x_position = 30 while True : for user_input_event in event.get () : if user_input_event.type == QUIT : exit () SCREEN.fill ((0, 0, 0)) draw.circle (SCREEN, (200, 0, 0), (249, 249), 220, 4) draw.circle (SCREEN, (0, 0, 200), (dot_x_position, 249), 20) if dot_x_position < 249 : dot_x_position += 1 else : break time.Clock ().tick (100) display.update () text = font.SysFont ('ariel', 42).render ('Close window to contunue.', 1, (255, 255, 255), (1, 1, 1)) SCREEN.blit (text, (70, 50)) display.update () while True : for user_input_event in event.get () : if user_input_event.type == QUIT : exit () Many thanks! Now I got it running. Your help is very much appreciated! |