Example #1
0
	def run(self):
		while self.trace is None and not self.die:
			time.sleep(0.1)

		if self.die:
			return

		if ol.init(4) < 0:
			return
		print "OL Initialized"
		params = ol.RenderParams()
		params.render_flags = ol.RENDER_GRAYSCALE
		params.on_speed = 2/120.0
		params.off_speed = 2/30.0
		params.flatness = 0.000001
		params.max_framelen = 48000 / 25
		params.min_length = 30
		params.snap = 0.04
		ol.setRenderParams(params)
		ol.loadIdentity()
		ol.scale((2, -2))
		ol.translate((-0.5, -0.5))
		ol.scale((1/640.0, 1/640.0))
		ol.translate((0, (640-480)/2))

		while not self.die:
			#ol.rect((100, 100), (640-100, 480-100), ol.C_WHITE)
			objects = self.trace
			for o in objects:
				ol.begin(ol.POINTS)
				for point in o[::2]:
					ol.vertex(point, ol.C_WHITE)
				ol.end()
			ftime = ol.renderFrame(60)
		ol.shutdown()
Example #2
0
	def draw(self):
		"""
		Draw the bullet shape
		"""
                #print ("drawing bullet")

		pts = []
		pts.append({'x': 0, 'y': 0})
		pts.append({'x': self.length*math.cos(self.shotAngle),
					'y': self.length*math.sin(self.shotAngle)})

		"""
		# Rotate points
		for p in pts:
			x = p['x']
			y = p['y']
			p['x'] = x*math.cos(self.theta) - y*math.sin(self.theta)
			p['y'] = y*math.cos(self.theta) + x*math.sin(self.theta)
		"""

		# Translate points
		for pt in pts:
			pt['x'] += self.x
			pt['y'] += self.y

                ol.begin(ol.LINESTRIP)
                for i in range(len(pts)):
                        ol.vertex((pts[i]['x'], pts[i]['y']), ol.C_WHITE)
                ol.end()

		self.drawn = True
Example #3
0
 def square(self,x1,y1,x2,y2):
     ol.begin(ol.LINESTRIP)
     ol.vertex((x1,y1))
     ol.vertex((x1,y2))
     ol.vertex((x2,y2))        
     ol.vertex((x2,y1))        
     ol.vertex((x1,y1))        
     ol.end()
Example #4
0
def play_ugo(size, frames, meta):
    frame_pts = []
    total_time = 0
    for frame_meta in meta['frames']:
        frame_pts.append(total_time)
        total_time += frame_meta['delay'] / 1000.0

    if ol.init(3) < 0:
        return

    width, height = size

    params = ol.RenderParams()
    params.render_flags = ol.RENDER_GRAYSCALE
    params.on_speed = 2 / 60.0
    params.off_speed = 2 / 30.0
    params.flatness = 0.000001
    params.max_framelen = 48000 / 25
    params.min_length = 30
    params.snap = 0.04
    ol.setRenderParams(params)
    ol.loadIdentity()
    ol.scale((2, -2))
    ol.translate((-0.5, -0.5))
    mw = float(max(width, height))
    print width, height, mw
    ol.scale((1 / mw, 1 / mw))
    ol.translate(((mw - width) / 2, (mw - height) / 2))

    frame = 0
    time = 0

    DECIMATE = 2

    while True:
        while time > total_time:
            time -= total_time
            frame = 0

        while (frame + 1) < len(frames) and frame_pts[frame + 1] < time:
            frame += 1

        print "t=%.02f frame=%d" % (time, frame)

        objects = frames[frame]
        points = 0
        for o in objects:
            ol.begin(ol.POINTS)
            for point in o[::DECIMATE]:
                ol.vertex(point, ol.C_WHITE)
                points += 1
            ol.end()
        print "%d objects, %d points" % (len(objects), points)
        time += ol.renderFrame(60)

    ol.shutdown()
