Skip to main content

A Python package for creative coding in Jupyter

Project description

ipycc

A Python package for creative coding in Jupyter

This package makes it easy to explore creative coding in Python using Jupyter notebooks. Its design is heavily inspired by p5.js and Turtle graphics from the Python standard library.

Turtles

A dark blue square with a sprial pattern drawn in white. The spiral is drawn one side at a time.

from ipycc import Turtle


ted = Turtle()
ted.draw()
ted.bgcolor("midnightblue")
ted.pencolor("ghostwhite")
for side in range(40):
    length = side * 5
    ted.fd(length)
    await ted.delay(0.1)
    ted.lt(123)
    await ted.delay(0.1)

Sketches

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

from ipycc import Sketch


p5 = Sketch(400, 400)
p5.background("dodgerblue")
p5.circle(200, 200, 50)
p5.run_sketch()

Ten white circles moving like fireflies on a dark blue background.

import math
from random import uniform
from ipycc import Sketch


p5 = Sketch(400, 400)
coupling = 1
num_bugs = 10
k_n = coupling / num_bugs

class Bug:
    def __init__(self):
        self.x = p5.width * 0.5
        self.y = p5.height * 0.5
        self.r = 5
        self.angle = uniform(0, math.tau)
        self.freq = uniform(5, 10)
        self.da_dt = 0
        self.dt = 0.01
    
    def render(self):
        p5.fill("ghostwhite")
        p5.no_stroke()
        p5.circle(self.x, self.y, 2 * self.r)
    
    def update(self):
        self.angle += self.da_dt * self.dt
        dx = math.cos(self.angle)
        dy = math.sin(self.angle)
        self.x += dx
        self.y += dy
    
    def sync(self, bugs):
        self.da_dt = self.freq
        for bug in bugs:
            self.da_dt += k_n * math.sin(bug.angle - self.angle)

bugs = [Bug() for _ in range(num_bugs)]

def draw():
    p5.background("#1919706F")
    for bug in bugs:
        bug.sync(bugs)
    
    for bug in bugs:
        bug.update()
        bug.render()

# Loop for 10 seconds.
p5.run_sketch(draw, 10) 

ipycc provides a simplified interface to the HTML canvas by wrapping ipycanvas in a beginner-friendly API.

Acknowledgements

  • Portions of the Sketch class are lovingly borrowed from their p5.js and proceso counterparts.
  • Portions of the Turtle class are lovingly borrowed from their standard library counterparts.

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.13.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

ipycc-0.0.13-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ipycc-0.0.13.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for ipycc-0.0.13.tar.gz
Algorithm Hash digest
SHA256 be846e02b02bf939510e2b59e187ab584aa43d7390f66db3bcb7339bca691f78
MD5 03f3d7bfc92fb32ac021c5610e51a6b0
BLAKE2b-256 637c97cd22a8c9af6fe30d0fabc0a44c4d187dd61619048fd63f4fa78f4cf293

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ipycc-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for ipycc-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 7e268c364ae45ca8b629a69e5fddb6c71048e7ec9bdccf766a3ad7b2cb834309
MD5 e3d5d015a27a9e99531aae4ed7643ad0
BLAKE2b-256 37e667e455121dd1fc63c96e5f24dc8837f74673738874ff1596afb47d4629e1

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