omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Scene_drawing help!

    Pythonista
    scenedrawing scene
    3
    3
    3290
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • amharder
      amharder last edited by

      I am trying to use scene_drawing to create a chessboard, and it is not going well at all, no matter what coordinates I put in for each square, it outlines the entire scene, please help! First post, should I enter my code or should I not?

      1 Reply Last reply Reply Quote 0
      • brumm
        brumm last edited by

        geometry

        beginner003

        1 Reply Last reply Reply Quote 1
        • abcabc
          abcabc last edited by

          scene_drawing is sort of deprecated. Use ShapeNode Here is an example to display chessboard grid You can tap a square to place a queen.

          # coding: utf-8
          import scene, ui
          
          class Block(scene.ShapeNode):
              def __init__(self, x, y, w, h,
                  fill_color='black', parent=None):
                  path = ui.Path.rect(0, 0, w, h)
                  self.label = None
                  self.root = parent        
                  super(Block, self).__init__(path=path,
                      fill_color=fill_color,
                      position=(x, y),
                      parent=parent)
                      
              def touch_began(self, touch):
                  if not self.label:
                      self.label = scene.LabelNode('♛', 
                      font=('Helvetica', 40),
                      color='green', parent=self.root)
                      self.add_child(self.label)
                     
          class MyScene (scene.Scene):        
              def setup(self):
                  self.background_color = 'gray'
                  colorlist = ['black', 'lightyellow']
                  m, n = 8, 8
                  w, h = 64, 64
                  start_x, start_y = self.size[0]/2-n/2*w, self.size[1]/2 - m/2*h
                  self.grid = {}
                  for i in range(m):
                      for j in range(n):
                          x, y = start_x+i*w, start_y+j*h
                          self.grid[i,j] = Block(x, y, w, h,
                              fill_color=colorlist[(i+j)%2],
                              parent=self)
          
              def touch_began(self, touch):
                  for i, j in self.grid:
                      if (touch.location in (self.grid[i, j].frame)):
                          self.grid[i,j].touch_began(touch)
                          return
                  
          scene.run(MyScene(), show_fps=True)
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors