Beispiel #1
0
 def _initcmap(self):
     map = []
     if self.format in ('mono', 'grey4') and self.mustunpack:
         convcolor = conv_grey
     else:
         convcolor = choose_conversion(self.format)
     maxbits = gl.getgdesc(GL.GD_BITS_NORM_SNG_CMODE)
     if maxbits > 11:
         maxbits = 11
     c0bits = self.c0bits
     c1bits = self.c1bits
     c2bits = self.c2bits
     if c0bits + c1bits + c2bits > maxbits:
         if self.fallback and c0bits < maxbits:
             # Cannot display frames in this mode, use grey
             self.skipchrom = 1
             c1bits = c2bits = 0
             convcolor = choose_conversion('grey')
         else:
             raise Error, 'Sorry, '+`maxbits`+ \
               ' bits max on this machine'
     maxc0 = 1 << c0bits
     maxc1 = 1 << c1bits
     maxc2 = 1 << c2bits
     if self.offset == 0 and maxbits == 11:
         offset = 2048
     else:
         offset = self.offset
     if maxbits <> 11:
         offset = offset & ((1 << maxbits) - 1)
     self.color0 = None
     self.fixcolor0 = 0
     for c0 in range(maxc0):
         c0v = c0 / float(maxc0 - 1)
         for c1 in range(maxc1):
             if maxc1 == 1:
                 c1v = 0
             else:
                 c1v = c1 / float(maxc1 - 1)
             for c2 in range(maxc2):
                 if maxc2 == 1:
                     c2v = 0
                 else:
                     c2v = c2 / float(maxc2 - 1)
                 index = offset + c0 + (c1<<c0bits) + \
                  (c2 << (c0bits+c1bits))
                 if index < MAXMAP:
                     rv, gv, bv = \
                       convcolor(c0v, c1v, c2v)
                     r, g, b = int(rv*255.0), \
                        int(gv*255.0), \
                        int(bv*255.0)
                     map.append((index, r, g, b))
                     if self.color0 == None:
                         self.color0 = \
                          index, r, g, b
     self.install_colormap(map)
     # Permanently make the first color index current
     gl.color(self.color0[0])
Beispiel #2
0
	def _initcmap(self):
		map = []
		if self.format in ('mono', 'grey4') and self.mustunpack:
			convcolor = conv_grey
		else:
			convcolor = choose_conversion(self.format)
		maxbits = gl.getgdesc(GL.GD_BITS_NORM_SNG_CMODE)
		if maxbits > 11:
			maxbits = 11
		c0bits = self.c0bits
		c1bits = self.c1bits
		c2bits = self.c2bits
		if c0bits+c1bits+c2bits > maxbits:
			if self.fallback and c0bits < maxbits:
				# Cannot display frames in this mode, use grey
				self.skipchrom = 1
				c1bits = c2bits = 0
				convcolor = choose_conversion('grey')
			else:
				raise Error, 'Sorry, '+`maxbits`+ \
				  ' bits max on this machine'
		maxc0 = 1 << c0bits
		maxc1 = 1 << c1bits
		maxc2 = 1 << c2bits
		if self.offset == 0 and maxbits == 11:
			offset = 2048
		else:
			offset = self.offset
		if maxbits <> 11:
			offset = offset & ((1<<maxbits)-1)
		self.color0 = None
		self.fixcolor0 = 0
		for c0 in range(maxc0):
			c0v = c0/float(maxc0-1)
			for c1 in range(maxc1):
				if maxc1 == 1:
					c1v = 0
				else:
					c1v = c1/float(maxc1-1)
				for c2 in range(maxc2):
					if maxc2 == 1:
						c2v = 0
					else:
						c2v = c2/float(maxc2-1)
					index = offset + c0 + (c1<<c0bits) + \
						(c2 << (c0bits+c1bits))
					if index < MAXMAP:
						rv, gv, bv = \
						  convcolor(c0v, c1v, c2v)
						r, g, b = int(rv*255.0), \
							  int(gv*255.0), \
							  int(bv*255.0)
						map.append(index, r, g, b)
						if self.color0 == None:
							self.color0 = \
								index, r, g, b
		self.install_colormap(map)
		# Permanently make the first color index current
		gl.color(self.color0[0])
Beispiel #3
0
	def _init(self, win):
		self.fg = win._fg
		self.bg = win._bg
		self.font = win._font
		self.size = win._size
		self.width, self.height = win._area[1]
		gl.winset(win._gid)
		gl.color(self.fg)
		return self
Beispiel #4
0
def main():
    gl.foreground()
    gl.prefposition(500, 900, 500, 900)
    w = gl.winopen('CrissCross')
    gl.ortho2(0.0, 400.0, 0.0, 400.0)
    gl.color(GL.WHITE)
    gl.clear()
    gl.color(GL.RED)
    gl.bgnline()
    gl.v2f(0.0, 0.0)
    gl.v2f(400.0, 400.0)
    gl.endline()
    gl.bgnline()
    gl.v2f(400.0, 0.0)
    gl.v2f(0.0, 400.0)
    gl.endline()
    time.sleep(5)