Example #5
0
def play_ugo(size, frames, meta):
    frame_pts = []
    total_time = 0
    for frame_meta in meta['frames']:
        frame_pts.append(total_time)
        total_time += frame_meta['delay'] / 1000.0

    if ol.init(3) < 0:
        return

    width, height = size

    params = ol.RenderParams()
    params.render_flags = ol.RENDER_GRAYSCALE
    params.on_speed = 2/60.0
    params.off_speed = 2/30.0
    params.flatness = 0.000001
    params.max_framelen = 48000 / 25
    params.min_length = 30
    params.snap = 0.04
    ol.setRenderParams(params)
    ol.loadIdentity()
    ol.scale((2, -2))
    ol.translate((-0.5, -0.5))
    mw = float(max(width, height))
    print width, height, mw
    ol.scale((1/mw, 1/mw))
    ol.translate(((mw-width)/2, (mw-height)/2))

    frame = 0
    time = 0

    DECIMATE = 2

    while True:
        while time > total_time:
            time -= total_time
            frame = 0

        while (frame+1) < len(frames) and frame_pts[frame+1] < time:
            frame += 1

        print "t=%.02f frame=%d" % (time, frame)

        objects = frames[frame]
        points = 0
        for o in objects:
            ol.begin(ol.POINTS)
            for point in o[::DECIMATE]:
                ol.vertex(point, ol.C_WHITE)
                points += 1
            ol.end()
        print "%d objects, %d points" % (len(objects), points)
        time += ol.renderFrame(60)

    ol.shutdown()
Example #6
0
    def draw(self):
        ol.loadIdentity()
        ol.rotate(lux.time / 10)

        # Grab the raw audio buffer
        mono = audio_engine.mono_buffer()

        # Make sure it ain't empty!!
        if mono.shape[0] == 0:
            return

        # Openlase can only draw 30000 points in one cycle (less that
        # that, actually!).  Clear the audio buffer and try again!
        if mono.shape[0] > 10000:
            audio_engine.clear_all()

        ol.color3(*(self.color_cycle()))
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        if (lux.time > self.nextSnapshot):
            #print "snapshot"
            self.nextSnapshot = lux.time + self.interval
            self.currentWave = self.nextWave
            self.nextWave = zeros(shape=(self.renderPointCount))
            # load in new values
            for i in range(int(self.renderPointCount - 1)):
                self.nextWave[i] = mono[i * self.skip] * 2

        # draw shape
        fracIntervalComplete = (
            lux.time - (self.nextSnapshot - self.interval)) / self.interval
        #        print '%f %f %f' % (lux.time,fracIntervalComplete, self.nextSnapshot)
        coordsToRender = zeros(shape=(self.renderPointCount, 2))
        firstVal = None
        for i in range(int(self.renderPointCount - 1)):
            val = ((self.nextWave[i] - self.currentWave[i]) *
                   fracIntervalComplete) + self.currentWave[i]
            if (firstVal is None): firstVal = val
            #print "next: %f  curr:  %f   frac: %f" % (self.nextWave[i], self.currentWave[i], fracIntervalComplete)
            (x, y) = self.doTheTrigStuff(
                val, (float(i) / float(self.renderPointCount)), firstVal)
            coordsToRender[i][0] = x
            coordsToRender[i][1] = y
        coordsToRender[self.renderPointCount - 1] = coordsToRender[0]

        # render shape
        ol.begin(ol.LINESTRIP)
        for i in range(0, int(self.renderPointCount), 1):
            #            print '%f: %f,%f' % (i,coordsToRender[i][0], coordsToRender[i][1])
            ol.vertex((coordsToRender[i][0], coordsToRender[i][1]))
        ol.end()
        ol.vertex((coordsToRender[0][0], coordsToRender[0][1]))
Example #7
0
    def draw(self):
        ol.loadIdentity()

        ol.rotate(lux.time / 10)

        # Grab the raw audio buffer
        mono = audio_engine.mono_buffer()

        # Make sure it ain't empty!!
        if mono.shape[0] == 0:
            return

        # Openlase can only draw 30000 points in one cycle (less that
        # that, actually!).  Clear the audio buffer and try again!
        if mono.shape[0] > 10000:
            audio_engine.clear_all()
            return

        ol.color3(*(self.color_cycle()))
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        if lux.time > self.nextSnapshot:
            # print "snapshot"
            self.nextSnapshot = lux.time + self.interval
            self.currentWave = self.nextWave
            self.nextWave = zeros(shape=(self.renderPointCount))
            # load in new values
            for i in range(self.renderPointCount - 1):
                self.nextWave[i] = mono[i * self.skip]

        # draw shape
        fracIntervalComplete = (lux.time - (self.nextSnapshot - self.interval)) / self.interval
        #        print '%f %f %f' % (lux.time,fracIntervalComplete, self.nextSnapshot)
        coordsToRender = zeros(shape=(self.renderPointCount, 2))
        firstVal = None
        for i in range(self.renderPointCount - 1):
            val = ((self.nextWave[i] - self.currentWave[i]) * fracIntervalComplete) + self.currentWave[i]
            if firstVal is None:
                firstVal = val
            # print "next: %f  curr:  %f   frac: %f" % (self.nextWave[i], self.currentWave[i], fracIntervalComplete)
            (x, y) = self.doTheTrigStuff(val, (float(i) / float(self.renderPointCount)), firstVal)
            coordsToRender[i][0] = x
            coordsToRender[i][1] = y
        coordsToRender[self.renderPointCount - 1] = coordsToRender[0]

        # render shape
        ol.begin(ol.LINESTRIP)
        for i in range(self.renderPointCount):
            #            print '%f: %f,%f' % (i,coordsToRender[i][0], coordsToRender[i][1])
            ol.vertex((coordsToRender[i][0], coordsToRender[i][1]))
        ol.end()
