Skip to main content

A Python package for creative coding in Jupyter

Project description

ipycc

A Python package for creative coding in Jupyter

ipycc is a friendly tool for learning to code, making art, and exploring mathematics within Jupyter notebooks. Try it out at https://code.ipy.cc!

ipycc's Sketch class provides a beginner-friendly API for drawing that is heavily inspired by p5.js. Sketch lovingly borrows from p5.js' source code and documentation, and mimics py5 where possible. Under the hood, it uses the powerful ipycanvas package for drawing.

The package also includes a (mostly) drop-in replacement for Turtle graphics from the Python standard library. The Turtle class is based on the standard library's implementation and uses the Sketch class for rendering. ipycc bundles the standard library's Vec2D class for vector arithmetic along with a few helper functions.

ipycc runs smoothly in JupyterLite, creating a nice way to start coding in the web browser without installing any software.

A tour of ipycc

Here are a few quick examples of ipycc in action.

Sketches

A light gray square with a circle in its center. The circle is drawn with a white center and a black edge.

from ipycc.sketch import Sketch

# Create a sketch and show it.
s = Sketch()
s.show()

# Paint the background.
s.background(200)

# Draw a circle.
s.circle(50, 50, 20)

A purple square with a circle in its center. The circle is drawn with a pink center and a thick white edge.

from ipycc.sketch import Sketch

# Create a sketch and show it.
s = Sketch(400, 400)
s.show()

# Paint the background.
s.background("darkorchid")

# Style the circle.
s.stroke_weight(5)
s.stroke("ghostwhite")
s.fill("fuchsia")

# Draw the circle.
s.circle(200, 200, 100)

A purple square with a circle in its center. The circle is drawn with a pink center and a thick white edge. It moves slowly to the right.

from ipycc.sketch import Sketch

# Create a sketch and show it.
s = Sketch(400, 400)
s.show()

# Define a function to draw frames in an animation.
def draw():
    # Paint the background.
    s.background("darkorchid")

    # Calculate the circle's x-coordinate.
    x = s.frame_count * 3

    # Style the circle.
    s.stroke_weight(5)
    s.stroke(248, 248, 255)
    s.fill("#FF00FF")

    # Draw the circle.
    s.circle(x, 200, 100)

# Run the animation for 5 seconds.
s.run_sketch(draw, 5)

Turtles

A white square with a short black line extending from the center to the right. A black arrow tip at the end of the line points up.

from ipycc.turtle import Turtle, showscreen

# Show the screen.
showscreen()

# Create a turtle.
t = Turtle()

# Draw a line.
t.forward(50)
# Turn left.
t.left(90)

A white square with the outline of a smaller black square. The smaller square is drawn one side at a time.

from ipycc.turtle import Turtle, showscreen

# Show the screen.
showscreen()

# Create a turtle.
t = Turtle()

# Draw a square.
for i in range(4):
    t.forward(50)
    t.left(90)

A black square with a sprial pattern drawn in green. The spiral is drawn one side at a time.

from ipycc.turtle import Turtle, showscreen

# Show the screen.
showscreen()

# Create a turtle.
t = Turtle()

# Style the turtle.
t.bgcolor("black")
t.color(0, 1, 0)

# Draw a spiral.
for i in range(40):
    length = i * 5
    t.forward(length)
    t.left(90)

Installation

If you'd like to install ipycc locally on your computer, start by downloading Python. You can then create a virtual environment, install ipycc, and launch JupyterLab from your system shell like so:

On Linux/macOS:

mkdir ipycc
cd ipycc
python3 -m venv venv
source venv/bin/activate
pip install jupyterlab ipycc
jupyter lab

On Windows:

mkdir ipycc
cd ipycc
py -m venv venv
venv\Scripts\activate
pip install jupyterlab ipycc
jupyter lab

The Python Packaging User Guide has additional information to help you get up and running.

💡 Local alternatives

If you're running ipycc locally, you may also be interested in py5 which uses Processing for drawing. py5 has advanced features that you may wish to explore at some point.

The standard library's version of Turtle graphics doesn't run in the web browser, but you can run it locally from Jupyter using the following magic command:

from turtle import Turtle

%gui tk

t = Turtle()
t.forward(50) # opens in a separate window

License

ipycc is licensed under the GNU Lesser General Public License v3.0.

Contributing

Found a bug or typo? Want a new feature? Feel free to open an issue in the project's GitHub repository!

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

ipycc-0.0.16.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipycc-0.0.16-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file ipycc-0.0.16.tar.gz.

File metadata

  • Download URL: ipycc-0.0.16.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ipycc-0.0.16.tar.gz
Algorithm Hash digest
SHA256 9879b777fdb2ef896c0f0b55dd5fb54443165c7f925b9273d39e8449f4028aa7
MD5 59bd2ca83a0e4ba67294d77a416959df
BLAKE2b-256 b0346f1c3988c48361872419b4a54d5056d8d56f14b0858e63918ed663d08199

See more details on using hashes here.

File details

Details for the file ipycc-0.0.16-py3-none-any.whl.

File metadata

  • Download URL: ipycc-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ipycc-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 0710491f695464a553e75eddfe02f036ec56611c7ac2f326bae658b02dc8f196
MD5 669d9ec4cb3b4eaba23727069aaef02c
BLAKE2b-256 0d47f8a0878a6d2332771d36cda077af1a4aadb64752349c90c70bd372494150

See more details on using hashes here.

Supported by

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