Skip to main content

Scratch-like Python programming

Project description

PyStage

Documentation Status

Scratch-like Python programming.

PyStage bridges the gap between Scratch and Python. This module implements all code blocks as available in scratch. With the PyStage command line converter Scratch projects can be easily transferred to Python executable Code. To run your game in Python, PyStage uses PyGame.

test

Demo

Consider the following code. It defines a stage and a sprite on the stage. The functions are code blocks that are associated with events (i.e. connected to a hat block in Scratch) via the corresponding methods.

from pystage.en import Stage

stage = Stage()
stage.add_backdrop("grid")
zombie = stage.add_a_sprite()

def doit(zombie):
    zombie.say("Hello pyStage!")
    for i in range(4):
        zombie.move(10)
        zombie.wait(1)
        zombie.think("This is awesome!")
        zombie.turn_left(90)
        zombie.wait(1)
        zombie.think("")
    zombie.say("Move me around with WASD.")

zombie.when_program_starts(doit)

def right(zombie):
    zombie.change_x_by(10)

def left(zombie):
    zombie.change_x_by(-10)

def up(zombie):
    zombie.change_y_by(10)

def down(zombie):
    zombie.change_y_by(-10)

zombie.when_key_pressed("d", right)
zombie.when_key_pressed("a", left)
zombie.when_key_pressed("w", up)
zombie.when_key_pressed("s", down)

stage.play()

And here is the result:

Demo screen capture

Goals

  • Export your Scratch project to real executable Python code!
  • Helping coding beginners to learn Python "by Scratch".
  • Implementation of scratch blocks in several languages (ideal for kids). As of now en and de.

A quick into video

See our quick intro to PyStage for ScratchCon 2021

Installation

pip install pystage

if doesn't work, try following commands one by one.

pip install wheel
pip install pygame==2.3.0
pip install svglib==1.1.0
pip install reportlab==3.5.67
pip install pystage

Getting started

If you are interested in PyStage and want to get in touch, feel free to join us on our Discord Server.

Currently, only the English API is fully translated, the German API is automatically generated. All other languages will be added when PyStage gets more stable. Get in touch if you want to help maintain a translation.

For the English API, you can start with the following example code:

from pystage.en import Sprite, Stage

stage = Stage()
zombie = stage.add_a_sprite()

def doit(zombie: Sprite):
    for i in range(4):
        zombie.move(10)
        zombie.turn_left(90)
        zombie.wait(1)

zombie.when_program_starts(doit)

stage.play()

Use the autocompletion of your editor to see what methods are available. There are methods for all Scratch blocks bound to your stage and sprite instances. Not all of them work. Motion and Looks is mostly implemented (besides graphics effects), the Pen extension works and most of Sensing should work as well. If you want to know the details, just check the files under src/pystge/core.

The documentation is here: https://pystage.readthedocs.io/en/latest/pystage.en.html


NOTE

Please note this is a pre alpha version. Not all things may work as expected. If so, please contact us or open an issue. Documentation is automatically generated but especially the user-facing block API is still mostly empty.


Import your Scratch projects

Use our Web converter

  1. Publish your Scratch project or download your Scratch project as .sb3 file.
  2. Go to https://convert.pystage.org and convert your project.
  3. Download the resulting zip file, it contains your new Python project ready to run.

Convert on your computer

Converting a Scratch project to Python code:

  1. Export your Scratch project on the Scratch page. You will get an .sb3 file.
  2. Use our command line converter. Yes, it's unhandy, we will work on it to make things easier.

The base usage is python -m pystage.convert.sb3 <SB3 File> -l en -d <DIRECTORY> The parameters are:

  • -l language of generated python "scratch blocks". In the moment of writing, en and de are available.
  • -d the output directory, defaults to current directory
  • -i print intermediate code representation
  • -s print sb3 project.json
  • -p print python code
  • -v verbose
  • -vv debug mode

Contributors

  • Kai Eckert, Stuttgart Media University
  • Florian Rupp, Stuttgart Media University

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pystage-0.1.2a2.tar.gz (782.9 kB view details)

Uploaded Source

Built Distribution

pystage-0.1.2a2-py3-none-any.whl (553.5 kB view details)

Uploaded Python 3

File details

Details for the file pystage-0.1.2a2.tar.gz.

File metadata

  • Download URL: pystage-0.1.2a2.tar.gz
  • Upload date:
  • Size: 782.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.0 requests/2.30.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.2

File hashes

Hashes for pystage-0.1.2a2.tar.gz
Algorithm Hash digest
SHA256 a7a0cdc51cc9e5624027fe844f2427b67f6575b9a3f922d0265225af03e014ee
MD5 5101b0afe4da2d12a71da5da6ba111fc
BLAKE2b-256 b64da0b07dd2dc2d7b154679d308f2ee8ff9cc49704d5c2d134ec726d061050b

See more details on using hashes here.

File details

Details for the file pystage-0.1.2a2-py3-none-any.whl.

File metadata

  • Download URL: pystage-0.1.2a2-py3-none-any.whl
  • Upload date:
  • Size: 553.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.0 requests/2.30.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.2

File hashes

Hashes for pystage-0.1.2a2-py3-none-any.whl
Algorithm Hash digest
SHA256 1b4a67d02094f188e472c7bcf75b8ba230734f456eecc82235015ee853ec317f
MD5 f74d810505cbaedabc8c6e2abcd6cdf6
BLAKE2b-256 a19849509bdf967d521670c415c1382e8aa52ca6a350c9abea0e83a9b9c1aae2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page