示例#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()
示例#2
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.loadIdentity3()
        ol.perspective(20, 1, 1, 100)
        ol.translate3((0, 0, -20))

        ol.color3(1.0,1.0,0.0);
        ol.translate3( (cos(lux.time/2.0), cos(lux.time/3.0), cos(lux.time/7.0)) )
        ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
        ol.rotate3X(lux.time * pi * 0.25 * lux.simple_rate)
        ol.rotate3Y(lux.time * pi * 0.13 * lux.simple_rate)
        

        for row in self.torender:
            ol.begin(ol.LINESTRIP)
            vi = self.faces[row]
            vi = vi + [vi[0]]

            for i in vi:
                tup = tuple(self.verts[i,:])
                ol.vertex3(tup)
            
            ol.end()
示例#3
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        # Grab the raw audio buffers
        mono = audio_engine.left_buffer()
#        mono = np.zeros(512)

        # Make sure they aren'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.loadIdentity3()
        ol.color3(*(self.color_cycle()))

        ol.begin(ol.LINESTRIP)
        for i in range(0, mono.shape[0]-1, self.subsamp):
            scale_factor = pow(0.9-abs(self.x_coord),0.5)*2
            if (mono[i] <= -1.0):
                mono[i] = 1.0
            ol.vertex3((self.x_coord, tanh(mono[i]*scale_factor), -1))
#            ol.vertex3((self.x_coord, log(mono[i]*scale_factor+1.0), -1))
            self.x_coord = self.x_coord + self.step
            if (self.x_coord > 0.9) : self.x_coord = -0.9
        ol.end()
示例#4
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()
示例#5
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        #set basic coord system
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -40))

        ol.color3(0.0, 0.0, 1.0)
        ol.scale3((1., 1., 1.))

        #for i in range(10):
        #    x = random()*40-20
        #    y = random()*40-20
        #x = randint(-20,20)
        #y = randint(-20,20)
        #    square(x,y,.1)

        # truly randomly sampled by image vals
        #for i in range(20):
        #    x,y,val = rndlena()
        #    ol.color3(0.0,0.0,val/255.)
        #    square(x*40./SIZEX-20,y*40/SIZEY-20,.1)

        #totally random, weighted by image value
        for i in range(20):
            x = randint(0, SIZEX - 1)
            y = randint(0, SIZEY - 1)
            #val = lena.getpixel((x,y))
            #val = 1.-exp(-.5*lenadat[x*SIZEX+y]/255.)
            val = lenadat[x * SIZEX + y] / 255. * .77
            ol.color3(0.0, 0.0, val)
            square(x * 40. / SIZEX - 20, y * 40 / SIZEY - 20, .05)
示例#6
0
    def draw(self, target=None):
        for particle in reversed(self.tail):
            # draw connecting lines
            if particle.follow:
                new_x, new_y = particle.follow.x, particle.follow.y
                if draw_links:
                    ol.color3(1, 0, 1)  # magenta links
                    ol.loadIdentity3()
                    ol.loadIdentity()
                    ol.begin(ol.LINESTRIP)
                    ol.vertex3((particle.x, particle.y, 0))
                    ol.vertex3((particle.follow.x, particle.follow.y, 0))
                    ol.end()
            else:
                if target: new_x, new_y = target[0], target[1]
                else:
                    new_x, new_y = math.cos(3 * lux.time), math.sin(2 *
                                                                    lux.time)
                #new_x, new_y = self.mouse_x, self.mouse_y
            particle.draw('blah')

            if abs(particle.x - new_x) > 0.01 or abs(particle.y -
                                                     new_y) > 0.01:
                self.tweener.add_tween(particle, x=new_x, y=new_y, duration=0.6, \
                    easing=pytweener.Easing.Cubic.ease_out, on_complete=particle.finish, on_update=particle.draw)
示例#7
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.loadIdentity3()
        ol.perspective(20, 1, 1, 100)
        ol.translate3((0, 0, -20))

        ol.color3(1.0, 1.0, 0.0)
        ol.translate3(
            (cos(lux.time / 2.0), cos(lux.time / 3.0), cos(lux.time / 7.0)))
        ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
        ol.rotate3X(lux.time * pi * 0.25 * lux.simple_rate)
        ol.rotate3Y(lux.time * pi * 0.13 * lux.simple_rate)

        for row in self.torender:
            ol.begin(ol.LINESTRIP)
            vi = self.faces[row]
            vi = vi + [vi[0]]

            for i in vi:
                tup = tuple(self.verts[i, :])
                ol.vertex3(tup)

            ol.end()
示例#8
0
    def draw(self):

        self.x_phase = 0.4*cos(1.7 * lux.time * self.RATE) + 0.6*cos(0.7 * lux.time * self.RATE)
        self.y_phase = cos(2.2 * lux.time * self.RATE)
        self.z_phase = cos(5.7 * lux.time * self.RATE)
        self.z_ratio = 2 + cos(0.1 * lux.time * self.RATE)

        ol.loadIdentity3()
        ol.loadIdentity()

        ol.perspective(20, 1, 1, 100)
        ol.translate3((0, 0, -10))
        ol.scale3((0.5, 0.5, 0.5))

        ol.rotate3Z(lux.time * pi * 0.01)
        ol.rotate3X(lux.time * pi * 0.025)
        ol.rotate3Y(lux.time * pi * 0.013)

        ol.color3(*(self.color_cycle()))

        ol.begin(ol.POINTS)
        decay_factor = 1
        first_point = None
        for i in range(self.SAMPLES_PER_FRAME):
            theta = float(i) / self.SAMPLES_PER_FRAME * self.MAX_THETA
            x = sin(self.x_ratio * theta + self.x_phase)
            y = sin(self.y_ratio * theta + self.y_phase)
            z = sin(self.z_ratio * theta + self.z_phase)
            if (i == 0):
                first_point = (x * decay_factor, y * decay_factor, z * decay_factor)
            ol.vertex3((x * decay_factor, y * decay_factor, z * decay_factor))
            decay_factor = decay_factor * self.decay
        ol.vertex3(first_point)
        ol.end()
示例#9
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        # set basic coord system
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -40))

        ol.color3(0.0, 0.0, 1.0)
        ol.scale3((1.0, 1.0, 1.0))

        # for i in range(10):
        #    x = random()*40-20
        #    y = random()*40-20
        # x = randint(-20,20)
        # y = randint(-20,20)
        #    square(x,y,.1)

        # truly randomly sampled by image vals
        # for i in range(20):
        #    x,y,val = rndlena()
        #    ol.color3(0.0,0.0,val/255.)
        #    square(x*40./SIZEX-20,y*40/SIZEY-20,.1)

        # totally random, weighted by image value
        for i in range(20):
            x = randint(0, SIZEX - 1)
            y = randint(0, SIZEY - 1)
            # val = lena.getpixel((x,y))
            # val = 1.-exp(-.5*lenadat[x*SIZEX+y]/255.)
            val = lenadat[x * SIZEX + y] / 255.0 * 0.77
            ol.color3(0.0, 0.0, val)
            square(x * 40.0 / SIZEX - 20, y * 40 / SIZEY - 20, 0.05)
示例#10
0
    def draw(self):

        self.x_phase = 0.4*cos(1.7 * lux.time * self.RATE) + 0.6*cos(0.7 * lux.time * self.RATE)
        self.y_phase = cos(2.2 * lux.time * self.RATE)
        self.z_phase = cos(5.7 * lux.time * self.RATE)
        self.z_ratio = 2 + cos(0.1 * lux.time * self.RATE)

        ol.loadIdentity3()
        ol.loadIdentity()

        ol.perspective(20, 1, 1, 100)
        ol.translate3((0, 0, -10))
        #ol.scale3((0.5, 0.5, 0.5))

        ol.rotate3Z(lux.time * pi * 0.01)
        ol.rotate3X(lux.time * pi * 0.025)
        ol.rotate3Y(lux.time * pi * 0.013)

        ol.color3(*(self.color_cycle()))

        ol.begin(ol.POINTS)
        decay_factor = 1
        first_point = None
        for i in range(self.SAMPLES_PER_FRAME):
            theta = float(i) / self.SAMPLES_PER_FRAME * self.MAX_THETA
            x = sin(self.x_ratio * theta + self.x_phase)
            y = sin(self.y_ratio * theta + self.y_phase)
            z = sin(self.z_ratio * theta + self.z_phase)
            if (i == 0):
                first_point = (x * decay_factor, y * decay_factor, z * decay_factor)
            ol.vertex3((x * decay_factor, y * decay_factor, z * decay_factor))
            decay_factor = decay_factor * self.decay
        ol.vertex3(first_point)
        ol.end()
示例#11
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        ol.color3(1.0, 1.0, 1.0)

        offset = cos(lux.time * 10)
        ol.begin(ol.LINESTRIP)
        npts = 25
        #ol.scale3((0.5,0.5,0.5))
        for i in range(npts):
            ol.color3(
                float(i) / npts, 1.0 - float(i) / npts,
                (float(i) / npts + (1.0 - float(i) / npts)) / 2.0)
            offset = 0
            mod = (i % 2 * 2.0 - 1.0) * 0.99
            #ol.scale3((mod, mod, mod))
            ol.rotate3Z(lux.time * pi * 0.01 * lux.simple_rate)
            ol.vertex3((float(i) / (npts / 2.0) - 1.0 + offset, -1.0, -1))
            ol.vertex3((float(i) / (npts / 2.0) - 1.0 + offset, 1.0, -1))

        ol.end()
