def scan(self): sync_to = 0.1 x = math.fmod(time.time(), sync_to) x = sync_to - x time.sleep(x) self.reset_timer() scan_iter = self.iter_scan() while True: try: next(scan_iter) except StopIteration: break self.tick() if not self.no_black: gl.clear(gl.COLOR_BUFFER_BIT) glut.swapBuffers() self.tick() if self.dropped: gl.color(1, 0, 0, 1) self.polyfill() glut.swapBuffers() time.sleep(0.5) return
def display(self): gl.clear(gl.COLOR_BUFFER_BIT) # gl.color(0, 0.0625, 0.125, 1) # self.polyfill() gl.lineWidth(2) gl.color(0.2, 0.2, 0.05, 1) for power in (1, ): # gl.lineWidth((3 - power) ** 2) dx = self.width // (2**power) dy = self.height // (2**power) with gl.begin(gl.LINES): for x in xrange(dx, self.width, dx): gl.vertex(x, 0, 0) gl.vertex(x, self.height, 0) for y in xrange(dy, self.height, dy): gl.vertex(0, y, 0) gl.vertex(self.width, y, 0) glut.swapBuffers()
def time_stage(self): seconds = int(time.time()) blocks = [0, 0, 0] while seconds: seconds, block = divmod(seconds, 8) blocks.append(block) size = 8 for i, x in enumerate(xrange(0, self.width, size)): bi = i % len(blocks) block = blocks[bi] if bi < 3: pattern = (1, 0.5, 0) gl.color( pattern[(bi + 0) % 3], pattern[(bi + 1) % 3], pattern[(bi + 2) % 3] ) else: gl.color( int(bool(block // 4)), int(bool(block // 2 % 2)), int(bool(block % 2)) ) with gl.begin(gl.POLYGON): gl.vertex(x, 0) gl.vertex(x + size, 0) gl.vertex(x + size, self.height) gl.vertex(x, self.height) yield
def display(self): gl.clear(gl.COLOR_BUFFER_BIT) gl.color(1, 1, 1, 1) max_bits = max(int(math.log(self.width - 1, 2)), int(math.log(self.height - 1, 2))) + 1 assert max_bits < 16 for power in xrange(0, self.layers): size = self.base_size * 2**power gl.lineWidth(self.base_width + 2 * power) v = (power + 1) / float(self.layers) gl.color(v, v, v, 1) with gl.begin(gl.LINES): for x in xrange(size, self.width, size): gl.vertex(x, 0, 0) gl.vertex(x, self.height, 0) for y in xrange(size, self.height, size): gl.vertex(0, y, 0) gl.vertex(self.width, y, 0) glut.swapBuffers()
def display(self): gl.bindFramebuffer(gl.FRAMEBUFFER, self.fbo) # Wipe the window. gl.enable('depth_test') gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.loadIdentity() gl.disable('texture_2d') self.fixed.use() gl.color(1, 1, 1, 1) for freq, offset, amp in self.curves: with gl.begin('line_strip'): for x in xrange(0, self.width + 1, 10): gl.vertex(x, self.height * (0.5 + 0.5 * amp * math.sin(4 * self.frame / self.frame_rate + offset + x * freq / self.width)), 0) gl.bindFramebuffer(gl.FRAMEBUFFER, 0) gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.enable('texture_2d') gl.enable('depth_test') gl.color(1, 1, 1, 1) print 'I need to print so it doesnt explode.' self.shader.use() location = gl.getUniformLocation(self.shader._prog, "texture1") if location >= 0: gl.uniform1i(location, 0) location = gl.getUniformLocation(self.shader._prog, "width") if location >= 0: gl.uniform1f(location, float(self.width)) location = gl.getUniformLocation(self.shader._prog, "height") if location >= 0: gl.uniform1f(location, float(self.height)) location = gl.getUniformLocation(self.shader._prog, "dilate") if location >= 0: gl.uniform1f(location, float(self.dilate)) with gl.begin('polygon'): gl.texCoord(0, 0) gl.vertex(0, 0) gl.texCoord(1, 0) gl.vertex(self.width, 0) gl.texCoord(1, 1) gl.vertex(self.width, self.height) gl.texCoord(0, 1) gl.vertex(0, self.height) glut.swapBuffers()
def mosaic_stage(self): size = 64 for x in xrange(0, self.width, size): for y in xrange(0, self.height, size): gl.color( random.choice((0, 1)), random.choice((0, 1)), random.choice((0, 1)) ) with gl.begin(gl.POLYGON): gl.vertex(x, y) gl.vertex(x + size, y) gl.vertex(x + size, y + size) gl.vertex(x, y + size) yield
def iter_scan(self): stages = [stage() for stage in self.stages] for stage in stages: while True: gl.clear(gl.COLOR_BUFFER_BIT) gl.color(1, 1, 1, 1) try: next(stage) except StopIteration: break glut.swapBuffers() yield
def grid_stage(self): gl.color(0, 0, 1, 1) self.polyfill() yield max_bits = max(int(math.log(self.width - 1, 2)), int(math.log(self.height - 1, 2))) + 1 assert max_bits < 16 for power in xrange(2, max_bits): gl.lineWidth(power - 1) self.grid(power) yield gl.color(1, 0, 1, 1) self.polyfill() yield
def info_stage2(self): i = 0 for power in xrange(1, 4): blocks = 2**power dx = self.width / float(blocks) dy = self.height / float(blocks) for x in xrange(blocks): for y in xrange(blocks): i = (i + 1) % 3 gl.color(int(i == 0), int(i == 1), int(i == 2), 1) with gl.begin(gl.POLYGON): gl.vertex(dx * x , dy * y) gl.vertex(dx * (x + 1), dy * y) gl.vertex(dx * (x + 1), dy * (y + 1)) gl.vertex(dx * x , dy * (y + 1)) if not i: yield
def gray_stage(self, texture=0): if not texture: gl.color(0, 1, 0, 1) else: gl.color(0, 1, 1, 1) self.polyfill() yield gl.color(1, 1, 1, 1) self.polyfill() yield yield # Subtract 1 so that 1024 only takes 9 bits. max_bits = int(math.ceil(max(math.log(self.width, 2), math.log(self.height, 2)))) assert max_bits < 16 assert self.width <= 2**max_bits assert self.height <= 2**max_bits assert self.width > 2**(max_bits-1) or self.height > 2**(max_bits-1) self.shader.use() self.shader.uniform1i('texture', texture) self.shader.uniform1f('bits', bits) self.shader.uniform1f('code_count', code_count) for bit in range(max_bits): self.shader.uniform1f('bit', bit) for axis in (0, 1): self.shader.uniform1i('axis', axis) self.polyfill() yield self.shader.unuse() gl.color(1, 0, 1, 1) self.polyfill() yield