• HT

    @JonB This is the link to my github code, sorry it's very messy:
    https://github.com/HenningTm/drawing_touchpad
    The .xlsx file in the repository contains the point coordinates for the shape and is redrawn in lines 474-489.

    posted in Pythonista read more
  • HT

    @JonB Can you give me some pointers how i would use this function? I'm not sure where it would work. This would also mean that I could only color the contour in one color right?

    posted in Pythonista read more
  • HT

    I tried something similar with changing the image to a numpy pixel array and the checking the touched pixel and its surroundings. Unfortunately this turned out to not work that great, since it didn't paint all the surrounding pixels, especially when it searched a large area. When I try Image.getpixel I get the error "'module' object has no attribute 'getpixel'.

    Any ideas how else I might accomplish this?

    Here is the code of my attempt with the numpy array:

    def touch_began(self,touch):
            self.x1, self.y1 = touch.location
            x = int(self.x1)
            y = int(self.y1)
            x = x * 2
            y = y * 2
            if pix[y,x] < 255:
                self.drawDot(touch.location,self.dotSize)
                self.check_area(touch.location, 15)
            return
    
    def check_area(self, t, size): # Checks area around touch for dark pixels and paints them red
            self.x1, self.y1 = t
            x = int(self.x1)
            y = int(self.y1)
            x = x * 2
            y = y * 2
            ptsx = []
            ptsy = []
            thresh = 120
            for xx in range(size):
                print('x: '+str(xx))
                for yy in range(size):
                    print('y: '+str(yy))
                    xn = 0
                    yn = 0
                if pix[y + yy, x + xx] < thresh:
                    xn = (x + xx) * 0.5
                    yn = (y + yy) * 0.5
                    # print(xn)
                    xn = math.ceil(xn)
                    # print(xn)
                    yn = math.ceil(yn)
                    ptsx.append(xn)
                    ptsy.append(yn)
                if pix[y - yy, x - xx] < thresh:
                    xn = (x - xx) * 0.5
                    yn = (y - yy) * 0.5
                    xn = math.ceil(xn)
                    yn = math.ceil(yn)
                    ptsx.append(xn)
                    ptsy.append(yn)
                if pix[y + yy, x - xx] < thresh:
                    xn = (x - xx) * 0.5
                    yn = (y + yy) * 0.5
                    xn = math.ceil(xn)
                    yn = math.ceil(yn)
                    ptsx.append(xn)
                    ptsy.append(yn)
                if pix[y - yy, x + xx] < thresh:
                    xn = (x + xx) * 0.5
                    yn = (y - yy) * 0.5
                    xn = math.ceil(xn)
                    yn = math.ceil(yn)
                    # self.drawDotCoords(xn,yn,self.dotSize)
                    ptsx.append(xn)
                    ptsy.append(yn)
                    # if xn != 0:
                    #     ptsx.append(xn)
                    #     ptsy.append(yn)
            if len(ptsx) > 0:
                self.drawDotCoords(ptsx,ptsy,self.dotSize) # Draws a one-pixel dot on each surrounding dark pixel
    

    posted in Pythonista read more
  • HT

    Hello!

    In my app, a shape is drawn consisting of many points, which are drawn with a ui.Path, somewhat like this:

    for i in range(1,len(self.points)):
                    x1 = self.points[i].x
                    y1 = self.points[i].y
                    x2 = self.points[i + 1].x
                    y2 = self.points[i + 1].y
                    self.path.move_to(x1, y1)
                    self.path.line_to(x2, y2)
    
    self.set_needs_display()
    

    After this is done I would like to be able to draw on top of that shape with a different color and only on that shape. I basically want to be able to recolor parts of the path.

    I was thinking that using add_clip() could be used on the path that drew the shape, constricting new drawing operations to the shape. Unfortunately I have not been able to make add_clip work.

    Does my approach make sense? If so, where would I use add_clip?

    posted in Pythonista read more
  • HT

    Works perfectly, thanks!

    posted in Pythonista read more
  • HT

    Hello!

    I would like to initialize a variable that functions just like the one you get from touch.location (e.g. you can access the x coordinate with touch.location.x).

    If i initialize the variable like this

    x = [150, 200]

    it will not work with functions that only work with touch.locations.
    How can I create variables like this programmatically?

    posted in Pythonista read more
  • HT

    Unfortunately I don't have access to a sftp server. I've got this part of the code, which sends me a mail. I just can't get it to attach the image to the mail:

    
    image = photos.save_image(img)
    
    to = 'receiver'
                            subject = 'data'
                            gmail_pwd = 'password'
                            gmail_user = 'sender'
                            attachment = self.table
                            print('Connecting...')
                            smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
                            console.show_activity()
                            smtpserver.ehlo()
                            smtpserver.starttls()
    
                        smtpserver.ehlo
                        smtpserver.login(gmail_user, gmail_pwd)
                        # 
                        print('Preparing message...')
                        outer = MIMEMultipart()
                        outer['Subject'] = subject
                        outer['To'] = to
                        outer['From'] = gmail_user
                        outer.preamble = 'You will not see this in a MIME-aware email reader.\n'
                        attachment = get_attachment(image)
                        outer.attach(attachment)
                        composed = outer.as_string()
    
                        print('Sending...')
                        smtpserver.sendmail(gmail_user, to, composed)
                        smtpserver.close()
                        console.hide_activity()
                        print('Done.')
    

    It prints out "Get_attachment is not defined"

    posted in Pythonista read more
  • HT

    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!

    posted in Pythonista read more
  • HT

    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?

    posted in Pythonista read more
  • HT

    Hello,

    I would like to know if there is a way to smooth out a drawn line, like shown in this video: https://www.youtube.com/watch?v=Kfy0lWAV16Y

    I know that certain drawing apps do it, is there an easy way to implement it?

    Best wishes.

    posted in Pythonista read more
  • HT

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

    posted in Pythonista read more
  • HT

    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?

    posted in Pythonista read more
  • HT

    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!

    posted in Pythonista read more
  • HT

    Hi,

    I've got an app in which the user draws multiple images in succession. The images are stored in an array. I'm wondering what the best method would be to transfer that data to a computer.

    Unfortunately I can't get the dropbox synchronator to work. An alternative I tried is to send a mail with the data. But I don't know how to attach the images or how to create a text file with the pixel Matrix that I could attach.

    Any pointers?

    posted in Pythonista read more
  • HT

    Thanks, that's exactly what I needed!

    posted in Pythonista read more
  • HT

    Hi everyone,

    I'm learning pythonista and am trying to work on this example script:
    https://gist.github.com/8f81907e4844d579ef8eda2ed5d65d5e

    It allows you to draw freely in the bottom view.
    I've added a switch, with which I want to change the drawing behaviour from drawing freely to only being able to draw straight lines.
    I want the app to move the line following the touch until the touch is ended, which is when the line is supposed to be drawn. I hope this is understandable.

    Can anyone give me some pointers?

    posted in Pythonista read more
  • HT

    That looks perfect. Thanks a lot!

    posted in Pythonista read more
  • HT

    Thanks, that is perfect! For some reason I didn't have this example.

    Could you explain how I could add this sketchpad to a view that's only the bottom half of the screen?
    I would like to display another image in the top half and have the bottom half be paintable.

    posted in Pythonista read more
  • HT

    Hi everyone,

    I want to make a little program which allows the user to paint in an area on the screen. After hitting a button I want to translate this image into a binary matrix with 1 for each white and 0 for each black pixel. I'm new to iOS programming and am not sure how to go about it.
    Right now I'm drawing in a scene with nodes like this:

    marker = ui.Path().oval(0, 0, 4, 4)
    marker.fill()
    marker.close()
    
    self.pending_mark_a = ShapeNode(marker, position = self.a, color = "#000000", size = (self.dotSize,self.dotSize))
    self.pending_mark_a.z_position = 1
    self.add_child(self.pending_mark_a)
    

    Can anyone help?

    Cheers

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!