示例#12
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        # Grab the raw audio buffers
        newbuffer = audio_engine.mono_buffer()

        # Make sure they aren't empty!!
        if (len(newbuffer) == 0):
            return
        else:
            self.mono = newbuffer

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

        ol.loadIdentity3()
        ol.color3(*(self.color_cycle()))

        ol.begin(ol.POINTS)
        for i in range(0, self.mono.shape[0]-1, self.SUBSAMP):

            val = tanh(self.mono[i] * self.BOOST)
            val = val * 0.5 + 0.5
            val = val * (self.MAX_SIZE - self.MIN_SIZE) + self.MIN_SIZE
            
            ol.vertex3((cos(self.pos) * val, sin(self.pos) * val, -1))
            
            self.pos = self.pos + self.W / 30000.0;
            while(self.pos >= 2*pi):
                self.pos = self.pos -2*pi
        ol.end()
示例#13
0
    def draw(self):
        time = lux.time
        #time = self.time
        ctf = self.color_time_frequency
        clf = self.color_length_frequency
        caf = self.color_angle_frequency/2
        theta = abs(math.sin(time*self.time_scale))
        R = self.R * math.sin(2*pi*time*self.time_scale*self.R_frequency)
        r = self.r * math.sin(2*pi*time*self.time_scale*self.r_frequency)
        p = self.p * math.sin(2*pi*time*self.time_scale*self.p_frequency) * self.bass

        ol.color3(1.0, 0.0, 1.0);
        ol.loadIdentity3()
        ol.loadIdentity()
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))
        
        first = True
        n = 0
        while theta < 2*pi*self.max_cycles and n < self.max_segments:
            theta += self.theta_step
            #x = (R + r) * math.cos(theta)
            #y = (R + r) * math.sin(theta)
            x = (R + r) * math.cos(theta) + (r + p) * math.cos((R+r)/r * theta)
            y = (R + r) * math.sin(theta) + (r + p) * math.sin((R+r)/r * theta)
            
            if first:
                ol.begin(ol.LINESTRIP)
                #ol.begin(ol.POINTS)
                first = False
            #red = math.sin(ctf*time*n/37) * math.sin(csf*theta*n/37)
            #green = math.sin(ctf*time*n/23) * math.sin(csf*theta*n/23)
            #blue = math.sin(ctf*time*n/128) * math.sin(csf*theta*n/128)
            
            angle = math.atan2(y, x)/(2*pi)
            red   = abs(math.sin(2*pi*(self.r_prime/3+ctf*time+clf*n+caf*angle)))
            green = abs(math.sin(2*pi*(self.g_prime/3+ctf*time+clf*n+caf*angle)))
            blue =  abs(math.sin(2*pi*(self.b_prime/3+ctf*time+clf*n+caf*angle)))
            ol.color3(red, green, blue)
            
            #this makes it square-ish
            #x += math.cos(2*pi*angle*self.spatial_resonance)*self.spatial_resonance_amplitude
            #y += math.sin(2*pi*angle*self.spatial_resonance)*self.spatial_resonance_amplitude
            x += math.cos(2*pi*angle*(self.spatial_resonance+1)+2*pi*self.spatial_resonance_offset)*self.spatial_resonance_amplitude
            y += math.sin(2*pi*angle*(self.spatial_resonance+1)+2*pi*self.spatial_resonance_offset)*self.spatial_resonance_amplitude


            x *= self.width
            y *= self.height
            ol.vertex3((x,y,0))
            n += 1
        ol.end()
        #dynamically adjust resolution
        target = self.max_segments * 0.8
        error = (target - n)/target
        self.theta_step = min(max(1e-100, self.theta_step * (1-error)), 1)
        #print n,  angle
        self.time += 1/30
示例#14
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()
示例#15
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()
示例#16
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()
示例#17
0
def draw_frame():
        global DRAW, frame_number

        #print "drawing frame ", frame_number
        frame_number = frame_number + 1
        
        ol.loadIdentity()
        #ol.scale((MAX_X, MAX_Y))
        DRAW.draw()
        ol.renderFrame(50)
示例#18
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()
        ol.color3(0.0, 1.0, 1.0);
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        #target_x, target_y = random.uniform(-1, 1), random.uniform(-1, 1)
        target_x, target_y = math.sin(2*pi*swoosh_frequency*lux.time*3), math.sin(2*pi*swoosh_frequency*lux.time*5)
        #target_x, target_y = math.tan(2*pi*swoosh_frequency*lux.time*3), math.sin(2*pi*swoosh_frequency*lux.time*5)
        for arm in self.arms: arm.draw([target_x, target_y])