Beispiel #5
0
def main():
    gl.foreground()
    gl.prefposition(500, 900, 500, 900)
    w = gl.winopen('CrissCross')
    gl.ortho2(0.0, 400.0, 0.0, 400.0)
    gl.color(GL.WHITE)
    gl.clear()
    gl.color(GL.RED)
    gl.bgnline()
    gl.v2f(0.0, 0.0)
    gl.v2f(400.0, 400.0)
    gl.endline()
    gl.bgnline()
    gl.v2f(400.0, 0.0)
    gl.v2f(0.0, 400.0)
    gl.endline()
    time.sleep(5)
Beispiel #6
0
def triangle():
    """
    Draws triangles
    """
    r = Render(200, 200)
    r.triangle(
        V2(10, 70), V2(50, 160), V2(70, 80),
        color(random.randint(0, 255), random.randint(0, 255),
              random.randint(0, 255)))
    r.triangle(
        V2(180, 50), V2(150, 1), V2(70, 180),
        color(random.randint(0, 255), random.randint(0, 255),
              random.randint(0, 255)))
    r.triangle(
        V2(180, 150), V2(120, 160), V2(130, 180),
        color(random.randint(0, 255), random.randint(0, 255),
              random.randint(0, 255)))
    r.display('out.bmp')
Beispiel #7
0
def gltest():
    import gl, fm
    gl.foreground()
    W, H = 1000, 800
    gl.prefsize(W, H)
    wid = gl.winopen('gltest')
    gl.ortho2(0, W, H, 0)
    gl.color(7)
    gl.clear()
    gl.color(0)
    fp = openfile()
    TSTART()
    fmt = GLFormatter().init(5, 0, W)
    feedfile(fp, fmt)
    fmt.flush()
    TSTOP()
    import time
    time.sleep(5)
def gltest():
	import gl, fm
	gl.foreground()
	W, H = 1000, 800
	gl.prefsize(W, H)
	wid = gl.winopen('gltest')
	gl.ortho2(0, W, H, 0)
	gl.color(7)
	gl.clear()
	gl.color(0)
	fp = openfile()
	TSTART()
	fmt = GLFormatter().init(5, 0, W)
	feedfile(fp, fmt)
	fmt.flush()
	TSTOP()
	import time
	time.sleep(5)
    def getColor(self, tx, ty, intensity = 1):
        '''Get the color of each pixel from BMP file'''
        
        if tx >= 0 and tx <= 1 and ty >= 0 and ty <= 1:
            x = int(tx * self.width - 1)
            y = int(ty * self.height - 1)

            return self.pixels[y][x]
        else:
            return color(0,0,0)
Beispiel #10
0
def testGL():
	import gl, GL, fmt
	if sys.argv[1:]: file = sys.argv[1]
	else: file = 'test.html'
	data = open(file, 'r').read()
	W, H = 600, 600
	gl.foreground()
	gl.prefsize(W, H)
	wid = gl.winopen('testGL')
	gl.ortho2(0, W, H, 0)
	gl.color(GL.WHITE)
	gl.clear()
	gl.color(GL.BLACK)
	b = fmt.GLBackEnd(wid)
	f = fmt.BaseFormatter(b.d, b)
	p = FormattingParser(f, GLStylesheet)
	p.feed(data)
	p.close()
	b.finish()
	#
	import time
	time.sleep(5)
def testGL():
    import gl, GL, fmt
    if sys.argv[1:]: file = sys.argv[1]
    else: file = 'test.html'
    data = open(file, 'r').read()
    W, H = 600, 600
    gl.foreground()
    gl.prefsize(W, H)
    wid = gl.winopen('testGL')
    gl.ortho2(0, W, H, 0)
    gl.color(GL.WHITE)
    gl.clear()
    gl.color(GL.BLACK)
    b = fmt.GLBackEnd(wid)
    f = fmt.BaseFormatter(b.d, b)
    p = FormattingParser(f, GLStylesheet)
    p.feed(data)
    p.close()
    b.finish()
    #
    import time
    time.sleep(5)
Beispiel #12
0
    def draw(self):
        scale = 1.5e-3
        
        
        gl.lighting( False )
        
        gl.color([0.6, 0.6, 0.6])
        gl.line_width(4)
        if self.am is not None and self.com is not None:
            gl.line( self.com, self.com + scale * 10 * self.am )
        
        gl.color([1., 1., 1.])
        gl.point_size(5.0)
        if self.com is not None:
            gl.points( self.com )

        gl.lighting( True )


        if self.active:
            draw(self.active, self.polygon, self.com, scale)

        gl.line_width(1)
        gl.point_size(1)
def color_static():
    """
    Draws static noise in color
    """
    width = 800
    height = 600
    r = Render(width, height)

    # very inefficient
    for x in range(width):
        for y in range(height):
            r.point(
                x, y,
                color(random.randint(0, 255), random.randint(0, 255),
                      random.randint(0, 255)))

    r.write('out.bmp')