Example #8
0
	def draw(self):
		"""
		Draw the healthbar shape.
		"""
		# Generate points
                #print ("drawing healthbar")
                
		full = self.radius/2

		hPerc = self.health/float(HealthBar.HEALTH_MAX)
		ihPerc = 1.0 - hPerc
		green = full * hPerc
		red = full * (1.0 - hPerc)

		y = 0.01
		xShift = 0.01

		pts = []
		pts.append({'x': full + xShift, 'y': y})
		pts.append({'x': -full*2 + full*3*ihPerc + xShift, 'y': y})

		# RED
                """
		pts.append({'x': full - full*3 + xShift, 'y': y})
		pts.append({'x': -full*2 + xShift, 'y': y})
                """
		#pts.append({'x': -full*2, 'y': full})
		#pts.append({'x': -full*2, 'y': full})

		# Translate points
		for pt in pts:
			pt['x'] += self.x
			pt['y'] += self.y

		# DRAW THE SHAPE

                ol.begin(ol.LINESTRIP)
                for i in range(len(pts)):
                        ol.vertex((pts[i]['x'], pts[i]['y']), ol.C_WHITE)
                ol.end()

		self.drawn = True
Example #9
0
	def draw(self):
		"""
		Draw the asteroid shape
		"""
		# Generate points
                #print "drawing asteroid"
		ed = self.radius
                #print "asteroid radius = ", ed

                pts = []
		for pt in self.points:
                        pts.append(pt[:])
                #print pts
		#pts.append([ ed, ed])
		#pts.append([-ed, ed])
		#pts.append([-ed, -ed])
		#pts.append([ ed, -ed])
                #pts.append([ ed, ed])

		# Rotate points
		for p in pts:
			x = p[0]
			y = p[1]
			p[0] = x*math.cos(self.theta) - y*math.sin(self.theta)
			p[1] = y*math.cos(self.theta) + x*math.sin(self.theta)

		# Translate points
                #print "asteroid x,y = ", self.x, self.y
		for pt in pts:
                        #print pt
                	pt[0] += self.x
			pt[1] += self.y
                        #print pt

                ol.begin(ol.LINESTRIP)
                for p in pts:
                        ol.vertex(tuple(p), ol.C_WHITE)
                ol.end()

		self.drawn = True
Example #10
0
	def draw(self):
		"""
		Draw the ship shape.
		"""
		# Generate points
                #print "drawing ship"
		ed = self.radius/2
                #print "ed = ", ed
		pts = []
		pts.append([ed, ed])
		#pts.append([-ed, ed])

		pts.append([-ed-ed*2, 0])

		#pts.append([-ed, -ed])
		pts.append([ed, -ed])
                pts.append([ed/2, 0])
                pts.append([ed, ed])

		# Rotate points
		for p in pts:
			x = p[0]
			y = p[1]
			p[0] = x*math.cos(self.theta) - y*math.sin(self.theta)
			p[1] = y*math.cos(self.theta) + x*math.sin(self.theta)

		# Translate points
		for pt in pts:
			pt[0] += self.x
			pt[1] += self.y

                ol.begin(ol.LINESTRIP)
                for i in range(5):
                        for p in pts:
                                #print p
                                ol.vertex(tuple(p), ol.C_WHITE)
                ol.end()

		self.drawn = True
