Skip to main content

A generative art library

Project description

LineDream is a generative art library for Python. It is heavily influenced by P5 and Processing. However, it takes a more object oriented approach, with less global state in regards to styling and transformations.

The current output target is SVG. As this provides a robust output set for vector graphics. There is not yet support for a draw loop - it is single frame output, but you could use a loop to simulate this. There are future plans to implement an OpenGL render window.

LineDream library was originally created to make art for a pen plotter, however, the inner object structure could be applied to many different rendering platforms.

Installation

pip install LineDream

Documentation

https://linedream.marcrleonard.com/documentation/

Example

import random
from LineDream import Line, Canvas, Rectangle, Square, Ellipse, Point, Circle, CircleMath, TextLine

Canvas.width=900
Canvas.height=500
Canvas.background_color='black'

for pp in range(100):
	x = random.randint(0, Canvas.width)
	y = random.randint(0, 400)

	coords = (x,y)
	p = Point(*coords)

	p.stroke_color= 'white'

c_size = 180

circle_center = Canvas.width/2, Canvas.height+c_size/2
c = Circle(*circle_center, 180)
c.stroke_color='white'

c = Circle(*circle_center, 200)
c.stroke_color='white'

c = Circle(*circle_center, 220)
c.stroke_color='white'

long=True
for degrees in range(360,180,-10):

	dist_from_circle = 250

	line_len = 40
	if long:
		line_len = 100
		long=False
	else:
		long=True

	d_x_s, d_y_s = CircleMath.distance_to_coords(degrees, dist_from_circle)
	x1 = circle_center[0] + d_x_s
	y1 = circle_center[1] + d_y_s

	d_x, d_y = CircleMath.distance_to_coords(degrees, dist_from_circle + line_len)
	x2 = circle_center[0] + d_x
	y2 = circle_center[1] + d_y

	Line([(x1,y1), (x2,y2)], stroke_color='white')

# EXPERIMENTAL
tt = TextLine('LineDream', kerning=10, stroke_color='white', stroke_width=2)
tt.transform(100, 100)
tt.scale(1.4)

Canvas.save(f'example.svg')

Custom LineDream Shapes

import math
from LineDream.primitives.BaseShape import BaseShape

class Hexagon(BaseShape):

    def __init__(self, c_x, c_y, radius, **kwargs):
        super().__init__(_close_path=True, **kwargs)

        num_points = 6

        # Calculate the angle between each point
        angle_step = 2 * math.pi / num_points

        for i in range(num_points):
            angle = i * angle_step
            x = c_x + radius * math.cos(angle)
            y = c_y + radius * math.sin(angle)
            self.add_vertex(x, y)


if __name__ == "__main__":
    from LineDream import Canvas

    Canvas.width=356
    Canvas.height=276
    Canvas.units = "mm"
    Canvas.background_color = "beige"

    # Add a Hexagon in the middle of canvas with a radius of 50
    Hexagon(Canvas.width/2, Canvas.height/2, 50, )

    Canvas.save('', open_viewer=True)

Todos:

  • Better document colors/opacity/styles for the SVG
  • Add 'tag' notion for lines
  • Add Group to the example

Development

Installation for Development

# Clone the repository
git clone https://github.com/marcrleonard/LineDream.git
cd LineDream

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

Running Tests

# Run tests locally
pytest

# Run tests with verbose output
pytest tests/ -v

# Run tests across multiple Python versions (3.9, 3.10, 3.11, 3.12)
tox

# Run tests with coverage report
tox -e coverage

Building and Publishing

# Build the package
python -m build

# Upload to PyPI (requires twine and PyPI credentials)
twine upload dist/*

# Or upload to TestPyPI first
twine upload --repository testpypi dist/*

Project Structure

All package metadata and dependencies are defined in pyproject.toml following modern Python packaging standards (PEP 517/518).

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

linedream-0.3.15.tar.gz (256.3 kB view details)

Uploaded Source

Built Distribution

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

linedream-0.3.15-py3-none-any.whl (271.3 kB view details)

Uploaded Python 3

File details

Details for the file linedream-0.3.15.tar.gz.

File metadata

  • Download URL: linedream-0.3.15.tar.gz
  • Upload date:
  • Size: 256.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for linedream-0.3.15.tar.gz
Algorithm Hash digest
SHA256 f9e539472107a337d154add25c4e5cb16e2102a640d7f168ab68280cb6b13ac0
MD5 e86f789b7805a28b385810c867b31f3c
BLAKE2b-256 a3a49ab29bd9d92554a8e7c7ec40b18f35a9daaf1c0b690aa846f7fe0028145a

See more details on using hashes here.

File details

Details for the file linedream-0.3.15-py3-none-any.whl.

File metadata

  • Download URL: linedream-0.3.15-py3-none-any.whl
  • Upload date:
  • Size: 271.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for linedream-0.3.15-py3-none-any.whl
Algorithm Hash digest
SHA256 6a37f01d47ab879df9d095807325e917a1923a1dd2a7802935b8d346bc87b208
MD5 02305a2173cd5734ed3048f2d19ddc02
BLAKE2b-256 06c26f796459c3e6784b032595efc139590c9bb177978129ac90973993b5fcb1

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