Beispiel #14
0
def draw(active, polygon, com, scale = 1.5e-3 ):
    if len(active) == 0: return

    gl.line_width(2.0)
    gl.lighting( False )

    # (closed) polygon
    gl.color([0, 1, 0] )
    hull = [ active[i][0] for i in polygon ]
    gl.line_strip( hull + [hull[0]] )

    # contact forces
    gl.color([1, 1, 0])
    for (p, f) in active:
        gl.line( p, p + scale * f )

    # a contact point on the ground
    origin = active[0][0]

    # contact wrench at origin
    w = np.zeros( 6 )
    for (p, f) in active:
        w[:3] += f
        w[3:] += np.cross(p - origin, f)

    # cop
    c = origin + cop( w )
        
    gl.color([1, 0, 0])
    gl.line( c, c + scale * w[:3] )

    # com projection
    gl.point_size(4.0)
    gl.color([0, 0.5, 1])
    com_proj = np.copy(com)
    com_proj[1] = origin[1]
    
    gl.points( com_proj )
    
    gl.lighting( True )
    gl.line_width(1.0)
    gl.point_size(1.0)
Beispiel #15
0
    def read(self):
        image = open(self.path, 'rb')
        image.seek(10)
        headerSize = struct.unpack('=l', image.read(4))[0]

        image.seek(14 + 4)
        self.width = struct.unpack('=l', image.read(4))[0]
        self.height = struct.unpack('=l', image.read(4))[0]
        image.seek(headerSize)

        self.pixels = []

        for y in range(self.height):
            self.pixels.append([])
            for x in range(self.width):
                b = ord(image.read(1)) / 255
                g = ord(image.read(1)) / 255
                r = ord(image.read(1)) / 255
                self.pixels[y].append(color(r, g, b))

        image.close()
    def readTexture(self):
        '''Read BMP file, extract the header and pixel values'''

        img = open(self.path, 'rb')
        img.seek(2 + 4 + 4)
        header_size = struct.unpack('=l', img.read(4))[0]
        img.seek(2 + 4 + 4 + 4 + 4)

        self.width = struct.unpack('=l', img.read(4))[0]
        self.height = struct.unpack('=l', img.read(4))[0]
        self.pixels = []

        img.seek(header_size)

        for y in range(self.height):
            self.pixel.append([])
            for x in range(self.width):
                b = ord(img.read(1))
                g = ord(img.read(1))
                r = ord(img.read(1))
                self.pixels[y].append(color(r, g, b))

        img.close()
Beispiel #17
0
    def star(x, y, size):
        """
        Draws a star.
        Size 1: small
        Size 2: medium
        Size 3: big
        """
        c = random.randint(0, 255)
        r.set_color(color(c, c, c)) # 3 identical colors will always be gray

        if size == 1:
            r.point(x, y)
        elif size == 2:  # 4 points
            r.point(x, y)
            r.point(x+1, y)
            r.point(x, y+1)
            r.point(x+1, y+1)
        elif size == 3:  # 9 points
            r.point(x, y)
            r.point(x+1, y)
            r.point(x, y+1)
            r.point(x-1, y)
            r.point(x, y-1)
Beispiel #18
0
        print 'usage: www file'
        sys.exit(2)
    file = sys.argv[1]
    try:
        fp = open(file, 'r')
        data = fp.read()
        fp.close()
    except IOError, msg:
        print file, ':', msg
        sys.exit(1)

    W, H = 600, 600
    gl.foreground()
    gl.prefsize(W, H)
    wid = gl.winopen('glwww')
    gl.color(GL.WHITE)
    gl.clear()
    gl.ortho2(0, W, H, 0)
    gl.color(GL.BLACK)
    T.TSTART()
    fmt = GLFormatter().init(5, 0, W - 5)
    p = html.FormattingParser().init(fmt, GLStylesheet)
    p.feed(data)
    p.close()
    T.TSTOP()
    gl.wintitle(p.title)
    import time
    time.sleep(5)


main()
Beispiel #19
0
def contorno(r):
	#columnas verticales
	r.line((70,200),(70,320),color(203, 67, 53))#izquierda
	r.line((190,130),(190,250),color(203, 67, 53))#medio
	r.line((530,150),(530,270),color(203, 67, 53))#derecha
	#uniones
	r.line((70,320),(190,250),color(203, 67, 53))#izquierda medio superior
	r.line((70,200),(190,130),color(203, 67, 53))#izquierda medio inferior

	r.line((190,130),(530,150),color(203, 67, 53))#medio derecha inferior

	#puerta
	r.line((310,139),(310,235),color(203, 67, 53))#columna izquierda
	r.line((410,144),(410,240),color(203, 67, 53))#columna derecha
	r.line((310,235),(410,240),color(203, 67, 53))#union superior
	r.line((310,138),(410,143),color(255, 255, 255))
	r.line((310,137),(410,142),color(255, 255, 255))
	r.line((310,136),(410,141),color(255, 255, 255))

	#techo
	r.line((70,320),(260,520),color(203, 67, 53))#diagonal izquierda
	r.line((190,250),(380,450),color(203, 67, 53))#diagonal medio izquierdo
	r.line((380,450),(530,270),color(203, 67, 53))#diagonal medio derecha
	r.line((380,450),(260,520),color(203, 67, 53))#diagonal medio superior

	#chimenea
	r.line((310,490),(310,505),color(203, 67, 53))#columna inferior izquierda
	r.line((296,500),(296,515),color(203, 67, 53))#columna superior izquierda
	r.line((296,515),(310,505),color(203, 67, 53))#union anteriores
	r.line((325,483),(325,510),color(203, 67, 53))#columna derecha
	r.line((310,505),(325,510),color(203, 67, 53))#union anterior con izquierda inferior
	r.line((325,510),(311,520),color(203, 67, 53))#union1
	r.line((311,520),(296,515),color(203, 67, 53))#union2