Example #11
0
    def draw(self):
        ol.loadIdentity()

        ol.color3(1.0, 1.0, 1.0);

        # bounding box
        ol.begin(ol.LINESTRIP)
        self.square(1,1,-1,-1)
        ol.end()
        
        # horizontal line
        ol.begin(ol.LINESTRIP)
        ol.vertex((-1,0))
        ol.vertex((1,0))        
        ol.end()

        # vertical line
        ol.begin(ol.LINESTRIP)
        ol.vertex((0,-1))
        ol.vertex((0,1))        
        ol.end()

        # inner box, for fun
        ol.color3(0.0, 1.0, 0.0);
        size = (sin(lux.time) * .2)+.5
        ol.begin(ol.LINESTRIP)
        self.square(size,size,-size,-size)
        ol.end()

        # Red dots
        ol.loadIdentity()
        ol.loadIdentity3()

        ol.begin(ol.LINESTRIP)
        for y in range(0, 20):
            ol.color3(float(y)/20.0, 0.0, 0.0);
            ol.vertex3((-0.6, (float(y-10) / 12.0), -1.0))
        ol.end()

        # Green dots
        ol.begin(ol.LINESTRIP)
        for y in range(0, 20):
            ol.color3(0.0, float(y)/20.0, 0.0);
            ol.vertex3((-0.4, (float(y-10) / 12.0), -1.0))
        ol.end()

        # Blue dots
        ol.begin(ol.LINESTRIP)
        for y in range(0, 20):
            ol.color3(0.0, 0.0, float(y)/20.0);
            ol.vertex3((-0.2, (float(y-10) / 12.0), -1.0))
        ol.end()

        # vertical line
        ol.begin(ol.LINESTRIP)
        ol.vertex((0,-1))
        ol.vertex((0,1))        
        ol.end()
Example #12
0
    def draw(self):
        ol.loadIdentity()

        ol.color3(1.0, 1.0, 1.0)

        # bounding box
        ol.begin(ol.LINESTRIP)
        self.square(1, 1, -1, -1)
        ol.end()

        # horizontal line
        ol.begin(ol.LINESTRIP)
        ol.vertex((-1, 0))
        ol.vertex((1, 0))
        ol.end()

        # vertical line
        ol.begin(ol.LINESTRIP)
        ol.vertex((0, -1))
        ol.vertex((0, 1))
        ol.end()

        # inner box, for fun
        ol.color3(0.0, 1.0, 0.0)
        size = (sin(lux.time) * .2) + .5
        ol.begin(ol.LINESTRIP)
        self.square(size, size, -size, -size)
        ol.end()

        # Red dots
        ol.loadIdentity()
        ol.loadIdentity3()

        ol.begin(ol.LINESTRIP)
        for y in range(0, 20):
            ol.color3(float(y) / 20.0, 0.0, 0.0)
            ol.vertex3((-0.6, (float(y - 10) / 12.0), -1.0))
        ol.end()

        # Green dots
        ol.begin(ol.LINESTRIP)
        for y in range(0, 20):
            ol.color3(0.0,
                      float(y) / 20.0, 0.0)
            ol.vertex3((-0.4, (float(y - 10) / 12.0), -1.0))
        ol.end()

        # Blue dots
        ol.begin(ol.LINESTRIP)
        for y in range(0, 20):
            ol.color3(0.0, 0.0,
                      float(y) / 20.0)
            ol.vertex3((-0.2, (float(y - 10) / 12.0), -1.0))
        ol.end()

        # vertical line
        ol.begin(ol.LINESTRIP)
        ol.vertex((0, -1))
        ol.vertex((0, 1))
        ol.end()
Example #13
0
                renderFrame = True
                openPath = False
                ol.loadIdentity()
                ol.scale((1.0/32768, 1.0/32768))
                ol.translate((0, 0))
                if banner != "":
                    ol.drawString(font, (-w/2,yoff), fsize, ol.C_GREEN, banner)
            continue

        if is_number(tokens[0]):
            if renderFrame:
                x = float(tokens[0])
                y = float(tokens[1])
                palette_i = int(tokens[2])
    
                if not openPath:
                    ol.begin(0)
                    openPath = True
                elif palette_i < 0:
                    ol.end()
                    ol.begin(0)
                    openPath = True

                ol.vertex((x,y),ol.C_RED)
            continue
    
    render_frame()

ol.shutdown()