p3he/draw.py

33 lines
995 B
Python

from cmath import exp
from constants import *
from gyro import *
from lines import *
class DrawnSegment:
def __init__(self,height,color):
self.height = height
self.color = color
def draw(level,gPlayer,fov,res):
drawn = list()
irot = exp(fov/res*I)
iprot = gPlayer.cRot
for i in range(res):
m = DrawnSegment(0,BLACK)
rot = irot**(i-(res/2)) * iprot
for j in level:
try: # Function "LineIntersection" faults from time to time
cInt = MobiusInt(j.pointA,j.pointB,gPlayer.cPos,rot)
except ZeroDivisionError:
continue
if cDot(rot,MobiusAdd(cInt,-gPlayer.cPos)) > 0:
continue
rDist = MobiusDist(cInt,gPlayer.cPos)*1.1
if not (j.isFinite and cBetween(j.pointA,j.pointB,cInt)):
continue
if (1 - m.height) > rDist:
m = DrawnSegment(1-rDist,j.color)
drawn.append(m)
return drawn