Beispiel #20
0
def pintar_casa(r):
	#cara izquierda
	r.triangle(V2(70,200),V2(70,320),V2(190,130), color(146, 43, 33))
	r.triangle(V2(70,320),V2(190,130),V2(190,250), color(146, 43, 33))
	#techo
	r.triangle(V2(70,320),V2(260,520),V2(190,250), color(192, 57, 43))
	r.triangle(V2(260,520),V2(190,250),V2(380,450),color(192, 57, 43))
	#techo fromtal
	r.triangle(V2(190,250),V2(380,450),V2(530,270),color(169, 50, 38))
	#enfrente
	r.triangle(V2(190,130),V2(190,250),V2(310,139),color(169, 50, 38))
	r.triangle(V2(530,150),V2(530,270),V2(410,144), color(169, 50, 38))
	#--laterales
	r.triangle(V2(310,139),V2(310,335),V2(190,250),color(169, 50, 38))
	r.triangle(V2(410,144),V2(410,340),V2(530,270),color(169, 50, 38))
	#frontal
	r.triangle(V2(310,335),V2(310,235),V2(410,300),color(169, 50, 38))
	r.triangle(V2(410,300),V2(410,240),V2(310,235),color(169, 50, 38))

	#chimenea
	r.triangle(V2(310,490),V2(310,505),V2(296,500),color(146, 43, 33))
	r.triangle(V2(310,505),V2(296,500),V2(296,515),color(146, 43, 33))

	r.triangle(V2(296,500),V2(296,515),V2(325,483),color(169, 50, 38))
	r.triangle(V2(296,515),V2(325,483),V2(325,510),color(169, 50, 38))

	r.triangle(V2(310,505),V2(296,515),V2(325,510),color(192, 57, 43))
	r.triangle(V2(296,515),V2(325,510),V2(311,520),color(192, 57, 43))
Beispiel #21
0
def main():
    # insure that we at least have an X display before continuing.
    import os
    try:
        display = os.environ['DISPLAY']
    except:
        # Raise ImportError because regrtest.py handles it specially.
        raise ImportError, "No $DISPLAY -- skipping gl test"

    # touch all the attributes of gl without doing anything
    if verbose:
        print 'Touching gl module attributes...'
    for attr in glattrs:
        if verbose:
            print 'touching: ', attr
        getattr(gl, attr)

    # create a small 'Crisscross' window
    if verbose:
        print 'Creating a small "CrissCross" window...'
        print 'foreground'
    gl.foreground()
    if verbose:
        print 'prefposition'
    gl.prefposition(500, 900, 500, 900)
    if verbose:
        print 'winopen "CrissCross"'
    w = gl.winopen('CrissCross')
    if verbose:
        print 'clear'
    gl.clear()
    if verbose:
        print 'ortho2'
    gl.ortho2(0.0, 400.0, 0.0, 400.0)
    if verbose:
        print 'color WHITE'
    gl.color(GL.WHITE)
    if verbose:
        print 'color RED'
    gl.color(GL.RED)
    if verbose:
        print 'bgnline'
    gl.bgnline()
    if verbose:
        print 'v2f'
    gl.v2f(0.0, 0.0)
    gl.v2f(400.0, 400.0)
    if verbose:
        print 'endline'
    gl.endline()
    if verbose:
        print 'bgnline'
    gl.bgnline()
    if verbose:
        print 'v2i'
    gl.v2i(400, 0)
    gl.v2i(0, 400)
    if verbose:
        print 'endline'
    gl.endline()
    if verbose:
        print 'Displaying window for 2 seconds...'
    time.sleep(2)
    if verbose:
        print 'winclose'
    gl.winclose(w)
Beispiel #22
0
	def paint(self, ((left, top), (right, bottom))):
		gl.rectf(left, top, right, bottom)
	#
	def box(self, ((left, top), (right, bottom))):
		#print 'box', ((left, top), (right, bottom))
		gl.rect(left, top, right, bottom)
	#
	def circle(self, (h, v), radius):
		gl.circ(h, v, radius)
	#
	def elarc(self, center, (rh, rv), (a1, a2)):
		pass # XXX
	#
	def erase(self, ((left, top), (right, bottom))):
		#print 'erase', ((left, top), (right, bottom))
		gl.color(self.bg)
		gl.rectf(left, top, right, bottom)
		gl.color(self.fg)
	#
	def invert(self, ((left, top), (right, bottom))):
		#print 'invert', ((h0, v0), (h1, v1))
		gl.logicop(LO_XOR)
		gl.color(self.bg)
		gl.rectf(left, top, right, bottom)
		gl.color(self.fg)
		gl.logicop(LO_SRC)
	#
	def line(self, (h0, v0), (h1, v1)):
		#print 'line', ((h0, v0), (h1, v1))
		gl.bgnline()
		gl.v2i(h0, v0)
