• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created over 3 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Joy is a tiny creative coding library in Python.

Joy

Joy is a tiny creative coding library in Python.

Installation

The easiest way to install it is download joy.py and place it in your directory. The library has no dependencies.

It can be downloaded from:

https://github.com/fossunited/joy/raw/main/joy.py

Coordinate System

Joy uses a canvas with (0, 0) as the center of the canvas.

By default, the size of the canvas is (300, 300).

Using Joy

The Joy library integrates well with Jupyter environment and it is recommended to explore Joy in a Jupyter lab.

The first thing you need to do is import the module.

from joy import *

Once the functionality in the module is imported, you can start playing with it.

Basic Shapes

Joy supports the basic shapes circle, ellipse, rectangle and line.

Let's start with a drawing a circle:

c = circle()
show(c)

svg

By default circle will have center at (0, 0) and radius as 100. But you can specify different values.

c = circle(x=50, y=50, r=50)
show(c)

svg

The other basic types that are supported are ellipse, rectangle, and line:

s1 = circle()
s2 = ellipse()
s3 = rectangle()
s4 = line()
show(s1, s2, s3, s4)

svg

Combining Shapes

Joy supports + operator to join shapes.

def donut(x, y, r):
    c1 = circle(x=x, y=y, r=r)
    c2 = circle(x=x, y=y, r=r/2)
    return c1+c2

d = donut(0, 0, 100)
show(d)

svg

Transformations

Joy supports translate, rotate and scale transformations. Transformations are applied using | operator.

shape = circle(r=50) | translate(x=100, y=0)
show(shape)

svg

Transformations can be chained too.

r1 = rectangle(w=200, h=200)
r2 = r1 | rotate(angle=45) | scale(1/SQRT2)
show(r1, r2)

svg

Higer-Order Transformations

Joy supports higher-order transformation repeat.

The repeat transformation applies a transformation multiple times and combines all the resulting shapes.

For example, draw 10 circles:

c = circle(x=-100, y=0, r=50)
shape = c | Repeat(10, Translate(x=10, y=0)
show(shape)

svg

Combined with rotation, it can create amusing patterns.

shape = line() | repeat(18, rotate(angle=10))
show(shape)

svg

We could do the same with a square:

shape = rectangle(w=200, h=200) | repeat(18, rotate(angle=10))
show(shape)

svg

or a rectangle:

shape = rectangle(w=200, h=100) | repeat(18, rotate(angle=10))
show(shape)

svg

We can combine multiple transformations and repeat.

shape = rectangle(w=300, h=300) | repeat(72, rotate(360/72) | scale(0.92))
show(shape)

svg

You can try the same with a circle too:

c = circle(x=100, y=0, radius=50)
shape = c | repeat(36*4, rotate(10) | scale(0.97))
show(shape)

svg

For more information, please checkout the tutorial.

Tutorial

See tutorial.ipynb.

Acknowledgements

Special thanks to Amit Kapoor (@amitkaps). This library woundn't have been possible without his inputs.

The long discussions between @anandology and @amitkaps on functional programming and computational artistry (for almost over an year) and the initial experiments were some of the seeds that gave life to this library.

License

This repository has been released under the MIT License.

More Repositories

1

fossunited

fossunited.org
Vue
72
star
2

mon_school

Frappe App for Mon School based on Frappe LMS
Python
45
star
3

falcon

A service that execute code in any programming language in a sandboxed environment.
Python
42
star
4

indiafoss

Free and Open Source Software conference management by the FOSS United community.
Python
31
star
5

monschool-website

Repository of all courses on mon.school
Python
24
star
6

Samaaja

Samaaja is an open source software solution for rapidly building location based civic services connected with volunteer, human interactions.
Python
16
star
7

robinhood

Volunteer checkin app (Frappe) for Robin Hood Army, a non-profit that distributes food surplus via volunteers.
Python
14
star
8

infra

Infrastrure of the FOSS United including the cloud servers and hosted free software
10
star
9

the-joy-of-programming

The Joy of Programming Course
Python
7
star
10

malgudi

The learning platform of Foss United
HTML
6
star
11

Branding

Branding assets of FOSS United Foundation
5
star
12

tg-feed-bot

Telegram bot to notify a channel whenever a new post appears in an RSS/Atom Feed
Python
4
star
13

printrov_merch_store

Pertrove Integration for Frappe
Python
4
star
14

fossunited.org

3
star
15

vms

Volunteer management system for NGO's
Python
3
star
16

documents

2
star
17

mon_events

Manage FOSS events(Hackthons/meetups).
Python
2
star
18

coursectl

CLI tool to manage courses on Community LMS
Python
2
star
19

hackathon-projects

A public repo for projects built during FOSS hackathons, grant under Hackathon Grant
1
star
20

server-setup

Repository containing all information about self hosted applications and servers
Python
1
star
21

governance

Information related to the Governance of the FOSS United Community
1
star