PyNugget Documentation



Version 2.1


Assets


We've added a major change: Asset support! Projects can now play sounds and render images which are stored in the Assets tab.

Project information


Projects now internally store their new version; you may notice projects now have a 2 under the version key in their json data.



Introduction

Welcome to the PyNugget documentation. Pynugget was designed by MarsChompsVenus to be a bridge between scratch and other coding languages.

It features a scratch-like stage, allowing users to feel at home and create projects with ease.



Creating Projects

Starting a new project is simple. Click “Start New Project” on the home page, or go to https://python.w8.quuq.dev/editor to go to the editor.

Make sure to save your project consistently!



Using the Editor

Pynugget is built off of python, and uses pyodide to run it in the browser.

Because of this, not all libraries are supported. More common ones such as math and random will work, but others will not. Contact us to request further support!



Project saving

Projects can be saved in two ways at the moment;
One is obviously inferior.



Share links


This is the inferior (but more easily shareable) method.
You can click the button with a link on it to copy a share link to your project.

WARNING: Share links do not store assets, so they must be stored elsewhere for these projects to work. Or you could go full-Ascii.


Pynugget files


This method is much more desirable for development purposes.
You can click the download button - or use Ctrl/⌘ + S - to save the current project as a .pynugget file.

Pynugget files are effectively renamed json files - and their contents can be edited externally. This is not reccomended as it may break syntax.



Auto Version Incrementation


Anyone who codes on a regular basis may know how annoying it can be to increase version numbers, especially if you do it often.

This is why, if you have a number at the end of your project name, pynugget will ask you if you'd like to increment the number by 1.


Syntax


Indentation


Pynugget is currently still a hobby project and is thus a bit buggy. One main bug is that of indentation.

In many codebases, you can use the tab button to indent, as well as four space.

In Pynugget, however, you must use one or the other. That is, you cannot use both tabs and spaces in the same python file, or you will recieve a lovely compiler error.

We are actively looking into this issue, but for the moment, we reccomend using just spaces, as they are automatically generated when a new line is created.

Time


The time library is VERY buggy. We do not reccomend using this library as it is prone to causing many crashes.

In development we attempted to work around it and provide functionality by compiling many common functions into other ways accomplishing their mission; "sleeping" for example would be a different type of waiting function in the JS.

We were not successful.



[New!] Assets

Recently, we've added Asset Support to Pynugget. Assets can be uploaded through the new Assets tab.

Currently, only the following filetypes are permitted:

svg
png
mp3



Custom Functions & Rendering

Pynugget does not support the pygame library, and so we have created several custom functions to allow programs to render on the screen and interact with users.

The custom functions can be found below:


Clearing the stage


The most important function concerned with rendering . . . would arguably be the function to clear the stage.

It's simply:

clear_stage()

Example Project




Rendering Text


You can render text with the function:

render_text("example text", xpos, ypos, centering style: (left, right, or center), scale, "font", color (in hex code), shadow_settings)


Here is a more realistic example:

render_text("Hello world \n\nPress space!", stage_width / 2, stage_height / 2, "center", 30, "Roboto", "#000000", "0px 2px 4px #000000")

Example Project




Forever Loops


Another important thing is a forever loop.
You can create a forever loop with

def loop():
    #code#
await forever(loop)


Just make sure you define any functions before you run

await forever(loop)

to initialize the loop.
Example Project




Rendering Images


You can render images with Pynugget through either a link or the Assets Tab. For projects using mainly share links, a service such as Cubeupload may be useful.

You can render images like this:

render_image(name/url,stage_width/2,stage_height/2,20,20,1)

Either a link or the exact name of an asset can be used.
Example Project




Stage resizing


You can resize the stage to effectively any custom size with

resize_stage(x,y)





Custom Cursors


Use the function

cursor("drag")


to set the mouse cursor. Here is a list of all valid custom mice:

auto
default
none
pointer
wait
text
move
crosshair
grab
grabbing
not-allowed
help
zoom-in
zoom-out
cell
context-menu
alias
copy
no-drop
vertical-text
all-scroll





Playing Sounds


You can play sounds with Pynugget through either a link or the Assets Tab. For projects using mainly share links, a service such as catbox.moe may be useful.

You can play sounds with

play_sound(name/url, volume=1.0)


The first field is the source of the sound it can be either the exact name in the assets tab, or a url.

The second field is the volume. It's not neccessary, but can be used to set the volume of the sound being played from 0-1.


Detecting key presses


You can detect keypresses on and individual level with

KeyPressed("k")


"k" can of course be replaced with any string. See the custom variable "key_down" for more.


Custom Variables

Pynugget also supports several custom variables to read data about the enviroment.


Stage Size


You can read the stage width and stage height with the variables

stage_width
stage_height

Note; the stage coordinates start at 0,0 in the top left corner, and the bottom right will be at the coordinates "stage_width, stage_height"


Reading the mouse


You can read data about the mouse with

mouse_x
mouse_y
mouse_down


Here is a more realistic example:

render_text("Hello world \n\nPress space!", stage_width / 2, stage_height / 2, "center", 30, "Roboto", "#000000", "0px 2px 4px #000000")

Example Project




Last Key Pressed


You can use

key_down


To detect the last key that was pressed. This can be useful for creating typing - or for debugging or finding out the name of the key you want to detect.


Example Projects

Considering pynugget is a hobby project, several projects have been built with it. Here are some below.

Triple Pendulum
Snake