Beispiel #23
0
#! /usr/bin/env python
Beispiel #24
0
#AndresEmilioQ - 18288
#RT1 Esferas
from gl import color
from aritmetica import *

WHITE = color(1, 1, 1)


class Material(object):
    def __init__(self, diffuse=WHITE):
        self.diffuse = diffuse


class Intersect(object):
    def __init__(self, distance):
        self.distance = distance


class Sphere(object):
    def __init__(self, center, radius, material):
        self.center = center
        self.radius = radius
        self.material = material

    def ray_intersect(self, orig, dir):

        L = sub(self.center, orig)
        tca = dot(L, dir)
        l = magnitud(L)
        d = (l**2 - tca**2)**0.5
        if d > self.radius:
Beispiel #25
0
from gl import Raytracer, color, V2, V3
from obj import Obj, Texture, Envmap
from sphere import *
import random

wall = Material(diffuse=color(0.49, 0.67, 0.48), spec=16)
roof = Material(diffuse=color(0.66, 0.84, 0.67), spec=16)
floor = Material(diffuse=color(0.4, 0.35, 0.35), spec=16)
cubo = Material(diffuse=color(0.4, 0.69, 0.8), spec=32)

width = 500
height = 500
r = Raytracer(width, height)
r.glClearColor(0.2, 0.6, 0.8)
r.glClear()

r.pointLight = PointLight(position=V3(1, 1, 3), intensity=0.75)
r.ambientLight = AmbientLight(strength=0.1)

print('\nThis render gonna be legen—\n')

# cuarto
r.scene.append(Plane(V3(0, -15, 0), V3(0, 1, 0), floor))
r.scene.append(Plane(V3(0, 15, 0), V3(0, -1, 0), roof))
r.scene.append(Plane(V3(-15, 0, 0), V3(1, 0, 0), wall))
r.scene.append(Plane(V3(15, 0, 0), V3(-1, 0, 0), wall))
r.scene.append(Plane(V3(0, 0, -45), V3(0, 0, 1), wall))

# cubos
r.scene.append(AABB(V3(0, -2.1, -10), 1.5, cubo))
r.scene.append(AABB(V3(1.3, 1.8, -7), 0.75, cubo))
Beispiel #26
0
import random

from gl import Raytracer, color
from object import Object, Texture
from sphere import Sphere, Material

r = Raytracer(500, 500)

brick = Material(diffuse=color(0.8, 0.25, 0.25))
stone = Material(diffuse=color(0.4, 0.4, 0.4))
grass = Material(diffuse=color(0.5, 1, 0))

snow = Material(diffuse=color(1, 0.96, 0.96))
orange = Material(diffuse=color(1, 0.65, 0))
coal = Material(diffuse=color(0.2, 0.2, 0.2))
dark = Material(diffuse=color(1, 1, 1))

##  snowman body
r.scene.append(Sphere([0, 2.5, -7], 1, snow))
r.scene.append(Sphere([0, 0.5, -6], 1.3, snow))
r.scene.append(Sphere([0, -2, -8], 2, snow))

##  snowman eyes
r.scene.append(Sphere([0.25, 2.2, -5], 0.07, coal))
r.scene.append(Sphere([-0.25, 2.2, -5], 0.07, coal))

##  snowman nose
r.scene.append(Sphere([0, 1.9, -5], 0.2, orange))

##  snowman mouth
r.scene.append(Sphere([0.25, 1.6, -5], 0.07, stone))
Beispiel #27
0
		print 'usage: www file'
		sys.exit(2)
	file = sys.argv[1]
	try:
		fp = open(file, 'r')
		data = fp.read()
		fp.close()
	except IOError, msg:
		print file, ':', msg
		sys.exit(1)

	W, H = 600, 600
	gl.foreground()
	gl.prefsize(W, H)
	wid = gl.winopen('glwww')
	gl.color(GL.WHITE)
	gl.clear()
	gl.ortho2(0, W, H, 0)
	gl.color(GL.BLACK)
	T.TSTART()
	fmt = GLFormatter().init(5, 0, W-5)
	p = html.FormattingParser().init(fmt, GLStylesheet)
	p.feed(data)
	p.close()
	T.TSTOP()
	gl.wintitle(p.title)
	import time
	time.sleep(5)

main()
Beispiel #28
0
# Andrea Abril Palencia Gutierrez, 18198
# DR2: Light and Shadows --- Graficas por computadora, seccion 20
# 14/09/2020 - 21/09/2020

from gl import Raytracer, color
from obj import Obj, Envmap
from sphere import Sphere, Material, PointLight, AmbientLight, Plane, AABB
import random
from textura import Texture

# materiales
suelo = Material(diffuse=color(0, 1, 0), spec=64)
madera = Material(texture=Texture('madera.bmp'))
grama = Material(texture=Texture('hoja.bmp'))
ladrillo = Material(texture=Texture('piedra.bmp'))
puerta = Material(texture=Texture('puertas.bmp'))

imagen = Raytracer(900, 600)
imagen.envmap = Envmap('cielo-atardecer.bmp')

imagen.pointLight = PointLight(position=(0, 2, 0), intensity=0.5)
imagen.ambientLight = AmbientLight(strength=0.2)

