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 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 grid(self, power): size = 2**power 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)
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 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 info_stage(self): for power in xrange(1, 5): blocks = 2**power dx = self.width / float(blocks) dy = self.height / float(blocks) for i in xrange(blocks): with gl.begin(gl.POLYGON): gl.vertex(dx * i, 0) gl.vertex(dx * (i + 1), 0) gl.vertex(dx * (i + 1), self.height) gl.vertex(dx * i, self.height) yield with gl.begin(gl.POLYGON): gl.vertex(0 , dy * i) gl.vertex(self.width, dy * i) gl.vertex(self.width, dy * (i + 1)) gl.vertex(0 , dy * (i + 1)) yield
def polyfill(self): with gl.begin('polygon'): gl.vertex(0, 0) gl.vertex(self.width, 0) gl.vertex(self.width, self.height) gl.vertex(0, self.height)