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 light blue square with a smaller square outlined in green at its center. The square is drawn one side at a time.

from ipycc import Turtle


t = Turtle()
t.draw()
t.bgcolor('midnightblue')
t.pencolor('ghostwhite')
t.pendown()
side = 5
while side < t.width:
    t.forward(side)
    t.left(90)
    await t.delay(0.1)
    side += 5

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.draw()

A dark blue square with ten circles in its center. The circles are drawn in white and move in synchrony.

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()

p5.draw(draw, 10) # loop for 10 seconds

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

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

Uploaded Source

Built Distribution

ipycc-0.0.10-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ipycc-0.0.10.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for ipycc-0.0.10.tar.gz
Algorithm Hash digest
SHA256 fbd52484dfdbc5bf2915a05b232f1f43bf2f8de716e140a6e2596aeffcf50444
MD5 e3a006e3a247dfea00e059005b764fc9
BLAKE2b-256 7a0faee747172ccb43d0245fa4eba3f91e3d1143c0f6a23affc7aae0c369bfa6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ipycc-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for ipycc-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 d82abd316504e962122919cc817cba7bbbfd86bff56c758ac40c50323185dd21
MD5 d123df1563e64d740d4a578d64f07cc1
BLAKE2b-256 26383bcb1f114f96f44dcf3804c39c8a94a33487bece6cced88cd8eb2cb8b784

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