{"id":18441536,"url":"https://github.com/zokis/pyartistry","last_synced_at":"2025-07-09T06:07:41.799Z","repository":{"id":232271486,"uuid":"783909666","full_name":"zokis/PyArtistry","owner":"zokis","description":"A Python Library for Creative Coding","archived":false,"fork":false,"pushed_at":"2024-04-13T16:27:21.000Z","size":119,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T19:47:22.959Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zokis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-08T20:17:15.000Z","updated_at":"2024-12-06T12:30:04.000Z","dependencies_parsed_at":"2024-04-13T17:36:36.857Z","dependency_job_id":"037d68c6-b3a5-4dee-bed9-c2bc02a58ef7","html_url":"https://github.com/zokis/PyArtistry","commit_stats":null,"previous_names":["zokis/pyartistry"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zokis/PyArtistry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zokis%2FPyArtistry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zokis%2FPyArtistry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zokis%2FPyArtistry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zokis%2FPyArtistry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zokis","download_url":"https://codeload.github.com/zokis/PyArtistry/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zokis%2FPyArtistry/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264403798,"owners_count":23602621,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T06:38:14.360Z","updated_at":"2025-07-09T06:07:41.769Z","avatar_url":"https://github.com/zokis.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyArtistry: A Python Library for Creative Coding\n\nPyArtistry is a Python library inspired by the popular Processing and p5.js framework. Originally designed for a personal project to generate static images without user interaction. PyArtistry is free to use, and its continuation and evolution are welcome by the community.\n\n![logo](https://github.com/zokis/PyArtistry/blob/main/logo.png?raw=true)\n\n- image generated by [example.py](https://github.com/zokis/PyArtistry/blob/main/example.py) script\n\nTo use PyArtistry, you need to have Python and the Pillow library installed. You can install Pillow using pip:\n`pip install Pillow` \n\n## Getting Started\n\nTo start using PyArtistry, you first need to create a canvas where you can draw your shapes and images:\n\n```\nfrom pyartistry import *\n\ncreateCanvas(400, 400)\n```\n## Drawing Shapes\n\nPyArtistry provides various functions to draw shapes on the canvas:\n\n### Rectangles\n\n`rect(x, y, width, height)` \n\n-   `x`: The x-coordinate of the rectangle.\n-   `y`: The y-coordinate of the rectangle.\n-   `width`: The width of the rectangle.\n-   `height`: The height of the rectangle.\n\n### Circles\n\n`circle(x, y, radius)` \n\n-   `x`: The x-coordinate of the circle's center.\n-   `y`: The y-coordinate of the circle's center.\n-   `radius`: The radius of the circle.\n\n### Ellipses\n\n`ellipse(x, y, width, height)` \n\n-   `x`: The x-coordinate of the ellipse's center.\n-   `y`: The y-coordinate of the ellipse's center.\n-   `width`: The width of the ellipse.\n-   `height`: The height of the ellipse.\n\n### Triangles\n\n`triangle(x1, y1, x2, y2, x3, y3)` \n\n-   `x1`, `y1`: The coordinates of the first vertex.\n-   `x2`, `y2`: The coordinates of the second vertex.\n-   `x3`, `y3`: The coordinates of the third vertex.\n\n### Quads\n\n`quad(x1, y1, x2, y2, x3, y3, x4, y4)` \n\n-   `x1`, `y1`: The coordinates of the first vertex.\n-   `x2`, `y2`: The coordinates of the second vertex.\n-   `x3`, `y3`: The coordinates of the third vertex.\n-   `x4`, `y4`: The coordinates of the fourth vertex.\n\n### Lines\n\n`line(x1, y1, x2, y2)` \n\n-   `x1`, `y1`: The coordinates of the start point.\n-   `x2`, `y2`: The coordinates of the end point.\n\n### Points\n\n`point(x, y)` \n\n-   `x`: The x-coordinate of the point.\n-   `y`: The y-coordinate of the point.\n\n## Custom Shapes\n\n-   `beginShape()`: Begins recording vertices for a shape.\n-   `vertex(x, y)`: Specifies a vertex for the shape.\n-   `endShape(close=False)`: Ends recording vertices and draws the shape. If `close` is `True`, the shape will be closed.\n\n## Color\n\nPyArtistry allows you to set colors for the shapes you draw:\n\n### Fill Color\n\n`fill(r, g, b)` \n\n-   `r`: The red component of the color (0-255).\n-   `g`: The green component of the color (0-255).\n-   `b`: The blue component of the color (0-255).\n\n`noFill()` \n\n### Stroke Color\n\n`stroke(r, g, b)` \n\n-   `r`: The red component of the stroke color (0-255).\n-   `g`: The green component of the stroke color (0-255).\n-   `b`: The blue component of the stroke color (0-255).\n\n`noStroke()` \n\n### Stroke Weight\n\n`strokeWeight(weight)` \n\n-   `weight`: The thickness of the stroke.\n\n## Math\n\n-   `sin(angle)`: Returns the sine of an angle.\n-   `cos(angle)`: Returns the cosine of an angle.\n-   `tan(angle)`: Returns the tangent of an angle.\n-   `remap(value, start1, stop1, start2, stop2, withinBounds=False)`: Re-maps a number from one range to another.\n-   `dist(x1, y1, x2, y2)`: Calculates the distance between two points in 2D.\n-   `lerp(start, stop, amt)`: Linearly interpolates between two values.\n-   `invLerp(start, stop, amt)`: Inverse linear interpolation between two values.\n-   `lerpColor(c1, c2, amt)`: Linearly interpolates between two colors.\n\n## Transformations\n\nPyArtistry supports transformations such as translation, rotation, and scaling:\n\n### Translate\n\n`translate(x, y)` \n\n-   `x`: The amount to translate along the x-axis.\n-   `y`: The amount to translate along the y-axis.\n\n### Rotate\n\n`rotate(angle)` \n\n-   `angle`: The angle of rotation in radians (use `radians(angle)` to convert degrees to radians).\n\n### Scale\n\n`scale(sx, sy)` \n\n-   `sx`: The scaling factor along the x-axis.\n-   `sy`: The scaling factor along the y-axis.\n\n## Displaying the Canvas\n\nAfter drawing your shapes, you can display the canvas using the `show()` function:\n\n`show()` \n\n## Saving the Canvas\n\nYou can save the canvas to an image file using the `save()` function:\n\n\n`save(\"filename.png\")` \n\n## Background\n\n`background(r, g, b)` \n\n-   `r`: The red component of the background color (0-255).\n-   `g`: The green component of the background color (0-255).\n-   `b`: The blue component of the background color (0-255).\n\n## Angle Mode\n\n`angleMode(mode)` \n\n-   `mode`: Either `DEGREES` or `RADIANS`. Sets the mode for interpreting angles in trigonometric functions.\n\n## Rectangle and Ellipse Modes\n\n`rectMode(mode)` \n\n-   `mode`: One of `CORNER`, `CORNERS`, `CENTER`, or `RADIUS`. Sets the mode for drawing rectangles.\n\n\n`ellipseMode(mode)` \n\n-   `mode`: One of `CORNER`, `CORNERS`, `CENTER`, or `RADIUS`. Sets the mode for drawing ellipses.\n\n## Color Mode\n\n`colorMode(mode, max_val=None)` \n\n-   `mode`: Either `RGB`, `HSB`, or `HSL`. Sets the mode for interpreting color values.\n-   `max_val`: Optional. The maximum value for color components in `RGB` mode.\n\n## State\n\n-   `push()`: Saves the current drawing style settings and transformations.\n-   `pop()`: Restores the saved drawing style settings and transformations.\n\n## Example\n\nHere's a simple example that draws a rectangle and a circle with different colors:\n\n```python\nfrom pyartistry import *\n\ncreateCanvas(400, 400)\nfill(255, 0, 0)\nrect(100, 100, 200, 150)\nfill(0, 0, 255)\ncircle(200, 200, 50)\nshow()\n```\n\nThis will create a canvas with a red rectangle and a blue circle.\n\n## Constants\n\n-   `DEGREES`: Constant for setting angle mode to degrees.\n-   `RADIANS`: Constant for setting angle mode to radians.\n-   `RGB`: Constant for setting color mode to RGB.\n-   `HSB`: Constant for setting color mode to HSB (Hue, Saturation, Brightness).\n-   `HSL`: Constant for setting color mode to HSL (Hue, Saturation, Lightness).\n-   `CORNER`: Constant for setting rectMode and ellipseMode\n-   `CORNERS`: Constant for setting rectMode and ellipseMode\n-   `CENTER`: Constant for setting rectMode and ellipseMode\n-   `RADIUS`: Constant for setting rectMode and ellipseMode\n\n## Noise Module\n\nThe Noise module in PyArtistry is used to generate Perlin noise, which is useful for creating natural-looking textures and patterns. Perlin noise is a type of gradient noise developed by Ken Perlin.\n\n### Functions\n\n#### `noise(x, y=0, z=0)`\n\nGenerates a Perlin noise value based on the input coordinates.\n\n-   `x`: The x-coordinate of the noise sample.\n-   `y`: The y-coordinate of the noise sample. Default is 0.\n-   `z`: The z-coordinate of the noise sample. Default is 0.\n\nReturns a noise value between 0 and 1.\n\n#### `noiseSeed(seed)`\n\nSets the seed value for the Perlin noise function.\n\n-   `seed`: The seed value for the noise generator.\n\nThis function allows you to get consistent noise values across different runs of your program.\n\n### Example\n\n```python\nfrom pyartistry import noise, noiseSeed\n\nnoiseSeed(99)\nn = noise(0.1, 0.2, 0.3)\nprint(n)  # Example output: 0.3778873367033471\n```\n\n### Notes\n\n-   The `noise` function generates values between 0 and 1, which can be scaled and translated to fit any desired range.\n-   The `noiseSeed` function is useful for creating reproducible noise patterns, which can be important in some applications.\n-   Perlin noise can be used for various purposes, such as generating terrain, creating textures, or simulating natural phenomena like clouds and water.\n\n## Saving GIFs\n\n### `saveGif(draw_func, filename, size=(400, 400), max_frames=100, frame_rate=60)`\n\nGenerates a GIF by repeatedly calling a drawing function and saving the resulting frames.\n\n-   `draw_func`: A function that takes a single argument `frameCount` and draws the content for each frame.\n-   `filename`: The name of the output GIF file.\n-   `size`: A tuple `(width, height)` specifying the size of each frame. Default is `(400, 400)`.\n-   `max_frames`: The total number of frames in the GIF. Default is `100`.\n-   `frame_rate`: The frame rate of the GIF in frames per second. Default is `60`.\n\nThis function creates a new canvas for each frame, calls the `draw_func` to draw the frame, and then appends the frame to the GIF. The GIF is saved with the specified `filename`.\n\n### Example Usage\n\n```python\nfrom pyartistry import *\n\ndef draw(frameCount):\n    background(200, 200, 200)\n\n    c1 = color(155, 0, 255, 255)\n    c2 = color(100, 255, 50, 255)\n\n    fill(lerpColor(c1, c2, (1 / 8) * frameCount))\n    translate(20, 20)\n    quad(x1=40, y1=40, x2=50, y2=60, x3=30, y3=60, x4=30, y4=50)\n\nsaveGif(draw, \"filename.gif\", (255, 255), max_frames=8, frame_rate=1)\n```\n\nIn this example, the `draw` function creates a series of frames with a quadrilateral that changes color over time. The `saveGif` function then generates a GIF with 8 frames at a frame rate of 1 frame per second.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzokis%2Fpyartistry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzokis%2Fpyartistry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzokis%2Fpyartistry/lists"}