示例#19
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]))
示例#20
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()
示例#21
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.color3(1.0, 0.0, 1.0);
        font = ol.getDefaultFont()
        s = "Lux!"
        w = ol.getStringWidth(font, 0.2, s)
        ol.drawString(font, (-w/2,0.1), 0.2, s)

        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        for i in range(2):

            if (i == 1):
                ol.color3(1.0,1.0,0.0);
            else:
                ol.color3(0.0,1.0,1.0);
                    
            ol.scale3((0.6, 0.6, 0.6))
            ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
            ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
            ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)
            
            ol.begin(ol.LINESTRIP)
            ol.vertex3((-1, -1, -1))
            ol.vertex3(( 1, -1, -1))
            ol.vertex3(( 1,  1, -1))
            ol.vertex3((-1,  1, -1))
            ol.vertex3((-1, -1, -1))
            ol.vertex3((-1, -1,  1))
            ol.end()

            ol.begin(ol.LINESTRIP);
            ol.vertex3(( 1,  1,  1))
            ol.vertex3((-1,  1,  1))
            ol.vertex3((-1, -1,  1))
            ol.vertex3(( 1, -1,  1))
            ol.vertex3(( 1,  1,  1))
            ol.vertex3(( 1,  1, -1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3(( 1, -1, -1))
            ol.vertex3(( 1, -1,  1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3((-1,  1,  1))
            ol.vertex3((-1,  1, -1))
            ol.end()
示例#22
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        for i in range(2):
            ol.loadIdentity3()
            ol.perspective(20, 1, 1, 100)
            ol.translate3((0, 0, -20))

            if (i == 1):
                ol.color3(1.0, 1.0, 0.0)
                ol.translate3((cos(lux.time / 2.0), cos(lux.time / 3.0),
                               cos(lux.time / 7.0)))
                ol.rotate3Z(lux.time * pi * 0.1 * lux.TwoCubes_simple_rate)
                ol.rotate3X(lux.time * pi * 0.25 * lux.TwoCubes_simple_rate)
                ol.rotate3Y(lux.time * pi * 0.13 * lux.TwoCubes_simple_rate)
            else:
                ol.color3(0.0, 1.0, 1.0)
                ol.scale3((0.6, 0.6, 0.6))
                ol.translate3((cos(lux.time / 3.2), cos(lux.time / 2.6),
                               cos(lux.time / 5.4)))
                ol.rotate3Z(lux.time * pi * 0.14 * lux.TwoCubes_simple_rate)
                ol.rotate3X(lux.time * pi * 0.53 * lux.TwoCubes_simple_rate)
                ol.rotate3Y(lux.time * pi * 0.22 * lux.TwoCubes_simple_rate)

            ol.begin(ol.LINESTRIP)
            ol.vertex3((-1, -1, -1))
            ol.vertex3((1, -1, -1))
            ol.vertex3((1, 1, -1))
            ol.vertex3((-1, 1, -1))
            ol.vertex3((-1, -1, -1))
            ol.vertex3((-1, -1, 1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3((1, 1, 1))
            ol.vertex3((-1, 1, 1))
            ol.vertex3((-1, -1, 1))
            ol.vertex3((1, -1, 1))
            ol.vertex3((1, 1, 1))
            ol.vertex3((1, 1, -1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3((1, -1, -1))
            ol.vertex3((1, -1, 1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3((-1, 1, 1))
            ol.vertex3((-1, 1, -1))
            ol.end()
示例#23
0
	def run(self):
		ol.init()
		params = ol.RenderParams()
		params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
		ol.setRenderParams(params)

		while not self.die:
			ol.loadIdentity()
			for x,y in self.dots:
				ol.dot((x,y), 30, ol.C_WHITE)

			ol.renderFrame(100)
		ol.shutdown()
示例#24
0
    def run(self):
        ol.init()
        params = ol.RenderParams()
        params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
        ol.setRenderParams(params)

        while not self.die:
            ol.loadIdentity()
            for x, y in self.dots:
                ol.dot((x, y), 30, ol.C_WHITE)

            ol.renderFrame(100)
        ol.shutdown()
示例#25
0
    def draw(self):
        '''a square'''
        #self.x = math.cos(2*pi*rotate_frequency*lux.time + self.angle + self.base_angle) * self.distance * self.distance_scale
        #self.y = math.sin(2*pi*rotate_frequency*lux.time + self.angle + self.base_angle) * self.distance * self.distance_scale
        
        #stolen from guilloche
        time = lux.time * time_scale 
        R = math.sin(2*pi*self.R_frequency*time) * self.R + 0.0001
        r = math.sin(2*pi*self.r_frequency*time) * self.r + 0.0001
        p = math.sin(2*pi*self.p_frequency*time) * self.p + 0.0001
        self.x = (R + r) * math.cos(time) + (r + p) * math.cos((R+r)/r * time) 
        self.y = (R + r) * math.sin(time) + (r + p) * math.sin((R+r)/r * time) 
        
        #clamp to display area
        if clamp_display:
            if self.x > 1: self.x = 1
            if self.y > 1: self.y = 1
            if self.x < -1: self.x = -1
            if self.y < -1: self.y = -1
        self.x *= scale
        self.y *= scale
        #self.graphics.circle(0, 0, self.radius)
        ol.loadIdentity3()
        ol.loadIdentity()


        #ol.color3(self.color[0], self.color[1], self.color[2])
        ol.color3(self.red, self.green, self.blue)
        ol.translate3((self.x, self.y, 0))
        angle = math.atan2(self.y, self.x)/(2*pi)
        red   = abs(math.sin(2*pi*(r_prime/3+ctf*time+clf*self.n+caf*angle)))*self.red
        green = abs(math.sin(2*pi*(g_prime/3+ctf*time+clf*self.n+caf*angle)))*self.green
        blue =  abs(math.sin(2*pi*(b_prime/3+ctf*time+clf*self.n+caf*angle)))*self.blue
        if seizure_mode:
          #red, green, blue = red/self.radius, green/self.radius, blue/self.radius
          red = abs(red*math.tan((2*pi*self.radius/node_big_radius)))
          green = abs(green*math.tan((2*pi*self.radius/node_big_radius)))
          blue = abs(blue*math.tan((2*pi*self.radius/node_big_radius)))
        
        ol.color3(red, green, blue)
 
        #do squares have radii?
        s = self.radius
        ol.begin(ol.POINTS)
        ol.vertex3((-s, s,0))
        ol.vertex3((-s, s,0))
        ol.vertex3(( s, s,0))
        ol.vertex3(( s,-s,0))
        ol.vertex3((-s,-s,0))
        ol.end()
示例#26
0
文件: tweet.py 项目: marcan/openlase
	def run(self):
		if ol.init(10) < 0:
			return
		params = ol.RenderParams()
		params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
		params.on_speed = 2/120.0
		params.off_speed = 2/30.0
		params.flatness = 0.000001
		ol.setRenderParams(params)
		ol.setPixelShader(self.shade)
		time = 0
		frames = 0
		cur_tweets = self.tweets
		xpos = 0
		idx = 0
		startpos = 1.3
		while not self.die:
			ol.loadIdentity3()
			ol.loadIdentity()

			if cur_tweets is None and self.tweets is not None:
				cur_tweets = self.tweets
				idx = 0
				xpos = startpos

			w = 0
			#print cur_tweets
			if cur_tweets is not None:
				font = ol.getDefaultFont()
				w = ol.getStringWidth(font, 0.4, cur_tweets[idx])
				col = ol.C_WHITE
				#print "Render %f %s 0x%x"%(xpos, cur_tweets[idx], col)
				ol.drawString(font, (xpos,0.1), 0.4, col, cur_tweets[idx])
	
			#print "render"
			ftime = ol.renderFrame(60)
			#print "done"
			xpos -= 0.6*ftime
			if xpos < (-w-1) and cur_tweets is not None:
				xpos = startpos
				idx += 1
				idx %= len(cur_tweets)
				if self.tweets != cur_tweets:
					idx = 0
					cur_tweets = self.tweets
					print("Reset and update")
				print("Finished, new idx: %d"%idx)
			frames += 1
			time += ftime
		ol.shutdown()
示例#27
0
文件: tweet.py 项目: sgnls/openlase
    def run(self):
        if ol.init(10) < 0:
            return
        params = ol.RenderParams()
        params.render_flags = ol.RENDER_NOREORDER | ol.RENDER_GRAYSCALE
        params.on_speed = 2 / 120.0
        params.off_speed = 2 / 30.0
        params.flatness = 0.000001
        ol.setRenderParams(params)
        ol.setPixelShader(self.shade)
        time = 0
        frames = 0
        cur_tweets = self.tweets
        xpos = 0
        idx = 0
        startpos = 1.3
        while not self.die:
            ol.loadIdentity3()
            ol.loadIdentity()

            if cur_tweets is None and self.tweets is not None:
                cur_tweets = self.tweets
                idx = 0
                xpos = startpos

            w = 0
            #print cur_tweets
            if cur_tweets is not None:
                font = ol.getDefaultFont()
                w = ol.getStringWidth(font, 0.4, cur_tweets[idx])
                col = ol.C_WHITE
                #print "Render %f %s 0x%x"%(xpos, cur_tweets[idx], col)
                ol.drawString(font, (xpos, 0.1), 0.4, col, cur_tweets[idx])

            #print "render"
            ftime = ol.renderFrame(60)
            #print "done"
            xpos -= 0.6 * ftime
            if xpos < (-w - 1) and cur_tweets is not None:
                xpos = startpos
                idx += 1
                idx %= len(cur_tweets)
                if self.tweets != cur_tweets:
                    idx = 0
                    cur_tweets = self.tweets
                    print("Reset and update")
                print("Finished, new idx: %d" % idx)
            frames += 1
            time += ftime
        ol.shutdown()
示例#28
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        for i in range(2):
            ol.loadIdentity3()
            ol.perspective(20, 1, 1, 100)
            ol.translate3((0, 0, -20))

            if (i == 1):
                ol.color3(1.0,1.0,0.0);
                ol.translate3((cos(lux.time/2.0), cos(lux.time/3.0), cos(lux.time/7.0)))
                ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
                ol.rotate3X(lux.time * pi * 0.25 * lux.simple_rate)
                ol.rotate3Y(lux.time * pi * 0.13 * lux.simple_rate)
            else:
                ol.color3(0.0,1.0,1.0);
                ol.scale3((0.6, 0.6, 0.6))
                ol.translate3((cos(lux.time/3.2), cos(lux.time/2.6), cos(lux.time/5.4)))
                ol.rotate3Z(lux.time * pi * 0.14 * lux.simple_rate)
                ol.rotate3X(lux.time * pi * 0.53 * lux.simple_rate)
                ol.rotate3Y(lux.time * pi * 0.22 * lux.simple_rate)
            
            ol.begin(ol.LINESTRIP)
            ol.vertex3((-1, -1, -1))
            ol.vertex3(( 1, -1, -1))
            ol.vertex3(( 1,  1, -1))
            ol.vertex3((-1,  1, -1))
            ol.vertex3((-1, -1, -1))
            ol.vertex3((-1, -1,  1))
            ol.end()

            ol.begin(ol.LINESTRIP);
            ol.vertex3(( 1,  1,  1))
            ol.vertex3((-1,  1,  1))
            ol.vertex3((-1, -1,  1))
            ol.vertex3(( 1, -1,  1))
            ol.vertex3(( 1,  1,  1))
            ol.vertex3(( 1,  1, -1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3(( 1, -1, -1))
            ol.vertex3(( 1, -1,  1))
            ol.end()

            ol.begin(ol.LINESTRIP)
            ol.vertex3((-1,  1,  1))
            ol.vertex3((-1,  1, -1))
            ol.end()
示例#29
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()
        ol.color3(0.0, 1.0, 1.0)
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        # target_x, target_y = random.uniform(-1, 1), random.uniform(-1, 1)
        target_x, target_y = (
            math.sin(2 * pi * swoosh_frequency * lux.time * 3),
            math.sin(2 * pi * swoosh_frequency * lux.time * 5),
        )
        # target_x, target_y = math.tan(2*pi*swoosh_frequency*lux.time*3), math.sin(2*pi*swoosh_frequency*lux.time*5)
        for arm in self.arms:
            arm.draw([target_x, target_y])
示例#30
0
    def draw(self, val):
        '''a square'''
        ol.loadIdentity3()
        ol.loadIdentity()
        ol.color3(self.color[0], self.color[1], self.color[2])
        ol.translate3((self.x, self.y, 0))
        ol.begin(ol.POINTS)
        ol.vertex3((.0, .0, .0))
        ol.vertex3((.0, .1, .0))
        ol.vertex3((.1, .1, .0))
        ol.vertex3((.1, .0, .0))
        ol.vertex3((.0, .0, .0))
        ol.end()

        self.moving = True
        return self
示例#31
0
  def draw(self, val):
    '''a square'''
    ol.loadIdentity3()
    ol.loadIdentity()
    ol.color3(self.color[0], self.color[1], self.color[2])
    ol.translate3((self.x, self.y, 0))
    ol.begin(ol.POINTS)
    ol.vertex3((.0,.0,.0))
    ol.vertex3((.0,.1,.0))
    ol.vertex3((.1,.1,.0))
    ol.vertex3((.1,.0,.0))
    ol.vertex3((.0,.0,.0))
    ol.end()

    self.moving = True
    return self
示例#32
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        #        dt = lux.time - self.last_time

        self.net.draw()
        foo = self.tweener.update(lux.time * time_scale - self.last_time)

        #print list(foo)
        #bar = list(foo)[0]

        ol.color3(1.0, 1.0, 1.0)
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        self.last_time = lux.time * time_scale
示例#33
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()
        
#        dt = lux.time - self.last_time

        self.net.draw()
        foo= self.tweener.update(lux.time*time_scale - self.last_time)
        
        #print list(foo)
        #bar = list(foo)[0]

        ol.color3(1.0, 1.0, 1.0);
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        self.last_time = lux.time * time_scale
示例#34
0
    def draw(self):
        time = lux.time
        ctf = self.color_time_frequency
        clf = self.color_length_frequency
        caf = self.color_angle_frequency/2
        theta0 = abs(math.sin(time*self.time_scale))

        
        for braid_count in range(1,self.NUM_CIRCLES):
            first = True
            n = 0
            theta = theta0
            
            ol.color3(1.0, 0.0, 1.0);
            ol.loadIdentity3()
            ol.loadIdentity()
            ol.perspective(40, 1, 1, 100)
            ol.translate3((0, 0, -3))
            ol.rotate3Z(lux.time * pi * self.z_rotations[braid_count])
            ol.rotate3X(lux.time * pi * self.x_rotations[braid_count])
            ol.rotate3Z(lux.time * pi * self.x_rotations[braid_count])

            ol.begin(ol.LINESTRIP)
            while theta < theta0 + 2*pi:

                r = (0.5+sin(10*theta)/2.0) / float(braid_count) * self.scale
                x = r * cos(theta)
                y = r * sin(theta)

                angle = math.atan2(y, x)/(2*pi)
                red   = abs(math.sin(2*pi*(self.r_prime/3+ctf*time+clf*n+caf*angle)+self.color_phases[braid_count]))
                green = abs(math.sin(2*pi*(self.g_prime/3+ctf*time+clf*n+caf*angle)+self.color_phases[braid_count]))
                blue =  abs(math.sin(2*pi*(self.b_prime/3+ctf*time+clf*n+caf*angle)+self.color_phases[braid_count]))
                ol.color3(red, green, blue)
                ol.vertex3((x,y,0))
                n += 1

                theta += 1.0/float(self.max_segments)

            r = (0.5+sin(10*theta)/2.0) / float(braid_count) * self.scale
            x = r * cos(theta)
            y = r * sin(theta)
            ol.vertex3((x,y,0))  # Close the path
            ol.end()
示例#35
0
    def draw(self):

        a = self.alpha * cos(lux.time / 10.0 * self.RATE)
        b = self.beta * sin(lux.time / 7.0 * self.RATE) + 10
        c = self.gamma * cos(lux.time / 11.0 * self.RATE)
        A = self.rho

        ol.loadIdentity3()
        ol.loadIdentity()
        ol.rotate3Z(lux.time * pi * 0.03)
        ol.color3(*(self.color_cycle()))

        ol.begin(ol.LINESTRIP)
        for i in range(self.SAMPLES_PER_FRAME):
            theta = float(i) / self.SAMPLES_PER_FRAME * self.MAX_THETA
            r = exp(cos(a * theta)) - A * cos(b*theta) + pow(abs(sin(theta/c)),b)
            r = r / (2.7 - A + pow(1,b)) * self.overall_amplitude

            ol.vertex3((r * cos(theta), r * sin(theta), -1))
        ol.end()
示例#36
0
    def draw(self):
        self.tweener.add_tween(self, scale_factor=0.25, time_scale = 1.0, duration=0.1, \
                               easing=pytweener.Easing.Expo.ease_in_out)

        ol.loadIdentity()
        ol.loadIdentity3()
        ol.translate3((-0.1, 0.0, 0.0))
        ol.scale3((self.scale_factor, self.scale_factor, self.scale_factor))

        # Spawn photons randomly
        if len(self.photons) < MAX_PHOTONS and random.random(
        ) < SPAWN_THRESHOLD:
            p = Photon()
            self.photons.append(p)

        # Draw photons
        dt = self.time_scale * (lux.time - self.last_time)
        self.last_time = lux.time
        self.tweener.update(lux.time - self.last_time)

        for p in self.photons:
            p.update(dt, self.photon_speed)
            p.draw()

        ol.color3(1.0, 1.0, 1.0)
        font = ol.getDefaultFont()
        s = "LASER"
        w = ol.getStringWidth(font, 1.0, s)
        ol.drawString(font, (-w / 2, 1.1), 1.0, s)

        # Draw the bounding box, with a very small hole in it.
        ol.color3(0.0, 1.0, 0.0)
        ol.begin(ol.LINESTRIP)
        ol.vertex3((CAVITY_SIZE[0] / 2, 0.1, 0.0))
        ol.vertex3((CAVITY_SIZE[0] / 2, CAVITY_SIZE[1] / 2, 0.0))
        ol.vertex3((-CAVITY_SIZE[0] / 2, CAVITY_SIZE[1] / 2, 0.0))
        ol.vertex3((-CAVITY_SIZE[0] / 2, -CAVITY_SIZE[1] / 2, 0.0))
        ol.vertex3((CAVITY_SIZE[0] / 2, -CAVITY_SIZE[1] / 2, 0.0))
        ol.vertex3((CAVITY_SIZE[0] / 2, -0.1, 0.0))
        ol.end()
示例#37
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        #set basic coord system
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -40))

        ol.color3(0.0,0.0,1.0);
        ol.scale3((1., 1., 1.))

        #for i in range(10):
        #    x = random()*40-20
        #    y = random()*40-20
            #x = randint(-20,20)
            #y = randint(-20,20)
        #    square(x,y,.1)

        #lux.time()
        #sleep(0.1)

        #for i in range(20):
        #    x,y,val = rndlena()
        #    ol.color3(0.0,0.0,val/255.)
        #    square(x*40./SIZEX-20,y*40/SIZEY-20,.1)
        
        #ol.color3(1.0,0.0,0.)        
        #square(10*.4-20,10*.4-20,.1)

        self.ROW+=3
        if self.ROW >= SIZEY:
            self.ROW=self.phase
            self.phase += 1
            if self.phase == 3: self.phase=0
        j=self.ROW
        
        for i in range(SIZEX):
            ol.color3(0.0,0.0,lena.getpixel((i,j))/255.)
            square(i*40./SIZEX-20.,j*40./SIZEY-20.,.1)
                
示例#38
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        # Grab the raw audio buffers
        mono = audio_engine.left_buffer()
        #        mono = np.zeros(512)

        # Make sure they aren'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.loadIdentity3()
        ol.color3(*(self.color_cycle()))

        count = 0
        while count < mono.shape[0]:

            ol.begin(ol.LINESTRIP)
            while self.x_coord < 1.0 and count < mono.shape[0]:

                scale_factor = pow(1.0 - abs(self.x_coord), 0.5) * 2
                #ol.vertex3((self.x_coord, mono[count]*scale_factor, -1))             # Linear
                ol.vertex3((self.x_coord, tanh(mono[count] * scale_factor),
                            -1))  # Tanh
                #ol.vertex3((self.x_coord, log(mono[count]*scale_factor+1.0), -1))    # Sigmoid

                self.x_coord += self.step
                count = count + self.subsamp
            ol.end()

            if self.x_coord >= 1.0:
                self.x_coord = -1.0

        ol.end()
示例#39
0
    def draw(self):
        self.tweener.add_tween(self, scale_factor=0.25, time_scale = 1.0, duration=0.1, \
                               easing=pytweener.Easing.Expo.ease_in_out)

        
        ol.loadIdentity()
        ol.loadIdentity3()
        ol.translate3((-0.1, 0.0, 0.0))
        ol.scale3((self.scale_factor, self.scale_factor, self.scale_factor))

        # Spawn photons randomly
        if len(self.photons) < MAX_PHOTONS and random.random() < SPAWN_THRESHOLD:
            p = Photon();
            self.photons.append(p)

        # Draw photons
        dt = self.time_scale * (lux.time - self.last_time)
        self.last_time = lux.time
        self.tweener.update(lux.time - self.last_time)
        
        for p in self.photons:
            p.update(dt, self.photon_speed)
            p.draw()

        ol.color3(1.0, 1.0, 1.0);
        font = ol.getDefaultFont()
        s = "LASER"
        w = ol.getStringWidth(font, 1.0, s)
        ol.drawString(font, (-w/2,1.1), 1.0, s)

        # Draw the bounding box, with a very small hole in it.
        ol.color3(0.0, 1.0, 0.0);
        ol.begin(ol.LINESTRIP)
        ol.vertex3(( CAVITY_SIZE[0]/2,  0.1, 0.0))
        ol.vertex3(( CAVITY_SIZE[0]/2,  CAVITY_SIZE[1]/2, 0.0))
        ol.vertex3((-CAVITY_SIZE[0]/2,  CAVITY_SIZE[1]/2, 0.0))
        ol.vertex3((-CAVITY_SIZE[0]/2, -CAVITY_SIZE[1]/2, 0.0))
        ol.vertex3(( CAVITY_SIZE[0]/2, -CAVITY_SIZE[1]/2, 0.0))
        ol.vertex3(( CAVITY_SIZE[0]/2,  -0.1, 0.0))
        ol.end()
示例#40
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()
        
        if not self.particle.moving and self.particle.wait > 0.5:
          self.particle.wait = 0
          self.bounce()

#        dt = lux.time - self.last_time
        self.particle.wait += lux.time - self.last_time

        self.chain.draw(target=(self.particle.x, self.particle.y))
        foo= self.tweener.update(lux.time - self.last_time)
        
        #print list(foo)
        #bar = list(foo)[0]

        ol.color3(1.0, 1.0, 1.0);
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        self.last_time = lux.time
示例#41
0
  def draw(self, target = None):
    for particle in reversed(self.tail):
        # draw connecting lines
        if particle.follow:
            new_x, new_y = particle.follow.x, particle.follow.y
            if draw_links:
                ol.color3(1,0,1) # magenta links
                ol.loadIdentity3()
                ol.loadIdentity()
                ol.begin(ol.LINESTRIP)
                ol.vertex3((particle.x, particle.y, 0))
                ol.vertex3((particle.follow.x, particle.follow.y, 0))
                ol.end()
        else:
            if target: new_x, new_y = target[0], target[1]
            else: new_x, new_y = math.cos(3*lux.time), math.sin(2*lux.time)
            #new_x, new_y = self.mouse_x, self.mouse_y
        particle.draw('blah')

        if abs(particle.x - new_x) > 0.01 or abs(particle.y - new_y) > 0.01:
            self.tweener.add_tween(particle, x=new_x, y=new_y, duration=0.6, \
                easing=pytweener.Easing.Cubic.ease_out, on_complete=particle.finish, on_update=particle.draw)
示例#42
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        # Grab the raw audio buffers
        mono = audio_engine.left_buffer()
#        mono = np.zeros(512)

        # Make sure they aren'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.loadIdentity3()
        ol.color3(*(self.color_cycle()))

        count = 0
        while count < mono.shape[0]:

            ol.begin(ol.LINESTRIP)
            while self.x_coord < 1.0 and count < mono.shape[0]:

                scale_factor = pow(1.0-abs(self.x_coord),0.5)*2
                #ol.vertex3((self.x_coord, mono[count]*scale_factor, -1))             # Linear
                ol.vertex3((self.x_coord, tanh(mono[count]*scale_factor), -1))        # Tanh
                #ol.vertex3((self.x_coord, log(mono[count]*scale_factor+1.0), -1))    # Sigmoid
                
                self.x_coord += self.step
                count = count + self.subsamp
            ol.end()

            if self.x_coord >= 1.0:
                self.x_coord = -1.0
                
        ol.end()
示例#43
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        if not self.particle.moving and self.particle.wait > 0.5:
            self.particle.wait = 0
            self.bounce()

#        dt = lux.time - self.last_time
        self.particle.wait += lux.time - self.last_time

        self.chain.draw(target=(self.particle.x, self.particle.y))
        foo = self.tweener.update(lux.time - self.last_time)

        #print list(foo)
        #bar = list(foo)[0]

        ol.color3(1.0, 1.0, 1.0)
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        self.last_time = lux.time
示例#44
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        ol.color3(1.0,1.0,1.0)

        offset = cos(lux.time*10)
        ol.begin(ol.LINESTRIP)
        npts = 25
        #ol.scale3((0.5,0.5,0.5))
        for i in range(npts):
            ol.color3(float(i)/npts,1.0-float(i)/npts,(float(i)/npts+(1.0-float(i)/npts))/2.0)
            offset = 0
            mod = (i%2 * 2.0 - 1.0) * 0.99
            #ol.scale3((mod, mod, mod))
            ol.rotate3Z(lux.time * pi * 0.01 * lux.simple_rate)
            ol.vertex3((float(i)/(npts/2.0)-1.0+offset,-1.0,-1))
            ol.vertex3((float(i)/(npts/2.0)-1.0+offset,1.0,-1))

        ol.end()
示例#45
0
    def draw(self):
        try:
            a = self.alpha * cos(lux.time / 10.0 * self.RATE)
            b = self.beta * sin(lux.time / 7.0 * self.RATE) + 10
            c = self.gamma * cos(lux.time / 11.0 * self.RATE)
            A = self.rho

            ol.loadIdentity3()
            ol.loadIdentity()
            ol.rotate3Z(lux.time * pi * 0.03)
            ol.color3(*(self.color_cycle()))

            ol.begin(ol.LINESTRIP)
            for i in range(self.SAMPLES_PER_FRAME):
                theta = float(i) / self.SAMPLES_PER_FRAME * self.MAX_THETA
                r = exp(cos(a * theta)) - A * cos(b * theta) + pow(
                    abs(sin(theta / c)), b)
                r = r / (2.7 - A + pow(1, b)) * self.overall_amplitude

                ol.vertex3((self.SCALE * r * cos(theta),
                            self.SCALE * r * sin(theta), -1))
            ol.end()
        except ValueError:
            pass  # Occasinal math hiccups can be safely ignored
示例#46
0
    def draw(self):

        self.i = self.i + 1.0

        #inverse persistence length
        self.thetad = 0.25 * (1.0 + sin(2.0 * pi * self.i / 2000.0))

        #RGB curliness offset
        offset = pi / 6.0

        #RGB curly-straight cycle frequency
        crlstrt = 0.005

        #RGB maximum curlyness
        curlmx = 0.2

        theta0B = curlmx * cos(self.i * crlstrt)
        theta0R = curlmx * cos(self.i * crlstrt + offset)
        theta0G = curlmx * cos(self.i * crlstrt + 2.0 * offset)

        self.thetaB = self.thetaB + random.gauss(theta0B, self.thetad)
        self.thetaR = self.thetaR + random.gauss(theta0R, self.thetad)
        self.thetaG = self.thetaG + random.gauss(theta0G, self.thetad)

        self.BX = np.append(self.BX[1:],
                            self.BX[-1] + self.dr * cos(self.thetaB))
        self.BY = np.append(self.BY[1:],
                            self.BY[-1] + self.dr * sin(self.thetaB))

        self.RX = np.append(self.RX[1:],
                            self.RX[-1] + self.dr * cos(self.thetaR))
        self.RY = np.append(self.RY[1:],
                            self.RY[-1] + self.dr * sin(self.thetaR))

        self.GX = np.append(self.GX[1:],
                            self.GX[-1] + self.dr * cos(self.thetaG))
        self.GY = np.append(self.GY[1:],
                            self.GY[-1] + self.dr * sin(self.thetaG))

        # derivative roughness parameter
        # b=0.1;
        # if b != 0.0:
        #     [Fx,Fy]=gradient([self.BX;self.RX;self.GX;self.BY;self.RY;self.GY])

        #     self.BX=b*Fx(4,:)+self.BX
        #     self.RX=b*Fx(5,:)+self.RX
        #     self.GX=b*Fx(6,:)+self.GX

        #     self.BY=b*Fx(1,:)+self.BY
        #     self.RY=b*Fx(2,:)+self.RY
        #     self.GY=b*Fx(3,:)+self.GY

        #combine paths
        rmult = 0.0001
        if 1:
            fmB = 0.5
            fmG = 0.5

            #            self.BX=(self.BX+self.RX+(2*random.uniform(1,self.N)-1.0)*rmult)/2.0
            self.BX = (self.BX + self.RX) / 2.0
            self.BY = (self.BY + self.RY +
                       (2 * random.uniform(1, self.N) - 1.0) * rmult) / 2.0

            self.RX = (self.RX + self.GX +
                       (2 * random.uniform(1, self.N) - 1.0) * rmult) / 2.0
            self.RY = (self.RY + self.GY +
                       (2 * random.uniform(1, self.N) - 1.0) * rmult) / 2.0

            self.GX = (self.BX + self.GX +
                       (2 * random.uniform(1, self.N) - 1.0) * rmult) / 2.0
            self.GY = (self.BY + self.GY +
                       (2 * random.uniform(1, self.N) - 1.0) * rmult) / 2.0
        else:
            fmB = 1.0
            fmG = 1.0

        #spin frequency
        freq = 0.01 + random.gauss(0, 0.002)

        self.BX = cos(freq * fmB) * self.BX - sin(freq * fmB) * self.BY
        self.BY = sin(freq * fmB) * self.BX + cos(freq * fmB) * self.BY

        self.RX = cos(freq) * self.RX - sin(freq) * self.RY
        self.RY = sin(freq) * self.RX + cos(freq) * self.RY

        self.GX = cos(freq * fmG) * self.GX - sin(freq * fmG) * self.GY
        self.GY = sin(freq * fmG) * self.GX + cos(freq * fmG) * self.GY

        #centering
        self.BX = self.BX - self.BX.mean()
        self.BY = self.BY - self.BY.mean()

        self.RX = self.RX - self.RX.mean()
        self.RY = self.RY - self.RY.mean()

        self.GX = self.GX - self.GX.mean()
        self.GY = self.GY - self.GY.mean()

        #scaling and bouncy factor
        bounce = 5.0
        self.fB = self.fB + (
            (self.fB + max(np.sqrt(self.BX**2 + self.BY**2))) / 2.0 -
            self.fB) / bounce
        self.fR = self.fR + (
            (self.fR + max(np.sqrt(self.RX**2 + self.RY**2))) / 2.0 -
            self.fR) / bounce
        self.fG = self.fG + (
            (self.fG + max(np.sqrt(self.GX**2 + self.GY**2))) / 2.0 -
            self.fG) / bounce

        self.BX = self.BX / self.fB
        self.BY = self.BY / self.fB

        self.RX = self.RX / self.fR
        self.RY = self.RY / self.fR

        self.GX = self.GX / self.fG
        self.GY = self.GY / self.fG

        ####################################
        #LUX RENDERING CODE
        ####################################

        ol.loadIdentity3()
        ol.loadIdentity()
        #        ol.color3(*(self.color_cycle()))
        ol.scale3((self.scale_factor, self.scale_factor, self.scale_factor))
        theta_rot = 0.4 * cos(1.7 * lux.time * self.ROT_RATE) + 0.6 * cos(
            0.7 * lux.time * self.ROT_RATE)
        ol.rotate3Z(theta_rot)

        render_type = ol.POINTS

        current_hue_marker = self.writhe_current_hue
        current_hue_target = self.writhe_hue_target
        current_hue_step = self.writhe_hue_step

        #        ol.color3(0.0,0.0,1.0)
        ol.begin(ol.POINTS)
        for i in range(self.BX.shape[0]):
            ol.color3(*(self.writhe_color_cycle()))
            ol.vertex3((self.BX[i], self.BY[i], -1))
        ol.end()

        self.writhe_current_hue = current_hue_marker
        self.writhe_current_target = current_hue_target
        self.writhe_current_step = current_hue_step

        ol.begin(ol.POINTS)
        for i in range(self.BX.shape[0]):
            ol.color3(*(self.writhe_color_cycle()))
            ol.vertex3((-self.BX[i], self.BY[i], -1))
        ol.end()

        self.writhe_current_hue = current_hue_marker
        self.writhe_current_target = current_hue_target
        self.writhe_current_step = current_hue_step

        ol.begin(ol.POINTS)
        for i in range(self.BX.shape[0]):
            ol.color3(*(self.writhe_color_cycle()))
            ol.vertex3((self.BX[i], -self.BY[i], -1))
        ol.end()

        self.writhe_current_hue = current_hue_marker
        self.writhe_current_target = current_hue_target
        self.writhe_current_step = current_hue_step

        ol.begin(ol.POINTS)
        for i in range(self.BX.shape[0]):
            ol.color3(*(self.writhe_color_cycle()))
            ol.vertex3((-self.BX[i], -self.BY[i], -1))
        ol.end()
示例#47
0
    def draw(self):
   
        self.i=self.i+1.0;
        
        #inverse persistence length
        self.thetad=0.25*(1.0+sin(2.0*pi*self.i/2000.0))
    
        #RGB curliness offset
        offset=pi/6.0
    
        #RGB curly-straight cycle frequency
        crlstrt=0.005
    
        #RGB maximum curlyness
        curlmx=0.2
    
        theta0B=curlmx*cos(self.i*crlstrt)
        theta0R=curlmx*cos(self.i*crlstrt+offset)
        theta0G=curlmx*cos(self.i*crlstrt+2.0*offset)
    
        self.thetaB=self.thetaB+random.gauss(theta0B,self.thetad)
        self.thetaR=self.thetaR+random.gauss(theta0R,self.thetad)
        self.thetaG=self.thetaG+random.gauss(theta0G,self.thetad)
    
        self.BX=np.append(self.BX[1:], self.BX[-1]+self.dr*cos(self.thetaB))
        self.BY=np.append(self.BY[1:], self.BY[-1]+self.dr*sin(self.thetaB))
        
        self.RX=np.append(self.RX[1:], self.RX[-1]+self.dr*cos(self.thetaR))
        self.RY=np.append(self.RY[1:], self.RY[-1]+self.dr*sin(self.thetaR))
    
        self.GX=np.append(self.GX[1:], self.GX[-1]+self.dr*cos(self.thetaG))
        self.GY=np.append(self.GY[1:], self.GY[-1]+self.dr*sin(self.thetaG))
         
        # derivative roughness parameter
        # b=0.1;
        # if b != 0.0:
        #     [Fx,Fy]=gradient([self.BX;self.RX;self.GX;self.BY;self.RY;self.GY])
        
        #     self.BX=b*Fx(4,:)+self.BX
        #     self.RX=b*Fx(5,:)+self.RX
        #     self.GX=b*Fx(6,:)+self.GX
        
        #     self.BY=b*Fx(1,:)+self.BY
        #     self.RY=b*Fx(2,:)+self.RY
        #     self.GY=b*Fx(3,:)+self.GY
    
        #combine paths
        rmult=0.0001;
        if 1:
            fmB=0.5
            fmG=0.5
        
            #            self.BX=(self.BX+self.RX+(2*random.uniform(1,self.N)-1.0)*rmult)/2.0
            self.BX=(self.BX+self.RX)/2.0
            self.BY=(self.BY+self.RY+(2*random.uniform(1,self.N)-1.0)*rmult)/2.0
        
            self.RX=(self.RX+self.GX+(2*random.uniform(1,self.N)-1.0)*rmult)/2.0
            self.RY=(self.RY+self.GY+(2*random.uniform(1,self.N)-1.0)*rmult)/2.0
        
            self.GX=(self.BX+self.GX+(2*random.uniform(1,self.N)-1.0)*rmult)/2.0
            self.GY=(self.BY+self.GY+(2*random.uniform(1,self.N)-1.0)*rmult)/2.0
        else:
            fmB=1.0
            fmG=1.0
    
        #spin frequency
        freq=0.01+random.gauss(0,0.002)
    
        self.BX=cos(freq*fmB)*self.BX-sin(freq*fmB)*self.BY
        self.BY=sin(freq*fmB)*self.BX+cos(freq*fmB)*self.BY
    
        self.RX=cos(freq)*self.RX-sin(freq)*self.RY
        self.RY=sin(freq)*self.RX+cos(freq)*self.RY
        
        self.GX=cos(freq*fmG)*self.GX-sin(freq*fmG)*self.GY
        self.GY=sin(freq*fmG)*self.GX+cos(freq*fmG)*self.GY
    
        #centering
        self.BX=self.BX-self.BX.mean()
        self.BY=self.BY-self.BY.mean()
    
        self.RX=self.RX-self.RX.mean()
        self.RY=self.RY-self.RY.mean()
    
        self.GX=self.GX-self.GX.mean()
        self.GY=self.GY-self.GY.mean()
    
        #scaling and bouncy factor
        bounce=5.0
        self.fB  =  self.fB + ((self.fB+max(np.sqrt(self.BX**2+self.BY**2)))/2.0-self.fB)/bounce
        self.fR  =  self.fR + ((self.fR+max(np.sqrt(self.RX**2+self.RY**2)))/2.0-self.fR)/bounce
        self.fG  =  self.fG + ((self.fG+max(np.sqrt(self.GX**2+self.GY**2)))/2.0-self.fG)/bounce
    
        self.BX=self.BX/self.fB
        self.BY=self.BY/self.fB
    
        self.RX=self.RX/self.fR
        self.RY=self.RY/self.fR
        
        self.GX=self.GX/self.fG
        self.GY=self.GY/self.fG    
    
        ####################################
        #LUX RENDERING CODE
        ####################################

        ol.loadIdentity3()
        ol.loadIdentity()
        #        ol.color3(*(self.color_cycle()))
        ol.scale3((self.scale_factor,self.scale_factor,self.scale_factor))
        theta_rot = 0.4*cos(1.7 * lux.time * self.ROT_RATE) + 0.6*cos(0.7 * lux.time * self.ROT_RATE)
        ol.rotate3Z(theta_rot)


        render_type  =  ol.POINTS

        current_hue_marker = self.writhe_current_hue
        current_hue_target = self.writhe_hue_target
        current_hue_step = self.writhe_hue_step
        
#        ol.color3(0.0,0.0,1.0)
        ol.begin(ol.POINTS)
        for i in range(self.BX.shape[0]):
            ol.color3(*(self.writhe_color_cycle()))
            ol.vertex3((self.BX[i], self.BY[i], -1))
        ol.end()

        self.writhe_current_hue = current_hue_marker
        self.writhe_current_target = current_hue_target
        self.writhe_current_step = current_hue_step

        ol.begin(ol.POINTS)
        for i in range(self.BX.shape[0]):
            ol.color3(*(self.writhe_color_cycle()))
            ol.vertex3((-self.BX[i], self.BY[i], -1))
        ol.end()

        self.writhe_current_hue = current_hue_marker
        self.writhe_current_target = current_hue_target
        self.writhe_current_step = current_hue_step

        ol.begin(ol.POINTS)
        for i in range(self.BX.shape[0]):
            ol.color3(*(self.writhe_color_cycle()))
            ol.vertex3((self.BX[i], -self.BY[i], -1))
        ol.end()

        self.writhe_current_hue = current_hue_marker
        self.writhe_current_target = current_hue_target
        self.writhe_current_step = current_hue_step

        ol.begin(ol.POINTS)
        for i in range(self.BX.shape[0]):
            ol.color3(*(self.writhe_color_cycle()))
            ol.vertex3((-self.BX[i], -self.BY[i], -1))
        ol.end()
示例#48
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        ol.color3(1.0, 0.0, 1.0)
        font = ol.getDefaultFont()
        s = "davidad"
        x = sin(lux.time) * 0.5
        w = ol.getStringWidth(font, x, s)
        #ol.drawString(font, (-w/2,0), x, s)

        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        t = lux.time * 2
        lx = 0
        ly = 0
        for i in range(8):

            c = floor(t * 2 + i) % 3
            c = 3
            if (c == 1):
                #if(1):
                ol.color3(1.0, 1.0, 0.0)
            if (c == 2):
                ol.color3(0.0, 1.0, 1.0)
            if (c == 3):
                ol.color3(1.0, 0.0, 1.0)

            ol.scale3((0.6, 0.6, 0.6))
            #ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
            #ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
            #ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)

            z = 2 * sin(t * 2)
            z = -1 + 4 * (t * 2 - floor(t * 2))
            #z = 4
            x = 0.5 * sin(t + i / 1.0)
            y = 0.5 * cos(t + i / 1.0)

            ol.begin(ol.LINESTRIP)
            ol.vertex3((x - 1, y - 1, z))
            ol.vertex3((x - 1, y + 1, z))
            ol.vertex3((x + 1, y + 1, z))
            ol.vertex3((x + 1, y - 1, z))
            ol.vertex3((x - 1, y - 1, z))
            ol.end()

            if i != 0:
                ol.begin(ol.LINESTRIP)
                ol.vertex3((x - 1, y - 1, z))
                ol.vertex3((lx - 1, ly - 1, z + 4))
                ol.end()

                ol.begin(ol.LINESTRIP)
                ol.vertex3((x - 1, y + 1, z))
                ol.vertex3((lx - 1, ly + 1, z + 4))
                ol.end()

                ol.begin(ol.LINESTRIP)
                ol.vertex3((x + 1, y + 1, z))
                ol.vertex3((lx + 1, ly + 1, z + 4))
                ol.end()

                ol.begin(ol.LINESTRIP)
                ol.vertex3((x + 1, y - 1, z))
                ol.vertex3((lx + 1, ly - 1, z + 4))
                ol.end()

            lx = x
            ly = y
示例#49
0
    def draw(self):
        time = lux.time
        #time = self.time
        ctf = self.color_time_frequency
        clf = self.color_length_frequency
        caf = self.color_angle_frequency / 2
        theta = abs(math.sin(time * self.time_scale))
        R = self.R * math.sin(
            2 * pi * time * self.time_scale * self.R_frequency)
        r = self.r * math.sin(
            2 * pi * time * self.time_scale * self.r_frequency)
        p = self.p * math.sin(
            2 * pi * time * self.time_scale * self.p_frequency) * self.bass
        audio = self.get_audio()

        ol.color3(1.0, 0.0, 1.0)
        ol.loadIdentity3()
        ol.loadIdentity()
        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))

        first = True
        n = 0
        while theta < 2 * pi * self.max_cycles and n < self.max_segments:
            theta += self.theta_step
            if audio:
                try:
                    sample_index = int(
                        theta / (2 * pi * self.max_cycles) *
                        (audio[0].shape[0] - 1)) + 1  #skip first sample
                    sample = audio[2][sample_index]
                except:
                    sample = 0
            else:
                sample = 0  #[0 for x in range(10000)] #empty vector
            #x = (R + r) * math.cos(theta)
            #y = (R + r) * math.sin(theta)
            sample *= self.audio_gain
            #print sample
            #x = (R + r) * math.cos(theta) + (r + p + sample) * math.cos((R+r)/r * theta)
            #y = (R + r) * math.sin(theta) + (r + p + sample) * math.sin((R+r)/r * theta)
            #ben's ill advised DALT change
            x = (R + r) * math.cos(theta) + (r + p * sample) * math.cos(
                (R + r) / r * theta)
            y = (R + r) * math.sin(theta) + (r + p * sample) * math.sin(
                (R + r) / r * theta)

            if first:
                #ol.begin(ol.LINESTRIP)
                ol.begin(ol.POINTS)
                first = False
            #red = math.sin(ctf*time*n/37) * math.sin(csf*theta*n/37)
            #green = math.sin(ctf*time*n/23) * math.sin(csf*theta*n/23)
            #blue = math.sin(ctf*time*n/128) * math.sin(csf*theta*n/128)

            angle = math.atan2(y, x) / (2 * pi)
            red = abs(
                math.sin(
                    2 * pi *
                    (self.r_prime / 3 + ctf * time + clf * n + caf * angle)))
            green = abs(
                math.sin(
                    2 * pi *
                    (self.g_prime / 3 + ctf * time + clf * n + caf * angle)))
            blue = abs(
                math.sin(
                    2 * pi *
                    (self.b_prime / 3 + ctf * time + clf * n + caf * angle)))
            ol.color3(red, green, blue)

            #this makes it square-ish
            #x += math.cos(2*pi*angle*self.spatial_resonance)*self.spatial_resonance_amplitude
            #y += math.sin(2*pi*angle*self.spatial_resonance)*self.spatial_resonance_amplitude
            x += math.cos(2 * pi * angle * (self.spatial_resonance + 1) +
                          2 * pi * self.spatial_resonance_offset
                          ) * self.spatial_resonance_amplitude
            y += math.sin(2 * pi * angle * (self.spatial_resonance + 1) +
                          2 * pi * self.spatial_resonance_offset
                          ) * self.spatial_resonance_amplitude

            x *= self.width
            y *= self.height
            ol.vertex3((x, y, 0))
            n += 1
        ol.end()
        #dynamically adjust resolution
        target = self.max_segments * 0.8
        error = (target - n) / target
        self.theta_step = min(max(1e-100, self.theta_step * (1 - error)), 1)
        #print n,  angle
        self.time += 1 / 30
示例#50
0
    def draw(self):
        theta = arange(0, 2 * pi, 2 * pi / self.N)

        # rotations in q-space
        mu = 0.01
        std = 0.001

        dth1 = random.gauss(mu, std)
        dth2 = random.gauss(mu, std)
        dth3 = random.gauss(mu, std)
        dth4 = random.gauss(mu, std)
        dth5 = random.gauss(mu, std)

        dth1b = random.gauss(mu, std)
        dth2b = random.gauss(mu, std)
        dth3b = random.gauss(mu, std)
        dth4b = random.gauss(mu, std)
        dth5b = random.gauss(mu, std)

        # dth1=self.dtheta*(1-2*(random.random()<self.cut));
        # dth2=self.dtheta*(1-2*(random.random()<self.cut));
        # dth3=self.dtheta*(1-2*(random.random()<self.cut));
        # dth4=self.dtheta*(1-2*(random.random()<self.cut));
        # dth5=self.dtheta*(1-2*(random.random()<self.cut));

        # dth1b=self.dtheta*(1-2*(random.random()<self.cut));
        # dth2b=self.dtheta*(1-2*(random.random()<self.cut));
        # dth3b=self.dtheta*(1-2*(random.random()<self.cut));
        # dth4b=self.dtheta*(1-2*(random.random()<self.cut));
        # dth5b=self.dtheta*(1-2*(random.random()<self.cut));

        self.th1 = self.th1 + dth1
        self.th2 = self.th2 + dth2
        self.th3 = self.th3 + dth3
        self.th4 = self.th4 + dth4
        self.th5 = self.th5 + dth5

        self.th1b = self.th1b + dth1b
        self.th2b = self.th2b + dth2b
        self.th3b = self.th3b + dth3b
        self.th4b = self.th4b + dth4b
        self.th5b = self.th5b + dth5b

        c1 = self.m1 * cos(self.th1)
        s1 = self.m1 * sin(self.th1)
        c2 = self.m2 * cos(self.th2)
        s2 = self.m2 * sin(self.th2)
        c3 = self.m3 * cos(self.th3)
        s3 = self.m3 * sin(self.th3)
        c4 = self.m4 * cos(self.th4)
        s4 = self.m4 * sin(self.th4)
        c5 = self.m5 * cos(self.th5)
        s5 = self.m5 * sin(self.th5)

        X = c1 * cos(theta + self.th1b) + c2 * cos(
            2 * theta +
            self.th2b) + c3 * cos(3 * theta + self.th3b) + c4 * cos(
                4 * theta + self.th4b) + c5 * cos(5 * theta + self.th5b)
        Y = s1 * sin(theta + self.th1b) + s2 * sin(
            2 * theta +
            self.th2b) + s3 * sin(3 * theta + self.th3b) + s4 * sin(
                4 * theta + self.th4b) + s5 * sin(5 * theta + self.th5b)

        X = (X - X.mean()).astype("complex")
        Y = (Y - Y.mean()).astype("complex")

        s = arange(1, self.N + 1, 1)

        Xtemp = X**self.p1x * Y**self.p1y + 2 * s * 1j - self.N * 1j
        Ytemp = X**self.p2x * Y**self.p2y + 2 * s * 1j - self.N * 1j

        X = Xtemp.real
        Y = Ytemp.real

        X = tanh(2 * X)
        Y = tanh(2 * Y)

        ol.loadIdentity3()
        ol.loadIdentity()
        ol.color3(*(self.color_cycle()))

        render_type = ol.POINTS

        ol.begin(ol.POINTS)
        for i in range(X.shape[0]):
            ol.vertex3((X[i], Y[i], -1))
        ol.vertex3((X[0], Y[0], -1))
        ol.end()

        ol.begin(ol.POINTS)
        for i in range(X.shape[0]):
            ol.vertex3((-X[i], Y[i], -1))
        ol.vertex3((-X[0], Y[0], -1))
        ol.end()

        ol.begin(ol.POINTS)
        for i in range(X.shape[0]):
            ol.vertex3((0.7 * X[i], -0.7 * Y[i], -1))
        ol.vertex3((0.7 * X[0], -0.7 * Y[0], -1))
        ol.end()

        ol.begin(ol.POINTS)
        for i in range(X.shape[0]):
            ol.vertex3((-0.7 * X[i], -0.7 * Y[i], -1))
        ol.vertex3((-0.7 * X[0], -0.7 * Y[0], -1))
        ol.end()
示例#51
0
    def draw(self, audio):
        '''a square'''
        #self.x = math.cos(2*pi*rotate_frequency*lux.time + self.angle + self.base_angle) * self.distance * self.distance_scale
        #self.y = math.sin(2*pi*rotate_frequency*lux.time + self.angle + self.base_angle) * self.distance * self.distance_scale

        #stolen from guilloche
        time = lux.time * time_scale
        R = math.sin(2 * pi * self.R_frequency * time) * self.R + 0.0001
        r = math.sin(2 * pi * self.r_frequency * time) * self.r + 0.0001
        p = math.sin(2 * pi * self.p_frequency * time) * self.p + 0.0001
        self.x = (R + r) * math.cos(time) + (r + p) * math.cos(
            (R + r) / r * time)
        self.y = (R + r) * math.sin(time) + (r + p) * math.sin(
            (R + r) / r * time)

        #clamp to display area
        if clamp_display:
            if self.x > 1: self.x = 1
            if self.y > 1: self.y = 1
            if self.x < -1: self.x = -1
            if self.y < -1: self.y = -1
        self.x *= scale
        self.y *= scale
        #self.graphics.circle(0, 0, self.radius)
        ol.loadIdentity3()
        ol.loadIdentity()

        #ol.color3(self.color[0], self.color[1], self.color[2])
        ol.color3(self.red, self.green, self.blue)
        ol.translate3((self.x, self.y, 0))
        angle = math.atan2(self.y, self.x) / (2 * pi)
        red = self.red  #abs(math.sin(2*pi*(r_prime/3+ctf*time+clf*self.n+caf*angle)))*self.red
        green = abs(
            math.sin(2 * pi * (g_prime / 3 + ctf * time + clf * self.n +
                               caf * angle))) * self.green
        blue = abs(
            math.sin(2 * pi * (b_prime / 3 + ctf * time + clf * self.n +
                               caf * angle))) * self.blue
        if seizure_mode:
            #red, green, blue = red/self.radius, green/self.radius, blue/self.radius
            red = abs(red * math.tan((2 * pi * self.radius / node_big_radius)))
            green = abs(green * math.tan(
                (2 * pi * self.radius / node_big_radius)))
            blue = abs(blue * math.tan(
                (2 * pi * self.radius / node_big_radius)))
        if audio:
            try:
                #seems most of the time all the samples are empty
                #sample_index = int((self.n/max_nodes)*audio[0].shape[0])
                sample_index = 0  #self.n
                sample = audio[0][n]

            except:
                sample = 1
        else:
            sample = 1  #[0 for x in range(10000)] #empty vector
        #print sample
        if audio:
            red = red
            blue = blue + sample * self.audio_gain
            green = green + sample * self.audio_gain
        ol.color3(red, green, blue)
        if self.last_sample - sample > 0.1:
            pass  #pulse
        #do squares have radii?
        s = self.radius
        ol.begin(ol.POINTS)
        ol.vertex3((-s, s, 0))
        ol.vertex3((-s, s, 0))
        ol.vertex3((s, s, 0))
        ol.vertex3((s, -s, 0))
        ol.vertex3((-s, -s, 0))
        ol.end()
示例#52
0
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import pylase as ol
from math import pi

ol.init()

time = 0
frames = 0

while True:
	ol.loadIdentity3()
	ol.loadIdentity()

	font = ol.getDefaultFont()
	s = "Hi!"
	w = ol.getStringWidth(font, 0.2, s)
	ol.drawString(font, (-w/2,0.1), 0.2, ol.C_WHITE, s)

	ol.perspective(60, 1, 1, 100)
	ol.translate3((0, 0, -3))

	for i in range(2):
		if (i == 1):
                    ol.color3(1.0,0.0,0.0);
                else:
                    ol.color3(0.0,1.0,0.0);
示例#53
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        self.server.recv(10)
示例#54
0
    def run(self):

        # Run the render loop.  This will repeatedly render frames of the current plugin.
        print '\t--> Starting up LUX Engine.'
        ftime = 0
        frames = 0

        # Initialize OpenLase.  This also creates the lux_engine jack endpoints.
        if (ol.init(3, 96000) != 0):
            raise Exception("Could not initialize openlase")

        # Connect the output engine to the lux_engine.
        self.output_engine.connect_ports("lux_engine:out_x", "lux_output:in_x")
        self.output_engine.connect_ports("lux_engine:out_y", "lux_output:in_y")
        self.output_engine.connect_ports("lux_engine:out_r", "lux_output:in_r")
        self.output_engine.connect_ports("lux_engine:out_g", "lux_output:in_g")
        self.output_engine.connect_ports("lux_engine:out_b", "lux_output:in_b")

        # Turn off the hardware safety interlock.
        self.output_engine.setOutputInitialized(True)

        # Create a local settings object for this thread.
        settings = LuxSettings()
        
        while not self.exiting:
            # Grab local references to these class variables
            self.lock.lock()
            current_plugin = self.current_plugin
            video_engine = self.video_engine
            self.lock.unlock()
            
            # SET PARAMETERS
            #
            # Check to see if the GUI parameter override has been set,
            # and we need to update OL parameters.
            if (self.ol_update_params and settings['calibration'].parameterOverride and current_plugin):
                current_plugin.setParametersToGuiValues()
                self.ol_update_params = False

            if (current_plugin and not settings['calibration'].parameterOverride):
                current_plugin.setParameters();

            # RENDER
            #
            # We call out to the current plugin's draw() method, or
            # the video plugin, depending on the current state of the
            # GUI.
            if (current_plugin):
                if (settings['video'].videoMode):
                    # Cause video color cycling to happen
                    ol.loadIdentity3();
                    ol.loadIdentity();
                    ol.perspective(60, 1, 1, 100);
                    ol.translate3((0, 0, -3));

                    ol.color3(*(self.video_color_drift.color_cycle()))
                    video_engine.draw_lasers()
                else:
                    current_plugin.draw()

                frame_render_time = ol.renderFrame(60)   # Takes max_fps as argument
                frames += 1
                ftime += frame_render_time
                #print "Frame time: %f, FPS:%f"%(frame_render_time, frame_render_time/ftime)
            else:
                # If there is no plugin for some reason, kill time
                # rather than burning CPU in a loop that does nothing.
                time.sleep(0.1)
示例#55
0
    def draw(self):
        ol.loadIdentity3()
        ol.loadIdentity()

        #ol.color3(1.0, 0.0, 1.0);
        #font = ol.getDefaultFont()
        #s = "Lux!"
        #w = ol.getStringWidth(font, 0.2, s)
        #ol.drawString(font, (-w/2,0.1), 0.2, s)

        ol.perspective(60, 1, 1, 100)
        ol.translate3((0, 0, -3))


        #Dodecahedron---------------------------
        ol.color3(1.0,1.0,1.0);
        ol.scale3((0.8, 0.8, 0.8))
        ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
        ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
        ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)

        for face in self.dodeca_face_edges:
            ol.begin(ol.LINESTRIP)
            ol.vertex3(face[0])
            ol.vertex3(face[1])
            ol.vertex3(face[2])
            ol.vertex3(face[3])
            ol.vertex3(face[4])
            ol.vertex3(face[0])
            ol.end()

        #Icosahedron---------------------------
        ol.color3(1.0,1.0,0.0);
                    
        ol.scale3((0.9, 0.9, 0.9))
        ol.rotate3Z(lux.time * pi * 0.5 * lux.simple_rate)
        #ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
        #ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)

        for face in self.icos_face_edges:
            ol.begin(ol.LINESTRIP)
            ol.vertex3(face[0])
            ol.vertex3(face[1])
            ol.vertex3(face[2])
            ol.vertex3(face[0])
            ol.end()
        #for strip in self.icos_face_edges:
        #    ol.begin(ol.LINESTRIP)
        #    for f in strip:
        #        ol.vertex3(f)
        #    ol.end()

        #Cube---------------------------
#         ol.color3(0.0,0.0,1.0);
#         ol.scale3((0.4, 0.4, 0.4))
#         #ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
#         #ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
#         ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)

#         ol.begin(ol.LINESTRIP)
#         ol.vertex3((-1, -1, -1))
#         ol.vertex3(( 1, -1, -1))
#         ol.vertex3(( 1,  1, -1))
#         ol.vertex3((-1,  1, -1))
#         ol.vertex3((-1, -1, -1))
#         ol.vertex3((-1, -1,  1))
#         ol.end()
        
#         ol.begin(ol.LINESTRIP);
#         ol.vertex3(( 1,  1,  1))
#         ol.vertex3((-1,  1,  1))
#         ol.vertex3((-1, -1,  1))
#         ol.vertex3(( 1, -1,  1))
#         ol.vertex3(( 1,  1,  1))
#         ol.vertex3(( 1,  1, -1))
#         ol.end()
        
#         ol.begin(ol.LINESTRIP)
#         ol.vertex3(( 1, -1, -1))
#         ol.vertex3(( 1, -1,  1))
#         ol.end()
        
#         ol.begin(ol.LINESTRIP)
#         ol.vertex3((-1,  1,  1))
#         ol.vertex3((-1,  1, -1))
#         ol.end()

        #Octahedron------------------------
        ol.color3(0.0,0.0,1.0);
        ol.scale3((.8, .8, .8))
        #ol.rotate3Z(lux.time * pi * 0.1 * lux.simple_rate)
        ol.rotate3X(lux.time * pi * 0.8 * lux.simple_rate)
        #ol.rotate3Y(lux.time * pi * 0.73 * lux.simple_rate)

        for strip in self.octahedron_face_edges:
            ol.begin(ol.LINESTRIP)
            for f in strip:
                ol.vertex3(f)
            ol.end()
示例#56
0
        scanline.append(
            [pixel_on, PixelCoordToGalvoCoord(x, y, width, height)])
        scanning_on = False
    if len(scanline) > 0:
        scanlines.append(scanline)
    scanlines.append(scanline)

if options.preview:
    pygame.init()
    #create the screen
    window = pygame.display.set_mode((scaledWidth, scaledHeight))

print "Found ", len(scanlines), "non blank scan lines... scanning now..."
for l in scanlines:
    if options.laser:
        ol.loadIdentity()
        ol.scale((float(options.xscale), float(options.yscale)))
    for s in l:
        if options.preview:
            pygame.draw.line(
                window, (0, 255, 0),
                GalvoCoordToPixelCoord(s[0], scaledWidth, scaledHeight),
                GalvoCoordToPixelCoord(s[1], scaledWidth, scaledHeight))
        if options.laser:
            ol.line((s[0][0], s[0][1]), (s[1][0], s[1][1]), ol.C_WHITE)
    if options.preview:
        pygame.display.flip()
    if options.laser:
        ol.renderFrame(int(options.power))

print options.pngfile,