Having trouble? Report it in the CodeJo Bug Tracker!
Mode
Project
Colors
Grid Canvas
Fabric Canvas
Web Canvas
Document Canvas
Sound
Keyboard Input
Gamepad Input
Canvas Mode
- grd()
- Switch into Grid Canvas mode. Shortcut for load('Scratchpad-grd') This is the default when loading the CodeJo page.
- fab()
- Switch into Fabric Canvas mode. Shortcut for load('Scratchpad-fab')
- web()
- Switch into Web Canvas mode. Shortcut for load('Scratchpad-web')
- doc()
- Switch into Document Canvas mode. Shortcut for load('Scratchpad-doc')
- NOTE:
- When in grd mode, grd will refer to the codejo.grd module, fab to the codejo.fab module when in fab mode, etc.
Project
- catalog()
- List projects, with their associated render mode.
- catalog(True)
- Include abandoned projects in the catalog listing (projects which were not saved before leaving the page).
- load('<projname>')
- Load the project named 'projname' and switch to the correct render mode.
- reload()
- Load the most recently abandoned project.
- run('<projname>')
- Load 'projname' and start it by calling the main() function.
- run()
- Start the currently loaded project by calling the main() function.
- save('<newname>')
- Save a copy of the currently loaded project as 'newname'.
- export()
- Download the currently loaded project.
- export('<projname>')
- Download the project named 'projname'.
- proj._import('<projname>')
- Load the project named 'projname' from the static/examples/ folder.
- proj._import('<projname>', force=True)
- Load the named project. Overwrite if a project with that name already exists.
- proj._import('<projname>', force=True, all=True)
- Load and overwrite all projects in the included examples.
Colors
- Color('<Name>')
- [Note: Captital C] Create color named 'Name' [Note: Does not set the currently active color!] (See colornames() for a complete list).
- Color('<#ABCDEF>')
- Create color with hex value '#ABCDEF'.
- Color('<#FFFFFFAA>')
- Like Color('<#FFFFFF>') but including alpha (transparency) channel.
- Color(r, g, b)
- Create color using red, green, and blue components in the range (0 <= R, G, B <= 255).
- Color((r, g, b))
- Like Color(r, g, b) but sending color data as a 3-tuple instead of separate values.
- Color('rgb(r, g, b)')
- Like Color(r, g, b) but sending color data as a string.
- Color(r, g, b, a)
- Like Color(r, g, b) but with alpha (transparency) channel (0 <= A <= 255).
- Color((r, g, b, a))
- Like Color(r, g, b, a) but sending color data as a 4-tuple instead of separate values.
- Color('rgba(r, g, b, a)')
- Like Color(r, g, b, a) but sending color data as a string.
- Color.from_hsl(h, s, l)
- Create a color using the given hue (0-360) saturation (0-100) and lightness (0-100) values.
- Color.avg(<*colors>)
- Create a color by averaging the given colors.
- Color('random')
- Create a randomly selected color (May not be the same as any specific named color).
- Color(random=True)
- Same as Color('random').
- Color(random='rlight')
- Create a random "light" color. (200 <= R, G, and B <= 255).
- Color(random='rmedium')
- Create a random "medium" color. (100 <= R, G, and B < 200).
- Color(random='rdark')
- Create a random "dark" color. (0 <= R, G, and B < 100).
- Color(random='<family>')
- Create a random color from the color family named 'family'. (See colorfams() for a complete list).
- Color(family='<family>')
- Same as color(random='<family>').
- <Color>.nudge(r=150)
- Starting from the given Color, create a new Color by setting the red component to 150. [Note that the parameter value must be numeric!]
- <Color>.nudge(r='+15')
- Starting from the given Color, create a new Color by adding 15 to the red component. [Note that the parameter value must be a string!]
- <Color>.nudge(g='-11')
- Starting from the given Color, create a new Color by subtracting 11 from the green component. [Note that the parameter value must be a string!]
- <Color>.nudge(b='92%')
- Starting from the given Color, create a new Color with the blue component set to 92% of the current value. [Note that the parameter value must be a string!]
- <Color>.nudge(r=55, g='105%')
- Starting from the given Color, create a new Color with the red component set to 55 and the green component set to 105% of its current value. [Note that the mix of numeric and string values!]
- <Color>.hexval()
- Color instance method that returns the color value as a hex color string.
- <Color>.rgb()
- Color instance method that returns the 'rgb(r, g, b)' form of the Color as a string. [NOTE: To get the actual values, use <Color>.rgb(True)]
- <Color>.rgb01()
- Color instance method that returns the 'rgb(r, g, b)' form of the Color as a string. This method uses rgb values 0-1 instead of 0-255. [NOTE: To get the actual values, use <Color>.rgb01(True)]
- <Color>.hsl()
- Color instance method that returns the 'hsl(h, s, l)' form of the Color as a string. [NOTE: To get the actual values, use <Color>.hsl(True)]
- color()
- [Note: Lower-case c] return the currently active color.
- color(...)
- Create a new Color object using the same parameter formats used in the Color constructor, but ALSO set the currently active color.
- nudge(...)
- Like the <Color>.nudge(...) methods, but start from the currently active color, and set the currently active color to the newly created and returned Color object.
- colornames()
- Return a list of all valid color names. (See the swatcher example for color swatches.)
- colorfams()
- Return a list of all valid color family names. (See the colfams example for color family swatches.)
- colorfams('<family>')
- Return a list of all colors in color family named 'family'.
Grid Canvas
- gr()
- Low-resolution. Pixels are 11x11 screen-resolution pixels.
- hgr()
- High-resolution. Pixels are 3x3 screen-resolution pixels.
- xgr()
- Full resolution.
- NOTE:
- Pass False to resolution selector to not clear the screen after changing resolution. (eg. hgr(False))
- canvas.setgridsize(w, h)
- Set custom grid size to w pixels wide and h pixels high.
- canvas.setpixelsize(w, h)
- Set custom grid size, using w and h as the width and height of the grid pixels in terms of full-resolution pixels.
- WIDTH
- Number of grid pixels across the canvas.
- HEIGHT
- Number of grid pixels vertically.
- clear(bgc=None)
- Clear the canvas to the given color, or to the current background color if not specified.
- canvas.random(margin=0)
- Return a randomly selected point on the canvas as a 2-tuple. Specifying margin will leave a border of margin pixels around the edge that will not be chosen.
- plot(x, y)
- Light up the pixel at (x, y) using the current color.
- plot((x, y))
- Same as plot(x, y) but sending point as a 2-tuple instead of as separate values.
- plot('random')
- Plot a randomly selected point using the current color.
- line(x1, y1, x2, y2)
- Light up the pixels along the line from (x1, y1) to (x2, y2) using the current color.
- line((x1, y1), (x2,y2))
- Same as line(x1, y1, x2, y2) but sending points as 2-tuples instead of as separate values.
- lineto(x2, y2)
- Same as line(x1, y1, x2, y2) where (x1, y1) was the most recently plotted point.
- lineto((x2, y2))
- Same as lineto(x2, y2) but sending point as a 2-tuple instead of as separate values.
- ray(x1, y1, x2, y2)
- Light up pixels from (x1, y1) extending through (x2, y2) and continuing to the edge of the canvas.
- ray(x1, y1, a=<degrees>)
- Light up pixels from (x1, y1) extending along the line at angle a until hitting the edge of the screen. (a = 0 to the right, positive angles counter-clockwise).
- rect(x, y, w, h, color=None)
- Draw a rectangle in grid coordinates from (x1, y1) with width w and height h using specified color, or the default.
- write(txt)
- Draw some pixellated text on the grid.
- write(txt, x, y)
- Start writing text txt at location (x, y).
- write(txt, (x, y))
- Same as write(txt, x, y) but sending point as a 2-tuple instead of as separate values.
- write(txt, wrap=True)
- Same as write(txt) but if the text would run off the screen, go back to the left edge and move down a line before continuing. wrap= is also available as a keyword in (..., x, y) and (..., (x, y)) forms also.
- colorat(x, y)
- Return the canvas color at location (x, y).
Fabric Canvas
- clear(bgc=None)
- Clear the canvas to the given color, or to the current background color if not specified.
- canvas.random(margin=0)
- Return a randomly selected point on the canvas as a 2-tuple. Specifying margin will leave a border of margin pixels around the edge that will not be chosen.
- canvas.lift(<fabobj>)
- Raise the Fabric object fabobj to the front, so that it is not obscured by any other object. Objects lifted later will be most on top.
- WIDTH
- Number of pixels across the canvas.
- HEIGHT
- Number of pixels vertically.
- Rect(x, y, w, h, c=None)
- Create a rectangle object at location (x, y) with width w and height h. Color can also be specified, or it will be taken from the currently active color.
- Circle(x, y, r, c=None)
- Create a circle object at location (x, y) and with radius r.
- Triangle(x, y, b, h, c=None)
- Create an isosceles triangle object at location (x, y) and with base b and height h.
- Polyline(x, y, pts, w=3, c=None)
- Create an polyline object at location (x, y) and with points specified in list pts.
- Text(x, y, txt, size=12, c=None)
- Create an text object at location (x, y) and with text txt and size and color specified or defaults.
- <fabobj>.remove()
- Remove the Fabric object <fabobj> from the scene.
- <fabobj>.outline(w=1, c='Black')
- Set the outline for the Fabric object <fabobj>. Use .outline(None) to remove the outline.
- colorat(x, y)
- Return the canvas color at location (x, y).
Web Canvas
- clear(bgc=None)
- Clear the canvas to the given color, or to the current background color if not specified.
- canvas.random(margin=0)
- Return a randomly selected point on the canvas as a 2-tuple. Specifying margin will leave a border of margin pixels around the edge that will not be chosen.
- WIDTH
- Number of pixels across the canvas.
- HEIGHT
- Number of pixels vertically.
- text(x, y, txt, size=12, c=None)
- Draw filled text txt to canvas at location (x, y) using font size and color if provided, or defaults.
- line(x1, y1, x2, y2, /, w=2, c=None)
- Draw a line from (x1, y1) to (x2, y2) with specified width and color, or defaults.
- lineto(x2, y2)
- Same as line(x1, y1, x2, y2) where (x1, y1) was the most recently plotted point.
- rect(x, y, w, h, color=None)
- Draw a rectangle starting at (x1, y1) with width w and height h using specified color, or the default.
Document Canvas
- clear(bgc=None)
- Clear the canvas to the given color, or to the current background color if not specified.
- canvas.random(margin=0)
- Return a randomly selected point on the canvas as a 2-tuple. Specifying margin will leave a border of margin pixels around the edge that will not be chosen.
- canvas.lift(<elem>)
- Raise the Document Element elem to the front, so that it is not obscured by any other element. Elements lifted later will be most on top.
NOTE: Only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items.
- WIDTH
- Number of pixels across the canvas.
- HEIGHT
- Number of pixels vertically.
- Styles(**kw)
- Create a Styles object, using keyword arguments to specify JavaScript-formatted CSS styles and values.
- Div(children=None, styles=None)
- Create an HTML Div element. If given, children can be a list of child elements, or a string of text which will be used as the div's entire inner HTML.
- AbsDiv(x, y, w, h, /, children=None, c=None, bgc=None, styles=None)
- Create an absolutely-positioned HTML Div element. Position and size must be specified during element creation.
Sound
- init()
- Required before any other sound calls.
- beep()
- A simple tone.
- beep(frequency=440, duration=200, waveform='sine', delay=None)
- A specific frequency can be requested. Give duration for a longer or shorter tone, as required. For different effects, choose waveform from 'sine', 'square', 'triangle', or 'sawtooth'. To play a tone in the future, add a delay in milliseconds.
- chord()
- Play several tones simultaneously. Can sound better than a single-tone beep. Or much worse.
- chord(frequencies=[220, 440, 880], duration=200, waveform='sine', delay=None)
- Pass the desired frequencies as a list. The other parameters as in beep can also be passed for duration, waveform, and delay.
Keyboard Input
- kb_grab()
- Take keyboard focus for the canvas area.
- kb_release()
- Return keyboard focus to the interactive console area.
- getkey()
- Return the next key that has been pressed, or None if no key has been pressed since last checked.
- keystate('<key>')
- Return True if the specified key is currently pressed.
- Special Key Values
-
"ControlLeft"
"ShiftLeft"
"AltLeft"
"ControlRight"
"ShiftRight"
"AltRight"
"ArrowUp"
"ArrowDown"
"ArrowLeft"
"ArrowRight"
"Space"
"Enter"
"Escape"
Gamepad Input
- gp_grab()
- Take focus for the canvas area and begin polling for gamepad events.
- gp_release()
- Return focus to the interactive console area.
- getpadraw(<pad>)
- Return the raw gamepad data for gamepad pad (0 and 1 currently supported). Yours will likely be different, but on my system, with my old Nintendo-style gamepads, it looks like this:
- Raw gamepad return (example)
-
0:D-pad X-value
1:D-pad Y-value
6:X-button
7:A-button
8:Left Bumper
9:Y-button
12:Select-button
13:Start-button
23:B-button
24:Right Bumper