# tierra
imagen.scene.append(Plane((0, -4, 0), (0, 1, 0), suelo))
# arbol 1
# tronco
imagen.scene.append(AABB((-5, -3.5, -7), 1, madera))
imagen.scene.append(AABB((-5, -2.5, -7), 1, madera))
imagen.scene.append(AABB((-5, -1.5, -7), 1, madera))
imagen.scene.append(AABB((-5, -0.5, -7), 1, madera))
Beispiel #29
0
from gl import Raytracer, color, V2, V3
from obj import Obj, Texture, Envmap
from sphere import *
import random

brick = Material(diffuse = color(0.8, 0.25, 0.25 ), spec = 16)
stone = Material(diffuse = color(0.4, 0.4, 0.4 ), spec = 32)
mirror = Material(spec = 64, matType = REFLECTIVE)

glass = Material(spec = 64, ior = 1.5, matType= TRANSPARENT) 


width = 256
height = 256
r = Raytracer(width,height)
r.glClearColor(0.2, 0.6, 0.8)
r.glClear()

r.envmap = Envmap('envmap.bmp')

r.pointLight = PointLight(position = V3(0,0,0), intensity = 1)
r.ambientLight = AmbientLight(strength = 0.1)

#r.scene.append( Sphere(V3( 1, 1, -10), 1.5, brick) )
#r.scene.append( Sphere(V3( 0, -1, -5),  1, glass) )
#r.scene.append( Sphere(V3(-3, 3, -10),  2, mirror) )

r.scene.append( Plane( V3(-2,-3,0), V3(1,1,0), stone))

#r.scene.append( AABB(V3(0, 1.5, -5), 1.5, stone ) )
r.scene.append( AABB(V3(1.5, -1.5, -5), 1.5, mirror ) )
"""
Maria Ines Vasquez Figueroa
18250
Gráficas
DR3 Planes & Cubes
Main
"""

from gl import Raytracer, color
from obj import Obj, Texture, Envmap
from sphere import *

brick = Material(diffuse=color(0.8, 0.25, 0.25), spec=16)
stone = Material(diffuse=color(0.4, 0.4, 0.4), spec=32)
grass = Material(diffuse=color(0.5, 1, 0), spec=32)
glass = Material(diffuse=color(0.25, 1, 1), spec=64)
coal = Material(diffuse=color(0.15, 0.15, 0.15), spec=32)
snow = Material(diffuse=color(1, 1, 1), spec=64)
carrot = Material(diffuse=color(1, 0.54, 0), spec=64)
eyes = Material(diffuse=color(0.90, 0.90, 0.90), spec=64)

pink_center = Material(diffuse=color(0.976, 0.38, 1), spec=64)
pink_bow = Material(diffuse=color(0.984, 0.6, 1), spec=64)
mirror = Material(spec=64, matType=REFLECTIVE)

width = 512
height = 512
r = Raytracer(width, height)
r.glClearColor(0.2, 0.6, 0.8)
r.glClear()
r.envmap = Envmap('envmap.bmp')
Beispiel #31
0
from gl import Raytracer, color, V2, V3
from obj import Obj, Texture
from sphere import Sphere, Material, PointLight, AmbientLight
import random

brick = Material(diffuse=color(0.8, 0.25, 0.25), spec=16)
stone = Material(diffuse=color(0.4, 0.4, 0.4), spec=32)
grass = Material(diffuse=color(0.5, 1, 0), spec=32)
glass = Material(diffuse=color(0.25, 1, 1), spec=64)

width = 256
height = 256
r = Raytracer(width, height)

r.pointLight = PointLight(position=V3(-2, 2, 0), intensity=1)
r.ambientLight = AmbientLight(strength=0.1)

r.scene.append(Sphere(V3(0, 0, -5), 1, brick))
r.scene.append(Sphere(V3(-0.5, 0.5, -3), 0.25, stone))
#r.scene.append( Sphere(V3(-1,-1, -5), 0.5, grass) )
#r.scene.append( Sphere(V3( 1,-1, -5), 0.5, glass) )

r.rtRender()

