Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to make some things impervious to time.sleep() python
    text
    copied!<p>My program is split into two functions. Once get data, positions, and color of a bunch of bouncing balls. The other draws these balls and makes them move. What I'm trying to do is make one ball appear every five seconds. In order to do this, I must use time.sleep() on one the data() function, but not the moving() function. Since the two are so closely linked, I cannot figure out how to do this. I think the only way would be either to completely chance the logic of my program (which I don't want to do), or to make the moving() function impervious to time.sleep() somehow. Any ideas?</p> <p>getData() function:</p> <pre><code>def getData(numobjects): for x in range(int(numobjects)): xCoordinate.append(random.randint(-300, 300)) yCoordinate.append(random.randint(-300, 300)) speed1.append(random.randrange(-8,8)) speed2.append(random.randrange(-8,8)) for i in range(len(speed1)): for char in range(len(speed2)): if i == 0 or char == 0: i = random.randint(-8,8) char = random.randint(-8,8) color.append([random.random(), random.random(), random.random()]) </code></pre> <p><em>part of the moving()</em> function:</p> <pre><code># Clearing the canvas and hiding the turtle for the next iteration of moving() turtle.clear() turtle.hideturtle() # Drawing all of the circles for i in range(len(xCoordinate)): turtle.penup() turtle.goto(xCoordinate[i], yCoordinate[i]) turtle.pendown() turtle.fillcolor(color[i][0], color[i][1], color[i][2]) turtle.begin_fill() turtle.circle(15) turtle.end_fill() xCoordinate[i] += speed1[i] yCoordinate[i] += speed2[i] # Bouncing off edges of the screen if xCoordinate[i] &gt; 300: xCoordinate[i] = 299 speed1[i] *= -1 if xCoordinate[i] &lt; -300: xCoordinate[i] = -299 speed1[i] *= -1 if yCoordinate[i] &gt; 300: yCoordinate[i] = 299 speed2[i] *= -1 if yCoordinate[i] &lt; -300: yCoordinate[i] = -299 speed2[i] *= -1 # updating turtle and running the moving() function every ten milliseconds turtle.update() turtle.ontimer(moving, 10) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload