Physics Fun with Python Play
h
timmy_i_chen (1001)

Using Python Play is seriously so much fun. In like 40 lines of code I wrote this fun little program with physics.

Simple instructions:
Click anywhere to create a ball.
Click and drag any ball anywhere.
Press Z to knock them all up in the air!

If you haven't tried using Python Play, I definitely recommend it.

You are viewing a single comment. View All
glench (38)

@PaoloAmoroso Python Play does use the asyncio features of Python 3. async/await were added in Python 3.5 (source) so you just need a version of Python greater than that (which repl.it has). If you want to use Python Play on repl.it, you just need to use a Python (3) repl and install replit-play in the package manager. Or you can just fork this repl.

And the reason for using async/await is mostly to be able to set up timers. In normal loop-based python programming, it's really annoying (especially for beginners) to make a program that changes the background to red, waits 1 second, changes to green, waits 1 second, then changes to blue and cycles back to red. In Python Play you can just do that like this:

@play.repeat_forever
async def do():
  play.set_backdrop('red')
  await play.timer(seconds=1)
  play.set_backdrop('green')
  await play.timer(seconds=1)
  play.set_backdrop('blue')
  await play.timer(seconds=1)

link to repl with above code