r.glFinish('output.bmp')
def getevent():
    while 1:
        #
        # Get next event from the processed queue, if any
        #
        if G.queue:
            event = G.queue[0]
            del G.queue[0]
            #print 'getevent from queue -->', event
            return event
        #
        # Get next event from the draw queue, if any,
        # but only if there is nothing in the system queue.
        #
        if G.drawqueue and not gl.qtest():
            win = G.drawqueue[0]
            del G.drawqueue[0]
            gl.winset(win._gid)
            gl.color(win._bg)
            gl.clear()
            event = WE_DRAW, win, win._area
            #print 'getevent from drawqueue -->', event
            return event
        #
        # Get next event from system queue, blocking if necessary
        # until one is available.
        # Some cases immediately return the event, others do nothing
        # or append one or more events to the processed queue.
        #
        dev, val = gl.qread()
        #
        if dev == REDRAW:
            win = G.windowmap[ ` val `]
            old_area = win._area
            win._fixviewport()
            win._needredraw()
            if old_area <> win._area:
                #print 'getevent --> WE_SIZE'
                return WE_SIZE, win, None
        elif dev == KEYBD:
            if val == 3:
                raise KeyboardInterrupt  # Control-C in window
            character = chr(val)
            if commands.has_key(character):
                return WE_COMMAND, G.focus, commands[character]
            return WE_CHAR, G.focus, character
        elif dev == LEFTARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_LEFT
        elif dev == RIGHTARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_RIGHT
        elif dev == UPARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_UP
        elif dev == DOWNARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_DOWN
        elif dev in (LEFTALTKEY, RIGHTALTKEY):
            if val:
                for code in codelist:
                    gl.qdevice(code)
            else:
                for code in codelist:
                    gl.unqdevice(code)
        elif dev in codelist:
            if val:
                event = G.focus._doshortcut(code2key[ ` dev `])
                if event:
                    return event
        elif dev == LEFTMOUSE:
            G.mousex = gl.getvaluator(MOUSEX)
            G.mousey = gl.getvaluator(MOUSEY)
            if val:
                type = WE_MOUSE_DOWN
                gl.qdevice(MOUSEX)
                gl.qdevice(MOUSEY)
            else:
                type = WE_MOUSE_UP
                gl.unqdevice(MOUSEX)
                gl.unqdevice(MOUSEY)
            return _mouseevent(type)
        elif dev == MOUSEX:
            G.mousex = val
            return _mouseevent(WE_MOUSE_MOVE)
        elif dev == MOUSEY:
            G.mousey = val
            return _mouseevent(WE_MOUSE_MOVE)
        elif dev == RIGHTMOUSE:  # Menu button press/release
            if val:  # Press
                event = G.focus._domenu()
                if event:
                    return event
        elif dev == INPUTCHANGE:
            if G.focus:
                G.queue.append(WE_DEACTIVATE, G.focus, None)
            G.focus = G.windowmap[ ` val `]
            if G.focus:
                G.queue.append(WE_ACTIVATE, G.focus, None)
        elif dev in (WINSHUT, WINQUIT):
            return WE_CLOSE, G.windowmap[ ` val `], None
        else:
            print '*** qread() --> dev:', dev, 'val:', val
Beispiel #33
0
from gl import Raytracer, color, V2, V3
from obj import Obj, Texture
from sphere import Sphere, Material, PointLight, AmbientLight
import random

snowman = Material(diffuse=color(1, 1, 1), spec=16)
button = Material(diffuse=color(0, 0, 0), spec=32)
nose = Material(diffuse=color(1, 0.5, 0), spec=64)

width = 960
height = 1280

# width = 240
# height = 320

r = Raytracer(width, height)
r.glClearColor(0.3, 0.5, 0.8)

r.pointLight = PointLight(position=V3(-2, 2, 0), intensity=1)
r.ambientLight = AmbientLight(strength=0.1)

r.glClearColor(0.3, 0.5, 0.8)

print('\nThis render gonna be legen—\n')

r.scene.append(Sphere(V3(0.15, 1.6, -4), 0.05, button))
r.scene.append(Sphere(V3(-0.15, 1.6, -4), 0.05, button))
r.scene.append(Sphere(V3(0, 1.4, -3.9), 0.10, nose))

r.scene.append(Sphere(V3(0.20, 1.25, -4), 0.04, button))
r.scene.append(Sphere(V3(-0.08, 1.20, -4), 0.04, button))
def getevent():
    while 1:
        #
        # Get next event from the processed queue, if any
        #
        if G.queue:
            event = G.queue[0]
            del G.queue[0]
            # print 'getevent from queue -->', event
            return event
            #
            # Get next event from the draw queue, if any,
            # but only if there is nothing in the system queue.
            #
        if G.drawqueue and not gl.qtest():
            win = G.drawqueue[0]
            del G.drawqueue[0]
            gl.winset(win._gid)
            gl.color(win._bg)
            gl.clear()
            event = WE_DRAW, win, win._area
            # print 'getevent from drawqueue -->', event
            return event
            #
            # Get next event from system queue, blocking if necessary
            # until one is available.
            # Some cases immediately return the event, others do nothing
            # or append one or more events to the processed queue.
            #
        dev, val = gl.qread()
        #
        if dev == REDRAW:
            win = G.windowmap[` val `]
            old_area = win._area
            win._fixviewport()
            win._needredraw()
            if old_area <> win._area:
                # print 'getevent --> WE_SIZE'
                return WE_SIZE, win, None
        elif dev == KEYBD:
            if val == 3:
                raise KeyboardInterrupt  # Control-C in window
            character = chr(val)
            if commands.has_key(character):
                return WE_COMMAND, G.focus, commands[character]
            return WE_CHAR, G.focus, character
        elif dev == LEFTARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_LEFT
        elif dev == RIGHTARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_RIGHT
        elif dev == UPARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_UP
        elif dev == DOWNARROWKEY:
            if val:
                return WE_COMMAND, G.focus, WC_DOWN
        elif dev in (LEFTALTKEY, RIGHTALTKEY):
            if val:
                for code in codelist:
                    gl.qdevice(code)
            else:
                for code in codelist:
                    gl.unqdevice(code)
        elif dev in codelist:
            if val:
                event = G.focus._doshortcut(code2key[` dev `])
                if event:
                    return event
        elif dev == LEFTMOUSE:
            G.mousex = gl.getvaluator(MOUSEX)
            G.mousey = gl.getvaluator(MOUSEY)
            if val:
                type = WE_MOUSE_DOWN
                gl.qdevice(MOUSEX)
                gl.qdevice(MOUSEY)
            else:
                type = WE_MOUSE_UP
                gl.unqdevice(MOUSEX)
                gl.unqdevice(MOUSEY)
            return _mouseevent(type)
        elif dev == MOUSEX:
            G.mousex = val
            return _mouseevent(WE_MOUSE_MOVE)
        elif dev == MOUSEY:
            G.mousey = val
            return _mouseevent(WE_MOUSE_MOVE)
        elif dev == RIGHTMOUSE:  # Menu button press/release
            if val:  # Press
                event = G.focus._domenu()
                if event:
                    return event
        elif dev == INPUTCHANGE:
            if G.focus:
                G.queue.append(WE_DEACTIVATE, G.focus, None)
            G.focus = G.windowmap[` val `]
            if G.focus:
                G.queue.append(WE_ACTIVATE, G.focus, None)
        elif dev in (WINSHUT, WINQUIT):
            return WE_CLOSE, G.windowmap[` val `], None
        else:
            print "*** qread() --> dev:", dev, "val:", val
