ENTRY | DOWNLOAD | MANUAL | ONGOING | |
sprite_tracking.py"""Track screen coordinates of shapes in perspective space. by stephan) """ from slut import * class Atlantis(World): def onSetup(self): self.name = "Form Follows Computation Here" self.width = 800 self.height = 600 self.showCoordinates = True p1 = Polygon(self, 'poly1') p2 = Polygon(self, 'poly2') p1.enableTracking() p2.enableTracking() p1.enableMouseEvents() p2.enableMouseEvents() p1.moveBy(Tween(1.0, 0.0, 0.0, 1.0)) p2.moveBy(SineTween(-1.5, 0.0, -1.5, 1.0)) p2.rotBy(SineTween(90.0, 0.0, 20.0, 2.0)) tt = TagText(self, 'tag1', 36, 'times') tt.setText('TAG*') Box(self, 'box1', 0, 100, 50, 50) Box(self, 'box2', 0, 100, 50, 50) self.tags['box1'].setColor(1.0, 1.0, 1.0, 1.0) self.tags['box2'].setColor(1.0, 0.0, 0.0, 1.0) def onDraw(self): p1 = self.sprites['poly1'] p2 = self.sprites['poly2'] self.tags['box1'].setVertices(p1.min_x, p1.min_y, p1.max_x-p1.min_x, p1.max_y-p1.min_y) self.tags['box2'].setVertices(p2.min_x, p2.min_y, p2.max_x-p2.min_x, p2.max_y-p2.min_y) self.tags['tag1'].moveTo(p1.max_x, p1.min_y) class Polygon(Sprite): def onDraw(self): glBegin(GL_POLYGON) glVertex3f(0.0, 0.0, 0.0) glVertex3f(1.0, 0.0, 0.0) glVertex3f(1.0, 1.0, 0.0) glVertex3f(-0.5, 1.5, 0.0) glVertex3f(0.0, 0.0, 0.0) glEnd() def onMouseButtonDown(self, event): if glo.ia.SHIFT: self.moveBy(Tween(1.0, 0.0, 0.0, 1.0)) else: self.moveBy(SineTween(-1.0, 0.0, 0.0, 1.0)) atlantis = Atlantis() atlantis.run() |
|
Initiated by Stephan Hechenberger Thanks to CADRE's 103 |