def render(self, graphics, width = None, height = None, x_offset = 0, y_offset = 0): graphics.save_context( ) graphics.translate( x_offset, y_offset ) graphics.rectangle( 0, 0, width or self.width, height or self.height) graphics.clip() graphics.set_source_surface(self.image_data) graphics.paint() graphics.restore_context()
def put_pattern(image, x, y, w, h): pattern = cairo.SurfacePattern(image[0]) if w > 0 and h > 0: pattern.set_matrix(cairo.Matrix(x0=1, y0=1, xx = (image[1]) / float(w), yy = (image[2]) / float(h))) graphics.save_context() graphics.translate(x, y) graphics.set_source(pattern) graphics.rectangle(0, 0, w, h) graphics.fill() graphics.restore_context()
def put_pattern(image, x, y, w, h): pattern = cairo.SurfacePattern(image[0]) if w > 0 and h > 0: pattern.set_matrix( cairo.Matrix(x0=1, y0=1, xx=(image[1]) / float(w), yy=(image[2]) / float(h))) graphics.save_context() graphics.translate(x, y) graphics.set_source(pattern) graphics.rectangle(0, 0, w, h) graphics.fill() graphics.restore_context()
def draw(dt): global qRot, qRte, qEnd global pos global direction global speed global score if MB: mb = mbhandler.queue.get() q = Vec3(0, -1, 0).rotateTo( Vec3(-mb['accelerometer']['x'], mb['accelerometer']['z'], mb['accelerometer']['y'])) qRot = q**0.1 * qRot if mb['button_a']['pressed']: speed += dspeed if mb['button_b']['pressed']: speed -= dspeed else: qRot = qRte(G.ElapsedTime) if G.ElapsedTime > qEnd: qRte, qEnd = qpath(qRot) speed = max(min(speed, 1), 0) ds = 4 / (1 - pos.lenSqr() / radius**2)**2 pos += (direction * speed * dt / ds)**~qRot for g in gems: if pos.dist(g) < .1: score += 1 v = RandomVec3(radius) g.cloneFrom(v) print(score) G.rotate(qRot) m.draw() G.translate(-pos) for g in gems: G.pushMatrix() G.translate(g) gem.draw() G.popMatrix() G.resetMatrix() G.line(0, -.1, 0, .1) G.line(-.1, 0, .1, 0)
def put_pattern(image, x, y, w, h): if w <= 0 or h <= 0: return graphics.save_context() if not self.stretch_w or not self.stretch_h: # if we repeat then we have to cut off the top-left margin # that we put in there so that stretching does not borrow white # pixels img = cairo.ImageSurface(cairo.FORMAT_ARGB32, image[1], image[2]) ctx = cairo.Context(img) ctx.set_source_surface(image[0], 0 if self.stretch_w else -1, 0 if self.stretch_h else -1) ctx.rectangle(0, 0, image[1], image[2]) ctx.clip() ctx.paint() else: img = image[0] pattern = cairo.SurfacePattern(img) pattern.set_extend(cairo.EXTEND_REPEAT) pattern.set_matrix(cairo.Matrix(x0 = 1 if self.stretch_w else 0, y0 = 1 if self.stretch_h else 0, xx = (image[1]) / float(w) if self.stretch_w else 1, yy = (image[2]) / float(h) if self.stretch_h else 1)) pattern.set_filter(self.stretch_filter_mode) # truncating as fill on half pixel will lead to nasty gaps graphics.translate(int(x + x_offset), int(y + y_offset)) graphics.set_source(pattern) graphics.rectangle(0, 0, int(w), int(h)) graphics.clip() graphics.paint() graphics.restore_context()