{"id":13936327,"url":"https://github.com/ryu577/pyray","last_synced_at":"2025-04-08T10:33:27.018Z","repository":{"id":44598282,"uuid":"116544595","full_name":"ryu577/pyray","owner":"ryu577","description":"A 3d rendering library written completely in python.","archived":false,"fork":false,"pushed_at":"2023-12-02T01:25:17.000Z","size":2309,"stargazers_count":742,"open_issues_count":2,"forks_count":105,"subscribers_count":44,"default_branch":"master","last_synced_at":"2025-04-01T09:31:40.529Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryu577.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"ryu577","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2018-01-07T06:56:02.000Z","updated_at":"2025-03-15T23:01:26.000Z","dependencies_parsed_at":"2023-12-02T02:26:15.038Z","dependency_job_id":"d492bb7f-a060-4a02-979b-6369b675faed","html_url":"https://github.com/ryu577/pyray","commit_stats":{"total_commits":242,"total_committers":14,"mean_commits":"17.285714285714285","dds":"0.37603305785123964","last_synced_commit":"331400157e47cd136be4192d4812f843ec9a0c34"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryu577%2Fpyray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryu577%2Fpyray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryu577%2Fpyray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryu577%2Fpyray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryu577","download_url":"https://codeload.github.com/ryu577/pyray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247824432,"owners_count":21002270,"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-08-07T23:02:34.316Z","updated_at":"2025-04-08T10:33:26.993Z","avatar_url":"https://github.com/ryu577.png","language":"Python","funding_links":["https://github.com/sponsors/ryu577"],"categories":["Python"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/ryu577/pyray.svg?branch=master)](https://travis-ci.com/ryu577/pyray)\n\n# Introduction\n\nI'm creating this repository in January 2018 and it is crazy that the best open source option for rendering 3d scenes remains POV ray.\nNow, POV ray is a great program, but why can't we have that functionality (rendering 2d, 3d and higher dimensional objects and scenes) in Python, a language that is perhaps the most widely used already and only growing in popularity?\nThis code is a first step towards that goal - have the ability to do everything POV ray does - rendering complex 3d objects and scenes, animations and much more in plain, vanilla Python. I imagine this would find applications in creating videos, video games, physical simulations or just pretty pictures.\n\nWhile there certainly is a very long way to go before this can be a reality, it won't happen without taking a first step. And of course, I could use help :)\n\nAbove all else, I want to emphasize simplicity in this library and minimize the dependence on external libraries so more people can hit the ground running with it.\n\n\n# Installation\nTo install the library, run (pyray was taken on pypi):\n\n```\npip install raypy\n```\n\nMake sure you have all the requirements (requirements.txt) installed. If not, you can run:\n\n```\npip install -r requirements.txt\n```\n\nAlternately, you can fork/download the code and run from the main folder:\n\n```\npython setup.py install\n```\n\n# Requirements\nI've made every effort to keep the requirements for this project to the bare minimum so most people can get it running with almost no pain. These are - \nPython Imaging Library (PIL), numpy and scipy. For writing on math equations images using the methods in WriteOnImage.py, you'll need matplotlib and sympy. All of these can be installed quite easily with `pip install -r requirements.txt`\n\n# Usage\nTo keep things simple and the dependencies minimal, the program simply writes an image or a series of images to the folder `./Images/RotatingCube` (this was the first object that was animated with this tool). \n\nYou can run any method tagged @MoneyShot to see how this works. For example, you can run the following method from cube.py - \n\n```python\nfrom pyray.shapes.solid.cube import *\ncube_with_cuttingplanes(7, popup=True)\n```\nand this will generate a colorful 3d cube with diagonal cutting planes shaded in different colors (in the folder where you run it from, file called im0.png). Something like this (click to see what happens) - \n\n\u003ca href=\"http://www.youtube.com/watch?feature=player_embedded\u0026v=KuXnrg1YpiY\" \ntarget=\"_blank\"\u003e\u003cimg src=\"https://github.com/ryu577/pyray/blob/master/Images/cube_planes.png\" \nalt=\"Image formed by above method\" width=\"240\" height=\"240\" border=\"10\" align=\"center\"/\u003e\u003c/a\u003e\n\n\nYou can now create a series of them using the following code - \n\n```python\nfor i in range(3, 15):\n\tcube_with_cuttingplanes(numTerms = i, im_ind = i-3)\n```\n\nThe series of images can then be easily converted to a video using the open source \u003ca href=\"https://ffmpeg.org/download.html\"\u003effmpeg program\u003c/a\u003e. For example\n\n\u003e ffmpeg -framerate 10 -f image2 -i im%d.png -vb 20M vid.avi\n\nThe video can then be converted to a .gif file if required - \n\n\u003e ffmpeg -i vid.avi -pix_fmt rgb24 -loop 0 out.gif\n\nFor example, something like this:\n\n\n\u003ca href=\"https://www.youtube.com/watch?v=OV7c6S32IDU\" \ntarget=\"_blank\"\u003e\u003cimg src=\"https://github.com/ryu577/ryu577.github.io/blob/master/Downloads/GradientAscent/which_direction.gif\" \nalt=\"Image formed by above method\" width=\"240\" height=\"180\" border=\"10\" /\u003e\u003c/a\u003e\n\nIn case you're wondering, you can generate the images used in the gif above via:\n\n```python\nfrom pyray.shapes.twod.plane import *\nfor i in range(20):\n\tbest_plane_direction(im_ind=i)\n```\n\nIf you think this is valuable, please star :)\n\n# Contributing\n\nWe welcome any kind of contribution, bug report, suggestion, new module, etc. Anything is welcome.\n\n# Install pre-commit hooks\n\nThe pre-commit hooks will run a set of linters and formmatters automatically against your code when\nyou commit. This enforces a common set of style standards and checks for common, simple mistakes in\ncode. If you have a project-specific set of hooks, install those instead. Otherwise, install the repo-wide hooks. From root:\n\n```shell\npip install pre-commit\npre-commit install\n```\n\n# Other examples\n\nTo create a bouncy sphere or a wavy sphere, run \n```python\nfrom pyray.shapes.solid.sphere import *\ndraw_wavy_sphere_wrapper('.\\\\im', 66, 1)\n```\n\n\u003cimg src=\"https://github.com/ryu577/pyray/blob/master/Images/WavySphere.gif\" \nalt=\"Image formed by above method\" width=\"240\" height=\"240\" border=\"10\" /\u003e\u003c/a\u003e\n\n```python\nimport numpy as np;from PIL import Image, ImageDraw, ImageFont, ImageMath; from pyray.axes import *\nfrom pyray.rotation import *; from pyray.shapes.twod.plot import draw_2d_arrow\nfrom pyray.axes import draw_grey_grid, Path, ZigZagPath, draw_grid\nfrom pyray.misc import dist\n\nfor i in range(0, 66):\n    im = draw_grid()\n    draw = ImageDraw.Draw(im,'RGBA')\n    pts = np.array([[0,0],[1,1],[5,-3]])\n    pth = Path(pts)\n    pth.zg.draw_lines(draw,i/10.0)\n    im.save(\"im\" + str(i) + \".png\")\n```\n\u003cimg src=\"https://camo.githubusercontent.com/a9229ef6577001fb21c262e75c472558061ee462/68747470733a2f2f73322e67696679752e636f6d2f696d616765732f416e6472655265666c636e2e676966\" \nalt=\"Image formed by above method\" width=\"240\" height=\"240\" border=\"10\" /\u003e\u003c/a\u003e\n\n\n```python\nfrom pyray.shapes.solid.polyhedron import *\nbasedir = '.\\\\'\ntr = Tetartoid()\nfor i in range(0, 31):\n    im = Image.new(\"RGB\", (2048, 2048), (1,1,1))\n    draw = ImageDraw.Draw(im, 'RGBA')\n    r = general_rotation(np.array([0,1,0]), 2*np.pi*i/30)\n    tr.render_solid_planes(draw, r, shift=np.array([1000, 1000, 0]), scale=750)\n    im.save(basedir + \"im\" + str(i) + \".png\")\n```\n\n\u003ca href=\"https://www.youtube.com/watch?v=0JEFjS2fiTA\u0026feature=youtu.be\" \ntarget=\"_blank\"\u003e\u003cimg src=\"https://github.com/ryu577/ryu577.github.io/blob/master/Downloads/tetartoid2.gif\" \nalt=\"Image formed by above method\" width=\"240\" height=\"240\" border=\"10\" /\u003e\u003c/a\u003e\n\n\n```python\nfrom pyray.shapes.twod.paraboloid import *\ndraw_paraboloids()\n```\n\n\u003ca href=\"https://www.youtube.com/watch?v=acsSIyDugP0\u0026t=53s\" \ntarget=\"_blank\"\u003e\u003cimg src=\"https://github.com/ryu577/ryu577.github.io/blob/master/Downloads/paraboloids.gif\" \nalt=\"Image formed by above method\" width=\"240\" height=\"240\" border=\"10\" /\u003e\u003c/a\u003e\n\n\n\n```python\nfrom pyray.shapes.zerod.pointswarm import *\npoints_to_bins()\n```\n\n\u003ca href=\"https://www.youtube.com/watch?v=OV7c6S32IDU\" \ntarget=\"_blank\"\u003e\u003cimg src=\"https://github.com/ryu577/ryu577.github.io/blob/master/Downloads/classificn/classificn.gif\" \nalt=\"Image formed by above method\" width=\"240\" height=\"240\" border=\"10\" /\u003e\u003c/a\u003e\n\n# Demonstrations\nSo far, I've been using this to create YouTube videos for \u003ca href=\"https://www.youtube.com/channel/UCd2Boc12Ora42VIJBULz0kA\"\u003emy channel\u003c/a\u003e.\n\nHere are some that demonstrate the abilities of this code (also see below for some images created with it) - \n\n1. \u003ca href=\"https://www.youtube.com/watch?v=KuXnrg1YpiY\"\u003eBinomial coefficients on hypercubes.\u003c/a\u003e\n\n2. \u003ca href=\"https://www.youtube.com/watch?v=OV7c6S32IDU\u0026t=3s\"\u003eWhy does Gradient descent work?\u003c/a\u003e\n\n3. \u003ca href=\"https://www.youtube.com/watch?v=STkcP5jcJYo\"\u003eIntroduction to Platonic solids\u003c/a\u003e\n\n4. \u003ca href=\"https://www.youtube.com/watch?v=57g6nQGBFcY\"\u003eSlice a 4d hypercube (Teserract).\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryu577%2Fpyray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryu577%2Fpyray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryu577%2Fpyray/lists"}