Skip to content
← Back to Community
Physics Fun with Python Play
Profile icon
h
has Hacker Plan
timmy_i_chen

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.

Voters
Profile icon
AudreyZhu
Profile icon
CynicalBlack
Profile icon
ChezCoder
Profile icon
MATHyou
Profile icon
MaxHerrera
Profile icon
TrentonHorne
Profile icon
glench
Profile icon
ronimac52
Profile icon
MichaelSynnott
Profile icon
launcherman08
Comments
hotnewtop
Profile icon
8Observer8

Hello. When I run your example with unit tests I see "Ran 0 tests". Please, help me to run tests. It is your example: https://repl.it/@timmy_i_chen/Unit-Testing-in-Python-with-Replit

Profile icon
a_siebel

The repl.it is really slow. Is this normal or a problem of my location (lag?). I'm viewing it from germany.

Profile icon
SaurabhBadenkal

hold z, and it removes balls

Profile icon
timmy_i_chen

@SaurabhBadenkal Totally a feature and not a bug :B

Profile icon
SaurabhBadenkal

@timmy_i_chen :'D (y)

Profile icon
kaiserb1

Scrolling works too :-)

Profile icon
mkhoi

If you spawn balls and dont move your mouse in the process, they will balance on each other LOL

Profile icon
timmy_i_chen

@mkhoi I love doing this, then you place one slightly-off-center ball and watch it all tumble down ;)

Profile icon
mkhoi

@timmy_i_chen I like to spawn collumns of balls then spawn one ball and throw it, it was awseome seeing them fall down

Profile icon
TomNG

It lags

Profile icon
PaoloAmoroso

I guess Python Play requires a specific type of Python-based REPL as it uses async features of Python 3.7 but the standard Python 3 REPL has 3.6.x, right?

Profile icon
21natzil

@PaoloAmoroso I'm not sure what you mean, the play library does not utilize asyncio, from what I've seen.

Profile icon
PaoloAmoroso

@21natzil The Python Play tutorial and the documentation do apparently use asyncio in some examples using Python Play. Is Python 3.7 required for user code?

Profile icon
21natzil

@PaoloAmoroso Ah, you're correct, I retract that statement. It does use some trickery to make normal functions async.

Profile icon
glench

@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