Skip to content

Latest commit

 

History

History
147 lines (77 loc) · 4.24 KB

README.md

File metadata and controls

147 lines (77 loc) · 4.24 KB

pyRT Examples

For the examples you need "pillow" installed. This can be done using pip. Some examples generate animated gif, for that you need the moviepy module. Please note that moviepy has a lot of dependencies - for example numpy - which are also installed.

pip install Pillow
pip install moviepy

or by running this Python code:

import pip
pip.main(['install', 'Pillow'])
pip.main(['install', 'moviepy'])

Using 'pyrt.image'

The first series of examples is just about images and drawing into them. It is important to understand the concept of an "image generator". While most graphics applications draw something on the screen, in pyRT there is no interactive window displaying anything. Images are for example generated as list of RGB tuples, which are then stored as an image in a common format like PNG.

Drawing Points

00_drawpoints.py

This example creates an image and draws 5000 random points using image.drawPoint(point,color)

Example 01

The image is stored using pillow.

Drawing Lines

01_drawlines.py

This example draws 500 random lines using using image.drawLine(start, end, color). Drawing lines is done using the Bresenham line drawing algorithm.

J. E. Bresenham. 1965. Algorithm for computer control of a digital plotter. IBM Syst. J. 4, 1 (March 1965), 25-30. DOI=http://dx.doi.org/10.1147/sj.41.0025

Example 01

Drawing Koch curve

02_snowflake.py

This example draws a Koch curve using recursion. It is just another example how line drawing can be used.

Example 02

Drawing Circles

03_circle.py

This example draws 100 random circles using image.drawCircle(center, radius, color). Drawing lines is done using the Midpoint circle algorithm.

Example 03

Drawing Rectangles

04_rectangle.py

This example draws 50 random rectangles using image.drawRectangle(bottomleft, width, height, color).

Example 04

Introduction to 3D Math

Drawing a triangle in 3D

05_triangle3d.py

This example shows how a projection matrix and the viewing transformation is used to render a (wireframe) 3D triangle on the image.

Example 05

Drawing an animated triangle in 3D

06_triangle3danim.py

This example generates an animated gif by moving the camera (changing the view matrix). The movie is created using moviepy module which is required to run this example.

Example 06

Raytracing

Create a scene with a triangle

07_raytracingtriangle.py

This example creates a scene with the same triangle like in example 5. Then it renders it using the SimpleRT raytracer.

Example 07

Raytrace triangle with different vertex colors

08_raytracingtriangle_colorvertex.py

This example adds a triangle with different vertex colors to the scene.

Example 08

Multiple triangles

09_multiple_triangles.py

This example renders two triangles

Example 09

Rendering a sphere

10_sphere.py

This example renders a sphere

Example 10

Rendering a sphere with a light

11_sphere_light.py

This example renders a sphere with a light

Example 11

Rendering a small scene with shadow

12_smallscene.py 12b_animated_scene.py

This example renders 4 spheres on ground (2 triangles). The second version (12b) animates the light source and generates a gif.

Example 12 Example 12b

Adding reflections

This example uses the scene from example 11. It changes the material of the spheres to supoprt reflections.

13_reflections.py 13_reflections.py

Example 13