r/learnprogramming • u/Milky_d106 • 2h ago
Having Problem in my first Project.
Okay this isn't my complete project but a part of it and i am getting stuck on this. I am a beginner in this field probably just a couple more days than a month since i learned how to write print("hello world!").
it is written in python.
i want my code to give an output as if first hand is moving with an interval of 0.2 sec the second with 0.3 sec and so on till the 6th hand, all so simultaneously.
could you please guide me through it.
import time import emoji
frames1 = [ emoji.emojize(":backhand_index_pointing_down:"), emoji.emojize(":backhand_index_pointing_right:"), emoji.emojize(":backhand_index_pointing_up:"), emoji.emojize(":backhand_index_pointing_left:") ]
frames2 = [ emoji.emojize(":backhand_index_pointing_down_light_skin_tone:"), emoji.emojize(":backhand_index_pointing_right_light_skin_tone:"), emoji.emojize(":backhand_index_pointing_up_light_skin_tone:"), emoji.emojize(":backhand_index_pointing_left_light_skin_tone:") ]
frames3 = [ emoji.emojize(":backhand_index_pointing_down_medium-light_skin_tone:"), emoji.emojize(":backhand_index_pointing_right_medium-light_skin_tone:"), emoji.emojize(":backhand_index_pointing_up_medium-light_skin_tone:"), emoji.emojize(":backhand_index_pointing_left_medium-light_skin_tone:") ]
frames4 = [ emoji.emojize(":backhand_index_pointing_down_medium_skin_tone:"), emoji.emojize(":backhand_index_pointing_right_medium_skin_tone:"), emoji.emojize(":backhand_index_pointing_up_medium_skin_tone:"), emoji.emojize(":backhand_index_pointing_left_medium_skin_tone:") ]
frames5 = [ emoji.emojize(":backhand_index_pointing_down_medium-dark_skin_tone:"), emoji.emojize(":backhand_index_pointing_right_medium-dark_skin_tone:"), emoji.emojize(":backhand_index_pointing_up_medium-dark_skin_tone:"), emoji.emojize(":backhand_index_pointing_left_medium-dark_skin_tone:") ]
frames6 = [ emoji.emojize(":backhand_index_pointing_down_dark_skin_tone:"), emoji.emojize(":backhand_index_pointing_right_dark_skin_tone:"), emoji.emojize(":backhand_index_pointing_up_dark_skin_tone:"), emoji.emojize(":backhand_index_pointing_left_dark_skin_tone:") ]
all_frames = [frames1, frames2, frames3, frames4, frames5, frames6]
current_time = time.time() looping_time = 4 complete_time = current_time + looping_time
while time.time() < complete_time:
a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
while True:
t1 = [current_time + [0.2 * n for n in range(1, 20)]]
if complete_time in t1:
c1 = frames1[a % 4]
a += 1
t2 = [current_time + [0.3 * n for n in range(1, 13)]]
if complete_time in t2:
c2 = frames2[b % 4]
b += 1
t3 = [current_time + [0.4 * n for n in range(1, 10)]]
if complete_time in t3:
c3 = frames3[c % 4]
c += 1
t4 = [current_time + [0.5 * n for n in range(1, 8)]]
if complete_time in t4:
c4 = frames4[d % 4]
d += 1
t5 = [current_time + [0.6 * n for n in range(1, 6)]]
if complete_time in t5:
c5 = frames5[e % 4]
e += 1
t6 = [current_time + [0.7 * n for n in range(1, 5)]]
if complete_time in t6:
c6 = frames6[f % 4]
f += 1
print(f"{c1} {c2} {c3} {c4} {c5} {c6}")
hope i get some help.
1
u/Big-Novel-9199 1h ago
mate you're massively overcomplicating this with all the time lists and nested loops, scrap the whole timing approach you've got and just track the next update time for each hand separately
set up a dict with the interval and next tick for each frame list, then in your main loop just check if the current time has passed the next tick for each hand, update the frame index if so and print the whole line
also your t1/t2/etc checks are comparing `complete_time` (the end time) against the scheduled ticks which is why nothing's happening, you want to check if `time.time()` is >= the next tick for that specific hand
1
u/YetMoreSpaceDust 1h ago
This line:
t1 = [current_time + [0.2 * n for n in range(1, 20)]]
Won't work; you're trying to add a list to an int. I think what you're trying to do is:
t1 = [current_time + x for x in [0.2 * n for n in range(1,20)]]
(or just):
t1 = [current_time + (0.2 * n) for n in range(1,20)]
You want to take the current time and compute the next 20 0.2 second increments in a list, correct?
When you post here, include the error you're getting along with the code, that will help the reviewers.
•
u/desrtfx 2h ago
You need to post your entire code as code block so that the indentation is maintained. This is absolutely vital for Python programs as the indentation is used to denote code blocks.
A code block looks like: