Program to move a dot towards a circle center - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Program to move a dot towards a circle center (/thread-35601.html) Pages:
1
2
|
Program to move a dot towards a circle center - plumberpy - Nov-21-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. RE: Program to move a dot towards a circle center - deanhystad - Nov-21-2021 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? RE: Program to move a dot towards a circle center - BashBedlam - Nov-21-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 () RE: Program to move a dot towards a circle center - plumberpy - Nov-23-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. RE: Program to move a dot towards a circle center - plumberpy - Nov-23-2021 (Nov-21-2021, 03:06 PM)BashBedlam Wrote: Here is a very basic script using pygame: 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. RE: Program to move a dot towards a circle center - plumberpy - Dec-01-2021 (Nov-21-2021, 03:06 PM)BashBedlam Wrote: Here is a very basic script using pygame: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. RE: Program to move a dot towards a circle center - deanhystad - Dec-01-2021 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. RE: Program to move a dot towards a circle center - plumberpy - Dec-01-2021 (Dec-01-2021, 05:38 AM)deanhystad Wrote: Is your code like this?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. RE: Program to move a dot towards a circle center - BashBedlam - Dec-01-2021 Okay... In this version, when the dot reaches the middle, we use break to fall through the firstwhile loop. 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 () RE: Program to move a dot towards a circle center - plumberpy - Dec-03-2021 (Dec-01-2021, 05:45 PM)BashBedlam Wrote: Okay... In this version, when the dot reaches the middle, we use Many thanks! Now I got it running. Your help is very much appreciated! |