GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Basic-Python-Raytracer/scene.py at master · cemrich/Basic-Python-Raytracer

Expand file tree

/

scene.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
65 lines (52 loc) · 1.87 KB
/

scene.py

Copy path

File metadata and controls

65 lines (52 loc) · 1.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
from Tkinter import Tk, Frame, Canvas, PhotoImage, NW
from scene.light import Light
from scene.material import Material, CheckedMaterial, Color
from scene.camera import Camera
from scene.sphere import Sphere
from scene.plane import Plane
from scene.triangle import Triangle
from geometry import Point, Vector
import math
# Konstanten definieren
FIELD_OF_VIEW = math.pi / 4.0 #45 Grad
SCALE = 1 #zum Schnellen Vergrößern/Verkleinern
WIDTH = int(320 * SCALE)
HEIGHT = int(240 * SCALE)
RENDER_LEVEL = 2
# Materialien
planeMat = CheckedMaterial(0.2)
redMat = Material(Color(0.8, 0, 0))
greenMat = Material(Color(0, 0.8, 0))
blueMat = Material(Color(0, 0, 0.8))
triangleMat = Material(Color(1, 1, 0))
# Szenen-Objekte
lightList = [Light(Point(30,30,10), Color(1, 1, 1))]
objectList = [Sphere(Point(2.5,3,-10), 2, redMat),
Sphere(Point(-2.5,3,-10), 2, greenMat),
Sphere(Point(0,7,-10), 2, blueMat),
Triangle(Point(2.5,3,-10), Point(-2.5,3,-10), Point(0,7,-10), triangleMat),
Plane(Point(0,0,0), Vector(0,1,0), planeMat)]
# Renderfunktion - wird pro Pixel aufgerufen
def render_pix(x, y, color):
img.put(color.toValidatedHexString(), (x, HEIGHT-y))
if x%320 == 0:
canvas.update()
# Fenster & Canvas aufbauen
mw = Tk()
mw._root().wm_title("Raytracer")
cFrame = Frame(mw, width=WIDTH, height=HEIGHT)
cFrame.pack()
canvas = Canvas(cFrame, width=WIDTH, height=HEIGHT, bg="white")
# Bild für Pixelunterstützung
img = PhotoImage(width=WIDTH, height=HEIGHT)
canvas.create_image(0, 0, image=img, anchor=NW)
canvas.pack()
# camera initialisieren
camera = Camera(Point(0,2,10), Vector(0,1,0), Point(0,3,0), FIELD_OF_VIEW)
camera.setScreenSize(WIDTH, HEIGHT)
# Anfangen zu Rendern, nachdem Canvas sichtbar ist
mw.wait_visibility()
camera.render(render_pix, objectList, lightList, level=RENDER_LEVEL)
# start
mw.mainloop()
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.