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.


    Undo last line drawn

    Pythonista
    drawing
    4
    9
    5396
    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.
    • HT
      HT last edited by ccc

      Hello!

      I'm drawing lines like this:

      def drawLine(self,x1,y1,x2,y2):
              self.path = ui.Path()
              self.path.line_width = 8.0
              self.path.line_join_style = ui.LINE_JOIN_ROUND
              self.path.line_cap_style = ui.LINE_CAP_ROUND
              self.path.move_to(x1, y1)
              self.path.line_to(x2, y2)
              self.set_needs_display()
      

      Is there a way to undo the last line drawn?

      Thanks in advance!

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

        One possible way I was thinking of (if a bit clunky), would be to draw a white line over the black one to "erase" it.

        But I can't figure out how to change the color of the line. ui.set_color doesnt seem to do anything. Does anybody know how to change the color?

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

          you need to store lines as a list operations, not the actual path. then regenrate the path when needed.

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

            Just to add a bit to the previous answer:

            Setup a new method which strictly redraws the self.path object, with the exception that you will maintain a list(), which contains all coordinates required paths (each line drawn)

            In the case of undo, pop the last item from the list and call your redraw function which will replay each draw op (except for the last)

            You will have to keep a list of "redo" as well for completeness, if you do this, before you pop the last result, add it to another list holding the redo actions.

            If I get time I will post an example- but TBH don't hold your breath, got a 2 month old who owns me now.

            cvp 1 Reply Last reply Reply Quote 1
            • HT
              HT last edited by

              Thanks guys, I got it to work with the saved coordinates. I would post the code, but it's pretty long and convoluted.

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

                The problem I'm having now is that pythonista crashes if the array of points gets too long (I add the touch locations during touch_moved). It happens pretty fast when I'm drawing freely. Unfortunately there is no error message. Has anyone come across this problem?

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

                  you might need to post your code. likely you have some memory issues, though i know that huge paths are going to be slow.. one option is to convert path to image after N segments. another option migt be to not create a single large path, but lots of smaller ones.

                  1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @reticulated last edited by

                    @reticulated If, like asked in your other topic, you want to smooth draw out your lines, you could only store some points, not all, only if they are not too close of previous one.,

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

                      You are right, the problem was, that I drew each little line as a path individually. Now that I create one big path and draw it once, it works. Thanks!

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors