rtx.py

Created by chick-chicky

Created on January 14, 2024

1.68 KB


from math import *

class Vec:
    def __init__(self,x,y,z):
        self.x,self.y,self.z = x,y,z
    def __add__(self,o):
        return Vec(self.x+o.x,self.y+o.y,self.z+o.y)
    def __sub__(self,o):
        return Vec(self.x-o.x,self.y-o.y,self.z-o.y)
    def __mul__(self,o):
        return Vec(self.x*o.x,self.y*o.y,self.z*o.y)
    def __truediv__(self,o):
        return Vec(self.x/o.x,self.y/o.y,self.z/o.y)
    def mag(self):
        return sqrt(self.x*self.x+self.y*self.y+self.z*self.z)
    def dst(self,o):
        return sqrt((self.x-o.x)**2+(self.y-o.y)**2+(self.z*o.z)**2)
    def norm(self):
        l = sqrt(self.x*self.x+self.y*self.y+self.z*self.z)
        return Vec(self.x/l,self.y/l,self.z/l)
    def clone(self):
        return Vec(self.x,self.y,self.z)

class Color:
    def __init__(self,r,g,b,a):
        self.r,self.g,self.b,self.a=r,g,b,a
    def __add__(self,o):
        return Color(self.r+o.r,self.g+o.g,self.b+o.b,self.a+o.a)
    def __sub__(self,o):
        return Color(self.r-o.r,self.g-o.g,self.b-o.b,self.a-o.a)
    def __mul__(self,o):
        return Color(self.r*o.r,self.g*o.g,self.b*o.b,self.a*o.a)
    def __truediv__(self,o):
        return Color(self.r/o.r,self.g/o.g,self.b/o.b,self.a/o.a)

def v(n): return Vec(n,n,n)
def c(n): return Color(n,n,n,n)
def d(n): return Color(n,n,n,1)

class Sphere:
    def __init__(self,pos,radius,color):
        self.p,self.r,self.c=pos,radius,color
    def inside(self,p):
        return sqrt((self.pos.x-p.x)**2+(self.pos.y-p.y)**2+(self.pos.z*p.z)**2) < self.r
    
camp = Vec(0,0,0)
cams = 5.0
caml = 2.0

res = 100.0,100.0
prec = 1
maxr = 10

shapes = [Sphere(Vec(0,0,2),1,Color(1,0,0,1))]

shadows = False
reflections = False

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.