Beispiel #35
0
#! /usr/bin/env python
import numpy as np

from gl import color
from mathGl import MathGl

white = color(1, 1, 1)


class Material(object):
    def __init__(self, diffuse=white):
        self.diffuse = diffuse


class Intersect(object):
    def __init__(self, distance):
        self.distance = distance


class Sphere(object):
    def __init__(self, center, radius, material):
        self.center = center
        self.radius = radius
        self.material = material

        self.mathGl = MathGl()

    def ray_intersect(self, orig, dir):
        L = self.mathGl.subtract(self.center, orig)
        tca = self.mathGl.dot(L, dir)

        l = self.mathGl.norm(L)
def main():
    # insure that we at least have an X display before continuing.
    import os

    try:
        display = os.environ["DISPLAY"]
    except:
        raise TestSkipped, "No $DISPLAY -- skipping gl test"

    # touch all the attributes of gl without doing anything
    if verbose:
        print "Touching gl module attributes..."
    for attr in glattrs:
        if verbose:
            print "touching: ", attr
        getattr(gl, attr)

    # create a small 'Crisscross' window
    if verbose:
        print 'Creating a small "CrissCross" window...'
        print "foreground"
    gl.foreground()
    if verbose:
        print "prefposition"
    gl.prefposition(500, 900, 500, 900)
    if verbose:
        print 'winopen "CrissCross"'
    w = gl.winopen("CrissCross")
    if verbose:
        print "clear"
    gl.clear()
    if verbose:
        print "ortho2"
    gl.ortho2(0.0, 400.0, 0.0, 400.0)
    if verbose:
        print "color WHITE"
    gl.color(GL.WHITE)
    if verbose:
        print "color RED"
    gl.color(GL.RED)
    if verbose:
        print "bgnline"
    gl.bgnline()
    if verbose:
        print "v2f"
    gl.v2f(0.0, 0.0)
    gl.v2f(400.0, 400.0)
    if verbose:
        print "endline"
    gl.endline()
    if verbose:
        print "bgnline"
    gl.bgnline()
    if verbose:
        print "v2i"
    gl.v2i(400, 0)
    gl.v2i(0, 400)
    if verbose:
        print "endline"
    gl.endline()
    if verbose:
        print "Displaying window for 2 seconds..."
    time.sleep(2)
    if verbose:
        print "winclose"
    gl.winclose(w)
Beispiel #38
0
# Classes to read and write CMIF video files.
Beispiel #39
0
def fondo(r):
	x = 0;
	y = 10

	for __ in range(26):
		x=0
		for _ in range(20):
			print('x ',x,y,_,(x+29,y-10),(x+30,y))
			try:
				r.line((x,y),(x+15,y+5),color(0, 0, 0))
				r.line((x,y+20),(x+15,y+15),color(0,0,0))

			except:
				r.line((x,y),(x+15,y+5),color(0, 0, 0))
				r.line((x,y+19),(x+15,y+15),color(0,0,0))
			r.line((x+15,y+5),(x+15,y+15),color(0,0,0))
			try:
				r.line((x+15,y+5),(x+30,y),color(0, 0, 0))
				r.line((x+15,y+15),(x+30,y+20),color(0, 0, 0))
				r.line((x+30,y-10),(x+30,y),color(0,0,0))
				r.line((x+30,780),(x+30,789),color(0,0,0))
			except:
				r.line((x+15,y+4),(x+29,y),color(0, 0, 0))
				r.line((x+15,y+15),(x+29,y+20),color(0, 0, 0))
				r.line((x+29,y-10),(x+29,y),color(0,0,0))
				r.line((x+29,780),(x+29,789),color(0,0,0))

			#print('x ',x, _)
			x+=30
		y+=30
Beispiel #40
0
# Classes to read and write CMIF video files.
Beispiel #41
0
	def setfgcolor(self, color):
		self.fg = color
		gl.color(self.fg)