jsuarez/extra/embyr_deprecated/embyr2d/application.py [39:117]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        self.writeFrame()
        self.trans = self.renderOffsets(self.H, self.H)
        keyframe = self.count == 0
        if keyframe:
           self.step()

        self.surf = self.view.render(self.realm, self.trans, keyframe)

        self.count = (self.count + 1) % (self.nAnim+1)
        self.blit(self.surf, (0,0))
        self.flip()
        self.frame += 1

    def writeFrame(self):
      NFRAMES=1800
      return
      if self.frame < NFRAMES:
         print('Frame: ', len(self.frames))
         frame = pygame.surfarray.array3d(pygame.transform.rotate(self.surf, 90))
         frame = np.fliplr(frame)
         #frame = frame[:1024, 256:256+1024]
         frame = frame[:1024, 1024+256:1024+256+1024]
         self.frames.append(frame)
         #pygame.image.save(self.screen, 'resource/data/lrframe'+str(self.frame)+'.png')
      elif self.frame == NFRAMES:
         import imageio
         print('Saving MP4...')
         imageio.mimwrite('swordfrag.mp4', self.frames, fps = 30)
         print('Saved')

    def clipZoom(self, zoom):
        return np.clip(zoom, 1.0, 8.0)

    def renderOffsets(self, W, H):
        #Scale
        zoom = self.clipZoom(self.zoom + self.zoomVol)
        scaleX, scaleY = int(W*zoom), int(H*zoom)

        #Translate
        deltaX = self.x + self.xVol - scaleX/2 + W/2
        deltaY = -self.y - self.yVol - scaleY/2 + H/2
        return scaleX, scaleY, deltaX, deltaY

    def on_touch_down(self, touch):
        self.xStart, self.yStart = touch.pos

    def on_touch_up(self, touch):
        if touch.button == 'left':
            self.xVol, self.yVol= 0, 0
            xEnd, yEnd = touch.pos
            self.x += xEnd - self.xStart
            self.y += yEnd - self.yStart
        elif touch.button == 'right':
            self.zoom = self.clipZoom(self.zoom + self.zoomVol)
            self.zoomVol = 0

    def on_touch_move(self, touch):
        if touch.button == 'left':
            xEnd, yEnd = touch.pos
            self.xVol = xEnd - self.xStart
            self.yVol = yEnd - self.yStart
        elif touch.button == 'right':
            xEnd, yEnd = touch.pos
            delta = (xEnd - self.xStart)/2 - (yEnd - self.yStart)/2
            self.zoomVol = delta/100

    def on_key_down(self, *args):
        text = args[3]
        if text == 'i':
            #Toggle isometric
            trans = self.renderOffsets(self.H, self.H)
            self.view.toggleEnv(trans)
        elif text == 'p':
            T()
        elif text == '[':
            self.view.leftScreenshot()
        else:
            #Toggle overlay
            self.view.key(text)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



